[PATCH eac] Refactoring of `parse_relation`

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Mon Aug 12 16:20:03 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 8abcfe4e3ba441a6d5d5e5666b413961b8c22246
# Parent  caaa8162473cb0a2d01bfe86747766ff893b7ea2
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 8abcfe4e3ba4
Refactoring of `parse_relation`

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

diff -r caaa8162473c -r 8abcfe4e3ba4 cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Tue Jul 30 17:31:36 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Tue Jul 30 17:31:36 2019 +0200
@@ -772,14 +772,12 @@
         relations = self._elem_find(cpf_description, 'eac:relations')
         if relations is None:
             return
-        # cpfRelation.
-        for cpfrel in self._elem_findall(relations, 'eac:cpfRelation'):
-            for extentity in self.build_relation(cpfrel):
-                yield extentity
-        # resourceRelation.
-        for rrel in self._elem_findall(relations, 'eac:resourceRelation'):
-            for extentity in self.build_resource_relation(rrel):
-                yield extentity
+        builders = (('eac:cpfRelation', self.build_relation),
+                    ('eac:resourceRelation', self.build_resource_relation),)
+        for xpath, builder in builders:
+            for elem in self._elem_findall(relations, xpath):
+                for extentity in builder(elem):
+                    yield extentity
 
     @add_xml_wrap_for('AssociationRelation', 'ChronologicalRelation',
                       'HierarchicalRelation')



More information about the saem-devel mailing list