[ldapfeed] simplify ldap2attrs
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 23 Nov 2015 14:28:19 +0100
changeset 10910 5ba4de264be4
parent 10909 53af91f77b9d
child 10911 cff2dbc33eff
[ldapfeed] simplify ldap2attrs * tdict argument is never given * separate value retrieval from setting output (will ease a latter cset)
sobjects/ldapparser.py
--- a/sobjects/ldapparser.py	Mon Nov 23 14:26:44 2015 +0100
+++ b/sobjects/ldapparser.py	Mon Nov 23 14:28:19 2015 +0100
@@ -125,11 +125,13 @@
                 entity.cw_set(**attrs)
                 self.notify_updated(entity)
 
-    def ldap2cwattrs(self, sdict, etype, tdict=None):
-        """ Transform dictionary of LDAP attributes to CW
-        etype must be CWUser or CWGroup """
-        if tdict is None:
-            tdict = {}
+    def ldap2cwattrs(self, sdict, etype):
+        """Transform dictionary of LDAP attributes to CW.
+
+        etype must be CWUser or CWGroup
+        """
+        assert etype in ('CWUser', 'CWGroup'), etype
+        tdict = {}
         if etype == 'CWUser':
             items = self.source.user_attrs.items()
         elif etype == 'CWGroup':
@@ -137,14 +139,13 @@
         for sattr, tattr in items:
             if tattr not in self.non_attribute_keys:
                 try:
-                    tdict[tattr] = sdict[sattr]
+                    value = sdict[sattr]
                 except KeyError:
-                    raise ConfigurationError('source attribute %s has not '
-                                             'been found in the source, '
-                                             'please check the %s-attrs-map '
-                                             'field and the permissions of '
-                                             'the LDAP binding user' %
-                                             (sattr, etype[2:].lower()))
+                    raise ConfigurationError(
+                        'source attribute %s has not been found in the source, '
+                        'please check the %s-attrs-map field and the permissions of '
+                        'the LDAP binding user' % (sattr, etype[2:].lower()))
+                tdict[tattr] = value
         return tdict
 
     def before_entity_copy(self, entity, sourceparams):