[PATCH eac] Refactoring of `parse_control`

Katia Saurfelt katia.saurfelt at logilab.fr
Fri Aug 9 09:24:26 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 9f8480c3139391302a264b7681ba0f6b598e4fe9
# Parent  40ba7f0a6513a12f853bef905ae039a67a28e018
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 9f8480c31393
Refactoring of `parse_control`.

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

diff --git a/cubicweb_eac/dataimport.py b/cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py
+++ b/cubicweb_eac/dataimport.py
@@ -881,18 +881,14 @@ class EACCPFImporter(object):
                 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