[PATCH eac] Refactoring of `parse_control`

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Fri Aug 2 14:52:47 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1564500696 -7200
#      Tue Jul 30 17:31:36 2019 +0200
# Node ID 1c7d7e9b8316efbf4dfa90f84d350ef7a18a66c3
# Parent  29a224db521a3644469c44173b2973bb398e0f12
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 1c7d7e9b8316
Refactoring of `parse_control`.

The condensing of the repeating for loops have been changed into
a structure that split data and logic.

diff -r 29a224db521a -r 1c7d7e9b8316 cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Fri Aug 02 10:20:36 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Tue Jul 30 17:31:36 2019 +0200
@@ -881,18 +881,14 @@
                 extentity = ExtEntity('EACOtherRecordId', self._gen_extid(), values)
                 self.record_visited(other_record_id, extentity)
                 yield extentity
-        for elem in control.xpath('eac:sources/eac:source',
-                                  namespaces=self.namespaces):
-            for extentity in self.build_source(elem):
-                yield extentity
-        for elem in control.xpath('eac:maintenanceHistory/eac:maintenanceEvent',
-                                  namespaces=self.namespaces):
-            for extentity in self.build_maintenance_event(elem):
-                yield extentity
-        for elem in control.xpath('eac:conventionDeclaration',
-                                  namespaces=self.namespaces):
-            for extentity in self.build_convention(elem):
-                yield extentity
+        builders = (('eac:sources/eac:source', self.build_source),
+                    ('eac:maintenanceHistory/eac:maintenanceEvent', self.build_maintenance_event),
+                    ('eac:conventionDeclaration', self.build_convention))
+        for xpath_str, builder in builders:
+            for elem in control.xpath(xpath_str,
+                                      namespaces=self.namespaces):
+                for extentity in builder(elem):
+                    yield extentity
 
     def build_maintenance_event(self, elem):
         """Parse a `maintenanceEvent` tag, yielding a prov:Activity external



More information about the saem-devel mailing list