[Opensrf-commits] r2090 - branches/rel_2_0/src/python/osrf (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Nov 16 09:09:11 EST 2010
Author: erickson
Date: 2010-11-16 09:09:09 -0500 (Tue, 16 Nov 2010)
New Revision: 2090
Modified:
branches/rel_2_0/src/python/osrf/net_obj.py
Log:
repaired logic in the as-yet-unused import_array_data; use the more efficient enumerate func; capture array length outside of loop for efficiency; avoid calls to set/get_field and access _data directly inside of the NetworkObject class for faster accessor/mutator's
Modified: branches/rel_2_0/src/python/osrf/net_obj.py
===================================================================
--- branches/rel_2_0/src/python/osrf/net_obj.py 2010-11-16 14:09:02 UTC (rev 2089)
+++ branches/rel_2_0/src/python/osrf/net_obj.py 2010-11-16 14:09:09 UTC (rev 2090)
@@ -44,7 +44,7 @@
self._data = data
if not data: self._data = {}
if isinstance(data, list):
- self.import_array_data(list)
+ self.import_array_data(data)
def import_array_data(self, data):
''' If an array-based object is created with an array
@@ -56,10 +56,8 @@
reg = self.get_registry()
if reg.protocol == 'array':
- for entry in range(len(reg.keys)):
- if len(data) > entry:
- break
- self.set_field(reg.keys[entry], data[entry])
+ for idx, key in enumerate(reg.keys):
+ self._data[key] = data[idx]
def get_data(self):
''' Returns the full dataset for this object as a dict '''
@@ -80,7 +78,7 @@
reg = self.get_registry()
obj = new_object_from_hint(reg.hint)
for field in reg.keys:
- obj.set_field(field, self.get_field(field))
+ obj._data[field] = self._data[field]
return obj
@@ -102,8 +100,8 @@
the field on the object whose data we are accessing '''
def accessor(self, *args):
if len(args) != 0:
- self.set_field(key, args[0])
- return self.get_field(key)
+ self._data[key] = args[0]
+ return self._data[key]
setattr(cls, key, accessor)
@@ -159,11 +157,16 @@
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])
+ subobj_len = len(sub_object)
+
+ for idx, key in enumerate(reg.keys):
+ if idx < subobj_len:
+ # don't attempt acces past the end of the data list
+ obj[key] = parse_net_object(sub_object[idx])
else:
- obj[reg.keys[entry]] = None
+ # make sure all keys are accounted for, even if there
+ # is no data for the key in the parsed object
+ obj[key] = None
else:
for key in reg.keys:
obj[key] = parse_net_object(sub_object.get(key))
More information about the opensrf-commits
mailing list