import simplejson, types
from osrf.net_obj import NetworkObject, parse_net_object
from osrf.const import OSRF_JSON_PAYLOAD_KEY, OSRF_JSON_CLASS_KEY
+import osrf.log
class NetworkEncoder(simplejson.JSONEncoder):
def default(self, obj):
def __tabs(depth):
space = ''
- while range(depth):
+ for i in range(depth):
space += ' '
return space
debug_str = ''
if isinstance(obj, NetworkObject):
+ osrf.log.log_internal("Returning key/value pairs for NetworkObject")
reg = obj.get_registry()
keys = list(reg.keys) # clone it, so sorting won't break the original
keys.sort()
for k in keys:
- key = k
- while len(key) < 24: key += '.' # pad the names to make the values line up somewhat
+ key = str(k)
+ while len(key) < 24:
+ key += '.' # pad the names to make the values line up somewhat
val = getattr(obj, k)()
subobj = val and not (isinstance(val, unicode) or \
debug_str += __tabs(depth) + key + ' = '
if subobj:
+ osrf.log.log_internal("Returning key/value pairs for subobject")
debug_str += '\n'
val = debug_net_object(val, depth+1)
if not subobj: debug_str += '\n'
else:
+ osrf.log.log_internal("Pretty-printing NetworkObject")
debug_str = pprint(to_json(obj))
return debug_str
self.sender = message.xmlnode.prop('router_from')
else:
self.sender = message.get_from().as_utf8()
- self.locale = None # XXX fix me good
else:
if args.has_key('sender'):
self.sender = args['sender']
self.body = args['body']
if args.has_key('thread'):
self.thread = args['thread']
- if args.has_key('locale'):
- self.thread = args['locale']
class Network(JabberClient):
def __init__(self, **args):
# -----------------------------------------------------------------------
# Go ahead and register the common network objects
# -----------------------------------------------------------------------
-osrf.net_obj.NetworkRegisterHint('osrfMessage', ['threadTrace', 'type', 'payload'], 'hash')
+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')
# by default, we're connected to no one
self.state = OSRF_APP_SESSION_DISCONNECTED
self.remote_id = None
+ self.locale = None
def find_session(threadTrace):
return Session.session_cache.get(threadTrace)
net_msg = osrf.net.NetworkMessage(
recipient = self.remote_id,
body = osrf.json.to_json([omessage]),
- thread = self.thread )
+ thread = self.thread,
+ locale = self.locale,
+ )
handle = osrf.net.get_network_handle()
handle.send(net_msg)
A request is made and any resulting respones are
collected for the client."""
- def __init__(self, session, rid, method=None, params=[]):
+ def __init__(self, session, rid, method=None, params=[], locale='en-US'):
self.session = session # my session handle
self.rid = rid # my unique request ID
self.send_time = 0 # local time the request was put on the wire
self.complete_time = 0 # time the server told us the request was completed
self.first_response_time = 0 # time it took for our first reponse to be received
+ self.locale = locale
def send(self):
"""Sends a request message"""
message = osrf.net_obj.NetworkObject.osrfMessage( {
'threadTrace' : self.rid,
'type' : OSRF_MESSAGE_TYPE_REQUEST,
- 'payload' : method
+ 'payload' : method,
+ 'locale' : self.locale
} )
self.send_time = time.time()
import osrf.system
import osrf.ses
import osrf.conf
+import osrf.log
# -------------------------------------------------------------------
ses = osrf.ses.ClientSession(service)
- end = None
start = time.time()
req = ses.request2(method, tuple(params))
while True:
resp = req.recv(timeout=120)
- if not end:
- total = time.time() - start
+ osrf.log.log_internal("Looping through receive request")
if not resp:
break
+ total = time.time() - start
otp = get_var('SRFSH_OUTPUT')
if otp == 'pretty':