[Opensrf-commits] r2086 - branches/rel_2_0/src/python/osrf (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Nov 15 22:38:08 EST 2010


Author: erickson
Date: 2010-11-15 22:38:06 -0500 (Mon, 15 Nov 2010)
New Revision: 2086

Modified:
   branches/rel_2_0/src/python/osrf/net_obj.py
Log:
rely on logic, not failure through try/catch, to determine of an object is a registered network object;  if an object is unregistered, do not treat it as an __unknown network object (which obfuscates and provides no value).

Modified: branches/rel_2_0/src/python/osrf/net_obj.py
===================================================================
--- branches/rel_2_0/src/python/osrf/net_obj.py	2010-11-16 03:37:49 UTC (rev 2085)
+++ branches/rel_2_0/src/python/osrf/net_obj.py	2010-11-16 03:38:06 UTC (rev 2086)
@@ -146,45 +146,40 @@
 # Define the custom object parsing behavior 
 # -------------------------------------------------------------------
 def parse_net_object(obj):
-    
-    try:
-        hint = obj[OSRF_JSON_CLASS_KEY]
-        sub_object = obj[OSRF_JSON_PAYLOAD_KEY]
-        reg = NetworkRegistry.get_registry(hint)
 
-        obj = {}
+    if isinstance(obj, dict):
+        if OSRF_JSON_CLASS_KEY in obj and OSRF_JSON_PAYLOAD_KEY in obj:
 
-        if reg.protocol == 'array':
-            for entry in range(len(reg.keys)):
-                if len(sub_object) > entry:
-                    obj[reg.keys[entry]] = parse_net_object(sub_object[entry])
-                else:
-                    obj[reg.keys[entry]] = None
-        else:
-            for key in reg.keys:
-                obj[key] = parse_net_object(sub_object.get(key))
+            hint = obj[OSRF_JSON_CLASS_KEY]
+            sub_object = obj[OSRF_JSON_PAYLOAD_KEY]
+            reg = NetworkRegistry.get_registry(hint)
+            
+            if reg:
 
-        estr = 'obj = NetworkObject.%s(obj)' % hint
-        try:
-            exec(estr)
-        except:
-            # this object has not been registered, shove it into the default container
-            obj = NetworkObject.__unknown(obj)
+                obj = {}
 
-        return obj
+                if reg.protocol == 'array':
+                    for entry in range(len(reg.keys)):
+                        if len(sub_object) > entry:
+                            obj[reg.keys[entry]] = parse_net_object(sub_object[entry])
+                        else:
+                            obj[reg.keys[entry]] = None
+                else:
+                    for key in reg.keys:
+                        obj[key] = parse_net_object(sub_object.get(key))
 
-    except:
-        pass
+                # vivicate the network object
+                estr = 'obj = NetworkObject.%s(obj)' % hint
+                exec(estr) 
+                return obj
 
-    # the current object does not have a class hint
-    if isinstance(obj, list):
-        for entry in range(len(obj)):
-            obj[entry] = parse_net_object(obj[entry])
+        # dict, but not a registered NetworObject
+        for key, value in obj.iteritems():
+            obj[key] = parse_net_object(value)
 
-    else:
-        if isinstance(obj, dict):
-            for key, value in obj.iteritems():
-                obj[key] = parse_net_object(value)
+    elif isinstance(obj, list):
+        for idx, value in enumerate(obj):
+            obj[idx] = parse_net_object(value)
 
     return obj
 



More information about the opensrf-commits mailing list