[sobjects/parsers] compatibility with xml view of cw <= 3.10
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Thu, 17 Feb 2011 10:26:50 +0100
changeset 7002 29f085f6177b
parent 7001 c53aa19640b2
child 7006 d0f635d3a6bb
[sobjects/parsers] compatibility with xml view of cw <= 3.10
sobjects/parsers.py
--- a/sobjects/parsers.py	Thu Feb 17 10:24:45 2011 +0100
+++ b/sobjects/parsers.py	Thu Feb 17 10:26:50 2011 +0100
@@ -46,6 +46,8 @@
     return todate(datetime.strptime(ustr, '%Y-%m-%d'))
 DEFAULT_CONVERTERS['Date'] = convert_date
 def convert_datetime(ustr):
+    if '.' in ustr: # assume %Y-%m-%d %H:%M:%S.mmmmmm
+        ustr = ustr.split('.',1)[0]
     return datetime.strptime(ustr, '%Y-%m-%d %H:%M:%S')
 DEFAULT_CONVERTERS['Datetime'] = convert_datetime
 def convert_time(ustr):
@@ -76,10 +78,17 @@
 
 def _entity_etree(parent):
     for node in list(parent):
-        item = {'cwtype': unicode(node.tag),
-                'cwuri': node.attrib['cwuri'],
-                'eid': typed_eid(node.attrib['eid']),
-                }
+        try:
+            item = {'cwtype': unicode(node.tag),
+                    'cwuri': node.attrib['cwuri'],
+                    'eid': typed_eid(node.attrib['eid']),
+                    }
+        except KeyError:
+            # cw < 3.11 compat mode XXX
+            item = {'cwtype': unicode(node.tag),
+                    'cwuri': node.find('cwuri').text,
+                    'eid': typed_eid(node.find('eid').text),
+                    }
         rels = {}
         for child in node:
             role = child.get('role')