[Opensrf-commits] r1178 - trunk/src/python/osrf
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Dec 16 16:28:05 EST 2007
Author: dbs
Date: 2007-12-16 16:06:49 -0500 (Sun, 16 Dec 2007)
New Revision: 1178
Modified:
trunk/src/python/osrf/cache.py
trunk/src/python/osrf/gateway.py
trunk/src/python/osrf/http_translator.py
trunk/src/python/osrf/log.py
trunk/src/python/osrf/net.py
trunk/src/python/osrf/net_obj.py
trunk/src/python/osrf/ses.py
trunk/src/python/osrf/stack.py
Log:
Continue the march towards a pedantic 1.0 python API.
Modified: trunk/src/python/osrf/cache.py
===================================================================
--- trunk/src/python/osrf/cache.py 2007-12-16 20:01:10 UTC (rev 1177)
+++ trunk/src/python/osrf/cache.py 2007-12-16 21:06:49 UTC (rev 1178)
@@ -53,7 +53,7 @@
@staticmethod
def connect(svrs):
global _client
- osrf.log.logDebug("cache: connecting to servers %s" % str(svrs))
+ osrf.log.log_debug("cache: connecting to servers %s" % str(svrs))
_client = memcache.Client(svrs, debug=1)
Modified: trunk/src/python/osrf/gateway.py
===================================================================
--- trunk/src/python/osrf/gateway.py 2007-12-16 20:01:10 UTC (rev 1177)
+++ trunk/src/python/osrf/gateway.py 2007-12-16 21:06:49 UTC (rev 1178)
@@ -2,7 +2,7 @@
from xml.sax import handler, make_parser, saxutils
from osrf.json import to_object
from osrf.net_obj import NetworkObject, new_object_from_hint
-from osrf.log import logError
+import osrf.log
import urllib, urllib2, sys, re
defaultHost = None
@@ -95,7 +95,7 @@
try:
parser.parse(response)
except Exception, e:
- logError('Error parsing gateway XML: %s' % unicode(e))
+ osrf.log.log_error('Error parsing gateway XML: %s' % unicode(e))
return None
return handler.getResult()
Modified: trunk/src/python/osrf/http_translator.py
===================================================================
--- trunk/src/python/osrf/http_translator.py 2007-12-16 20:01:10 UTC (rev 1177)
+++ trunk/src/python/osrf/http_translator.py 2007-12-16 21:06:49 UTC (rev 1178)
@@ -7,8 +7,9 @@
import osrf.conf
import osrf.set
import sys
-from osrf.const import *
-from osrf.net import get_network_handle
+from osrf.const import OSRF_MESSAGE_TYPE_DISCONNECT, OSRF_STATUS_CONTINUE, \
+ OSRF_STATUS_TIMEOUT, OSRF_MESSAGE_TYPE_STATUS,
+import osrf.net
import osrf.log
@@ -141,7 +142,7 @@
self.handle.send(net_msg)
if self.disconnect_only:
- osrf.log.logDebug("exiting early on DISCONNECT")
+ osrf.log.log_debug("exiting early on DISCONNECT")
return apache.OK
first_write = True
@@ -228,7 +229,7 @@
self.cache.put(self.thread, \
{'ip':self.remote_host, 'jid': net_msg.sender}, CACHE_TIME)
- osrf.log.logDebug("caching session [%s] for host [%s] and server "
+ osrf.log.log_debug("caching session [%s] for host [%s] and server "
" drone [%s]" % (self.thread, self.remote_host, net_msg.sender))
@@ -248,7 +249,7 @@
code = int(last_msg.payload().statusCode())
if code == OSRF_STATUS_TIMEOUT:
- osrf.log.logDebug("removing cached session [%s] and "
+ osrf.log.log_debug("removing cached session [%s] and "
"dropping TIMEOUT message" % net_msg.thread)
self.cache.delete(net_msg.thread)
return False
Modified: trunk/src/python/osrf/log.py
===================================================================
--- trunk/src/python/osrf/log.py 2007-12-16 20:01:10 UTC (rev 1177)
+++ trunk/src/python/osrf/log.py 2007-12-16 21:06:49 UTC (rev 1178)
@@ -14,7 +14,9 @@
# -----------------------------------------------------------------------
import traceback, sys, os, re, threading
-from osrf.const import *
+from osrf.const import OSRF_LOG_DEBUG, OSRF_LOG_ERR, OSRF_LOG_INFO, \
+ OSRF_LOG_INTERNAL, OSRF_LOG_TYPE_FILE, OSRF_LOG_TYPE_STDERR, \
+ OSRF_LOG_TYPE_SYSLOG, OSRF_LOG_WARN
LOG_SEMAPHORE = threading.BoundedSemaphore(value=1)
@@ -49,16 +51,16 @@
# -----------------------------------------------------------------------
# Define wrapper functions for the log levels
# -----------------------------------------------------------------------
-def log_internal(s):
- __log(OSRF_LOG_INTERNAL, s)
-def logDebug(s):
- __log(OSRF_LOG_DEBUG, s)
-def log_info(s):
- __log(OSRF_LOG_INFO, s)
-def log_warn(s):
- __log(OSRF_LOG_WARN, s)
-def logError(s):
- __log(OSRF_LOG_ERR, s)
+def log_internal(debug_str):
+ __log(OSRF_LOG_INTERNAL, debug_str)
+def log_debug(debug_str):
+ __log(OSRF_LOG_DEBUG, debug_str)
+def log_info(debug_str):
+ __log(OSRF_LOG_INFO, debug_str)
+def log_warn(debug_str):
+ __log(OSRF_LOG_WARN, debug_str)
+def log_error(debug_str):
+ __log(OSRF_LOG_ERR, debug_str)
def __log(level, msg):
"""Builds the log message and passes the message off to the logger."""
@@ -120,7 +122,7 @@
def __log_file(msg):
''' Logs the message to a file. '''
- global LOG_FILE, LOG_TYPE
+ global LOG_TYPE
logfile = None
try:
Modified: trunk/src/python/osrf/net.py
===================================================================
--- trunk/src/python/osrf/net.py 2007-12-16 20:01:10 UTC (rev 1177)
+++ trunk/src/python/osrf/net.py 2007-12-16 21:06:49 UTC (rev 1178)
@@ -83,7 +83,7 @@
threading.currentThread().getName().lower()
self.jid = JID(args['username'], args['host'], resource)
- osrf.log.logDebug("initializing network with JID %s and host=%s, "
+ osrf.log.log_debug("initializing network with JID %s and host=%s, "
"port=%s, username=%s" % (self.jid.as_utf8(), args['host'], \
args['port'], args['username']))
Modified: trunk/src/python/osrf/net_obj.py
===================================================================
--- trunk/src/python/osrf/net_obj.py 2007-12-16 20:01:10 UTC (rev 1177)
+++ trunk/src/python/osrf/net_obj.py 2007-12-16 21:06:49 UTC (rev 1178)
@@ -54,12 +54,14 @@
of data, cycle through and load the data '''
self._data = {}
- if len(data) == 0: return
+ if len(data) == 0:
+ return
reg = self.get_registry()
if reg.protocol == 'array':
for entry in range(len(reg.keys)):
- if len(data) > entry: break
+ if len(data) > entry:
+ break
self.set_field(reg.keys[entry], data[entry])
def get_data(self):
@@ -89,7 +91,7 @@
except AttributeError:
return NetworkObject.__unknown()
-def __makeNetworkAccessor(cls, key):
+def __make_network_accessor(cls, key):
''' Creates and accessor/mutator method for the given class.
'key' is the name the method will have and represents
the field on the object whose data we are accessing '''
@@ -100,7 +102,7 @@
setattr(cls, key, accessor)
-def NetworkRegisterHint(hint, keys, type='hash'):
+def register_hint(hint, keys, type='hash'):
''' Registers a new network-serializable object class.
'hint' is the class hint
@@ -122,7 +124,7 @@
# assign an accessor/mutator for each field on the object
for k in keys:
- __makeNetworkAccessor(cls, k)
+ __make_network_accessor(cls, k)
# attach our new class to the NetworkObject
# class so others can access it
@@ -133,7 +135,7 @@
# create a unknown object to handle unregistred types
-NetworkRegisterHint('__unknown', [], 'hash')
+register_hint('__unknown', [], 'hash')
# -------------------------------------------------------------------
# Define the custom object parsing behavior
Modified: trunk/src/python/osrf/ses.py
===================================================================
--- trunk/src/python/osrf/ses.py 2007-12-16 20:01:10 UTC (rev 1177)
+++ trunk/src/python/osrf/ses.py 2007-12-16 21:06:49 UTC (rev 1178)
@@ -29,11 +29,11 @@
# -----------------------------------------------------------------------
# Go ahead and register the common network objects
# -----------------------------------------------------------------------
-osrf.net_obj.NetworkRegisterHint('osrfMessage', ['threadTrace', 'locale', 'type', 'payload'], 'hash')
-osrf.net_obj.NetworkRegisterHint('osrfMethod', ['method', 'params'], 'hash')
-osrf.net_obj.NetworkRegisterHint('osrfResult', ['status', 'statusCode', 'content'], 'hash')
-osrf.net_obj.NetworkRegisterHint('osrfConnectStatus', ['status', 'statusCode'], 'hash')
-osrf.net_obj.NetworkRegisterHint('osrfMethodException', ['status', 'statusCode'], 'hash')
+osrf.net_obj.register_hint('osrfMessage', ['threadTrace', 'locale', 'type', 'payload'], 'hash')
+osrf.net_obj.register_hint('osrfMethod', ['method', 'params'], 'hash')
+osrf.net_obj.register_hint('osrfResult', ['status', 'statusCode', 'content'], 'hash')
+osrf.net_obj.register_hint('osrfConnectStatus', ['status', 'statusCode'], 'hash')
+osrf.net_obj.register_hint('osrfMethodException', ['status', 'statusCode'], 'hash')
class Session(object):
@@ -127,7 +127,7 @@
if self.state != OSRF_APP_SESSION_CONNECTED:
self.reset_remote_id()
- osrf.log.logDebug("Sending request %s -> %s " % (self.service, method))
+ osrf.log.log_debug("Sending request %s -> %s " % (self.service, method))
req = Request(self, self.next_id, method, arr, self.locale)
self.requests[str(self.next_id)] = req
self.next_id += 1
@@ -190,7 +190,7 @@
def push_response_queue(self, message):
"""Pushes the message payload onto the response queue
for the request associated with the message's ID."""
- osrf.log.logDebug("pushing %s" % message.payload())
+ osrf.log.log_debug("pushing %s" % message.payload())
try:
self.find_request(message.threadTrace()).pushResponse(message.payload())
except Exception, e:
@@ -201,7 +201,7 @@
try:
return self.requests[str(rid)]
except KeyError:
- osrf.log.logDebug('find_request(): non-existent request %s' % str(rid))
+ osrf.log.log_debug('find_request(): non-existent request %s' % str(rid))
return None
@@ -269,13 +269,13 @@
if len(self.queue) > 0:
if not self.first_response_time:
self.first_response_time = now
- osrf.log.logDebug("time elapsed before first response: %f" \
+ osrf.log.log_debug("time elapsed before first response: %f" \
% (self.first_response_time - self.send_time))
if self.complete:
if not self.complete_time:
self.complete_time = now
- osrf.log.logDebug("time elapsed before complete: %f" \
+ osrf.log.log_debug("time elapsed before complete: %f" \
% (self.complete_time - self.send_time))
# -----------------------------------------------------------------
Modified: trunk/src/python/osrf/stack.py
===================================================================
--- trunk/src/python/osrf/stack.py 2007-12-16 20:01:10 UTC (rev 1177)
+++ trunk/src/python/osrf/stack.py 2007-12-16 21:06:49 UTC (rev 1178)
@@ -29,7 +29,7 @@
if not ses:
# This is an incoming request from a client, create a new server session
- osrf.log.logError("server-side sessions don't exist yet")
+ osrf.log.log_error("server-side sessions don't exist yet")
ses.set_remote_id(net_msg.sender)
@@ -75,7 +75,7 @@
if status_code == OSRF_STATUS_OK:
# We have connected successfully
- osrf.log.logDebug("Successfully connected to " + session.service)
+ osrf.log.log_debug("Successfully connected to " + session.service)
session.state = OSRF_APP_SESSION_CONNECTED
return
@@ -85,12 +85,12 @@
return
if status_code == OSRF_STATUS_TIMEOUT:
- osrf.log.logDebug("The server did not receive a request from us in time...")
+ osrf.log.log_debug("The server did not receive a request from us in time...")
session.state = OSRF_APP_SESSION_DISCONNECTED
return
if status_code == OSRF_STATUS_NOTFOUND:
- osrf.log.logError("Requested method was not found on the server: %s" % status_text)
+ osrf.log.log_error("Requested method was not found on the server: %s" % status_text)
session.state = OSRF_APP_SESSION_DISCONNECTED
raise osrf.ex.OSRFServiceException(status_text)
More information about the opensrf-commits
mailing list