From: dbs Date: Sun, 16 Dec 2007 19:00:32 +0000 (+0000) Subject: Add some basic locale support. X-Git-Tag: osrf_rel_2_0_1~794 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e119f4c09ce7a472c10f67a087932fe3e0278dc4;p=OpenSRF.git Add some basic locale support. Revert a dailyWTF that caused massive CPU & memory consumption. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1173 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/python/osrf/http_translator.py b/src/python/osrf/http_translator.py index 012a596..a53befd 100644 --- a/src/python/osrf/http_translator.py +++ b/src/python/osrf/http_translator.py @@ -137,7 +137,7 @@ class HTTPTranslator(object): net_msg = NetworkMessage(recipient=self.recipient, thread=self.thread, \ - body=self.body) + body=self.body, locale=self.locale) self.handle.send(net_msg) if self.disconnect_only: diff --git a/src/python/osrf/json.py b/src/python/osrf/json.py index da3dad4..d0a4764 100644 --- a/src/python/osrf/json.py +++ b/src/python/osrf/json.py @@ -1,6 +1,7 @@ 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): @@ -43,7 +44,7 @@ def to_json_raw(obj): def __tabs(depth): space = '' - while range(depth): + for i in range(depth): space += ' ' return space @@ -55,14 +56,16 @@ def debug_net_object(obj, depth=1): 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 \ @@ -71,6 +74,7 @@ def debug_net_object(obj, depth=1): 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) @@ -79,6 +83,7 @@ def debug_net_object(obj, 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 diff --git a/src/python/osrf/net.py b/src/python/osrf/net.py index c1db6a8..b636847 100644 --- a/src/python/osrf/net.py +++ b/src/python/osrf/net.py @@ -61,7 +61,6 @@ class NetworkMessage(object): 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'] @@ -71,8 +70,6 @@ class NetworkMessage(object): 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): diff --git a/src/python/osrf/ses.py b/src/python/osrf/ses.py index d2e9a4e..0eb725f 100644 --- a/src/python/osrf/ses.py +++ b/src/python/osrf/ses.py @@ -29,7 +29,7 @@ import random, os, time, threading # ----------------------------------------------------------------------- # 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') @@ -46,6 +46,7 @@ class Session(object): # 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) @@ -62,7 +63,9 @@ class Session(object): 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) @@ -205,7 +208,7 @@ class Request(object): 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 @@ -217,6 +220,7 @@ class Request(object): 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""" @@ -231,7 +235,8 @@ class Request(object): 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() diff --git a/src/python/srfsh.py b/src/python/srfsh.py index 609f889..a9ed580 100755 --- a/src/python/srfsh.py +++ b/src/python/srfsh.py @@ -5,6 +5,7 @@ import osrf.json import osrf.system import osrf.ses import osrf.conf +import osrf.log # ------------------------------------------------------------------- @@ -115,7 +116,6 @@ def handle_request(parts): ses = osrf.ses.ClientSession(service) - end = None start = time.time() req = ses.request2(method, tuple(params)) @@ -123,10 +123,10 @@ def handle_request(parts): 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':