[PATCH eac] EACResourceRelation use dict.pop method to get xml attributes

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Mon Aug 19 12:25:02 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1565692359 -7200
#      Tue Aug 13 12:32:39 2019 +0200
# Node ID 12471fc97993b54af9b5e81c46ea84e66e9b64aa
# Parent  62abf97445862a29d98cbc9f36fe45ed565e4de0
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 12471fc97993
EACResourceRelation use dict.pop method to get xml attributes

diff -r 62abf9744586 -r 12471fc97993 cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Tue Aug 13 12:13:07 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Tue Aug 13 12:32:39 2019 +0200
@@ -878,7 +878,7 @@
         """Build a `EACResourceRelation` external entity (along with
         ExternalUri entities).
         """
-        obj_uri = elem.attrib.get('{%(xlink)s}href' % self.namespaces)
+        obj_uri = elem.attrib.pop('{%(xlink)s}href' % self.namespaces, None)
         if obj_uri is None:
             self.import_log.record_warning(self._(
                 'found a resourceRelation without any object (no xlink:href '
@@ -892,16 +892,19 @@
         relation_entry = self._elem_find(elem, 'eac:relationEntry')
         if relation_entry is not None:
             values['relation_entry'] = set([text_type(relation_entry.text)])
-        resource_role = elem.attrib.get('{%(xlink)s}role' % self.namespaces)
+        resource_role = elem.attrib.pop('{%(xlink)s}role' % self.namespaces, None)
         if resource_role:
             values['resource_role'] = set([text_type(resource_role)])
-        agent_role = elem.attrib.get('resourceRelationType')
+        agent_role = elem.attrib.pop('resourceRelationType', None)
         if agent_role:
             values['agent_role'] = set([text_type(agent_role)])
         dates = self.parse_daterange(self._elem_find(elem, 'eac:dateRange'))
         if dates:
             values.update(dates)
-        attributes = json.dumps(dict(elem.attrib), sort_keys=True)
+        if elem.attrib:
+            attributes = json.dumps(dict(elem.attrib), sort_keys=True)
+        else:
+            attributes = json.dumps({})
         values.update({'xml_attributes': set([text_type(attributes)])})
         values.update(self.parse_tag_description(elem))
         yield ExtEntity('EACResourceRelation', self._gen_extid(), values)
diff -r 62abf9744586 -r 12471fc97993 test/test_dataimport.py
--- a/test/test_dataimport.py	Tue Aug 13 12:13:07 2019 +0200
+++ b/test/test_dataimport.py	Tue Aug 13 12:32:39 2019 +0200
@@ -384,14 +384,9 @@
              ),
             ('EACResourceRelation', _gen_extid(),
              {'agent_role': set([u'creatorOf']),
-              'xml_attributes': set([u'{"resourceRelationType": "creatorOf", '
-                                     u'"{http://www.w3.org/1999/xlink}actuate": '
-                                     u'"onRequest", "{http://www.w3.org/1999/xlin'
-                                     u'k}href": "http://gael.gironde.fr/ead.html?i'
-                                     u'd=FRAD033_IR_N", "{http://www.w3.org/1999/xl'
-                                     u'ink}role": "Fonds d\'archives", "{http://www.'
-                                     u'w3.org/1999/xlink}show": "new", "{http://www.w'
-                                     u'3.org/1999/xlink}type": "simple"}']),
+              'xml_attributes': set([u'{"{http://www.w3.org/1999/xlink}actuate": "onRequest", '
+                                     u'"{http://www.w3.org/1999/xlink}show": "new", '
+                                     u'"{http://www.w3.org/1999/xlink}type": "simple"}']),
               'relation_entry': set([u'Gironde. Conseil g\xe9n\xe9ral. Direction de'
                                      u' l\'administration et de la s\xe9curit\xe9 juridique']),
               'resource_role': set([u'Fonds d\'archives']),
@@ -769,15 +764,10 @@
                          u'<he xmlns="urn:isbn:1-931666-33-4" xmlns:xlink="http'
                          u'://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org'
                          u'/2001/XMLSchema-instance">joe</he>')
-        self.assertEqual(rrelation.json_attrs, {"resourceRelationType": "creatorOf",
-                                                "{http://www.w3.org/1999/xlink}actuate":
-                                                "onRequest",
-                                                "{http://www.w3.org/1999/xlink}href":
-                                                "http://gael.gironde.fr/ead.html?id=FRAD033_IR_N",
-                                                "{http://www.w3.org/1999/xlink}role":
-                                                "Fonds d'archives",
-                                                "{http://www.w3.org/1999/xlink}show": "new",
-                                                "{http://www.w3.org/1999/xlink}type": "simple"})
+        self.assertEqual(rrelation.json_attrs, {u"{http://www.w3.org/1999/xlink}actuate":
+                                                u"onRequest",
+                                                u"{http://www.w3.org/1999/xlink}show": u"new",
+                                                u"{http://www.w3.org/1999/xlink}type": u"simple"})
         rset = cnx.find('EACFunctionRelation', r_type=u'performs')
         func_relation = rset.one()
         self.assertEqual(func_relation.json_attrs,



More information about the saem-devel mailing list