[Opensrf-commits] r1173 - in trunk/src/python: . osrf

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Dec 16 14:21:50 EST 2007


Author: dbs
Date: 2007-12-16 14:00:32 -0500 (Sun, 16 Dec 2007)
New Revision: 1173

Modified:
   trunk/src/python/osrf/http_translator.py
   trunk/src/python/osrf/json.py
   trunk/src/python/osrf/net.py
   trunk/src/python/osrf/ses.py
   trunk/src/python/srfsh.py
Log:
Add some basic locale support.
Revert a dailyWTF that caused massive CPU & memory consumption.


Modified: trunk/src/python/osrf/http_translator.py
===================================================================
--- trunk/src/python/osrf/http_translator.py	2007-12-16 16:37:11 UTC (rev 1172)
+++ trunk/src/python/osrf/http_translator.py	2007-12-16 19:00:32 UTC (rev 1173)
@@ -137,7 +137,7 @@
 
 
         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:

Modified: trunk/src/python/osrf/json.py
===================================================================
--- trunk/src/python/osrf/json.py	2007-12-16 16:37:11 UTC (rev 1172)
+++ trunk/src/python/osrf/json.py	2007-12-16 19:00:32 UTC (rev 1173)
@@ -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 __tabs(depth):
     space = ''
-    while range(depth):
+    for i in range(depth):
         space += '   '
     return space
 
@@ -55,14 +56,16 @@
 
     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 @@
             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 @@
             if not subobj: debug_str += '\n'
 
     else:
+        osrf.log.log_internal("Pretty-printing NetworkObject")
         debug_str = pprint(to_json(obj))
     return debug_str
 

Modified: trunk/src/python/osrf/net.py
===================================================================
--- trunk/src/python/osrf/net.py	2007-12-16 16:37:11 UTC (rev 1172)
+++ trunk/src/python/osrf/net.py	2007-12-16 19:00:32 UTC (rev 1173)
@@ -61,7 +61,6 @@
                 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 @@
                 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):

Modified: trunk/src/python/osrf/ses.py
===================================================================
--- trunk/src/python/osrf/ses.py	2007-12-16 16:37:11 UTC (rev 1172)
+++ trunk/src/python/osrf/ses.py	2007-12-16 19:00:32 UTC (rev 1173)
@@ -29,7 +29,7 @@
 # -----------------------------------------------------------------------
 # 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 @@
         # 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 @@
         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 @@
         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 @@
         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 @@
         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()

Modified: trunk/src/python/srfsh.py
===================================================================
--- trunk/src/python/srfsh.py	2007-12-16 16:37:11 UTC (rev 1172)
+++ trunk/src/python/srfsh.py	2007-12-16 19:00:32 UTC (rev 1173)
@@ -5,6 +5,7 @@
 import osrf.system
 import osrf.ses
 import osrf.conf
+import osrf.log
 
 
 # -------------------------------------------------------------------
@@ -115,7 +116,6 @@
 
     ses = osrf.ses.ClientSession(service)
 
-    end = None
     start = time.time()
 
     req = ses.request2(method, tuple(params))
@@ -123,10 +123,10 @@
 
     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':



More information about the opensrf-commits mailing list