[datafeed] minor cleanups to cwxml parser
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 01 Jul 2015 08:58:39 +0200
changeset 11256 0d9105673ec9
parent 11255 58be5fe4a232
child 11257 dede32213426
[datafeed] minor cleanups to cwxml parser
cubicweb/sobjects/cwxmlparser.py
--- a/cubicweb/sobjects/cwxmlparser.py	Wed Sep 23 10:59:56 2015 +0200
+++ b/cubicweb/sobjects/cwxmlparser.py	Wed Jul 01 08:58:39 2015 +0200
@@ -1,4 +1,4 @@
-# copyright 2010-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2010-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -83,7 +83,7 @@
     typeddict = {}
     for rschema in eschema.subject_relations():
         if rschema.final and rschema in stringdict:
-            if rschema in ('eid', 'cwuri', 'cwtype', 'cwsource'):
+            if rschema in ('eid', 'cwuri'):  # XXX really omit cwuri?
                 continue
             attrtype = eschema.destination(rschema)
             value = stringdict[rschema]
@@ -197,6 +197,7 @@
         super(CWEntityXMLParser, self).process(url, raise_on_error)
 
     def parse_etree(self, parent):
+        """Overriden from :class:`DataFeedXMLParser` to use a builder component."""
         for node in list(parent):
             builder = self._cw.vreg['components'].select(
                 'cw.entityxml.item-builder', self._cw, node=node,
@@ -294,7 +295,7 @@
             itemurl = self.complete_url(item['cwuri'], item['cwtype'], rels)
             item_rels = list(self.parse(itemurl))
             assert len(item_rels) == 1, 'url %s expected to bring back one '\
-                   'and only one entity, got %s' % (itemurl, len(item_rels))
+                'and only one entity, got %s' % (itemurl, len(item_rels))
             self._parsed_urls[item['cwuri']] = item_rels[0]
             if rels:
                 # XXX (do it better) merge relations
@@ -323,12 +324,7 @@
         item = dict(node.attrib.items())
         item['cwtype'] = text_type(node.tag)
         item.setdefault('cwsource', None)
-        try:
-            item['eid'] = int(item['eid'])
-        except KeyError:
-            # cw < 3.11 compat mode XXX
-            item['eid'] = int(node.find('eid').text)
-            item['cwuri'] = node.find('cwuri').text
+        item['eid'] = int(item['eid'])
         rels = {}
         for child in node:
             role = child.get('role')
@@ -418,7 +414,7 @@
     __regid__ = 'cw.entityxml.action.link'
 
     def check_options(self, options, eid):
-        if not 'linkattr' in options:
+        if 'linkattr' not in options:
             msg = self._cw._("'%s' action requires 'linkattr' option") % self.action
             raise ValidationError(eid, {rn('options', 'subject'): msg})
 
@@ -477,8 +473,9 @@
 
     def check_options(self, options, eid):
         super(CWEntityXMLActionLinkInState, self).check_options(options, eid)
-        if not 'name' in options['linkattr']:
-            msg = self._cw._("'%s' action for in_state relation should at least have 'linkattr=name' option") % self.action
+        if 'name' not in options['linkattr']:
+            msg = self._cw._("'%s' action for in_state relation should at least "
+                             "have 'linkattr=name' option") % self.action
             raise ValidationError(eid, {rn('options', 'subject'): msg})
 
     def _find_entities(self, item, kwargs):