@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)
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
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()
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
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
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))
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
# -----------------------------------------------------------------------
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)
# -----------------------------------------------------------------------
# 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."""
def __log_file(msg):
''' Logs the message to a file. '''
- global LOG_FILE, LOG_TYPE
+ global LOG_TYPE
logfile = None
try:
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']))
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):
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 '''
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
# 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
# create a unknown object to handle unregistred types
-NetworkRegisterHint('__unknown', [], 'hash')
+register_hint('__unknown', [], 'hash')
# -------------------------------------------------------------------
# Define the custom object parsing behavior
# -----------------------------------------------------------------------
# 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):
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
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:
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
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))
# -----------------------------------------------------------------
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)
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
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)