server/sources/ldapuser.py
branchtls-sprint
changeset 1802 d628defebc17
parent 1398 5fe84a5f7035
child 1952 8e19c813750d
--- a/server/sources/ldapuser.py	Thu May 14 10:24:56 2009 +0200
+++ b/server/sources/ldapuser.py	Thu May 14 11:38:40 2009 +0200
@@ -52,14 +52,14 @@
 
 class LDAPUserSource(AbstractSource):
     """LDAP read-only CWUser source"""
-    support_entities = {'CWUser': False} 
+    support_entities = {'CWUser': False}
 
     port = None
-    
+
     cnx_mode = 0
     cnx_dn = ''
     cnx_pwd = ''
-    
+
     options = (
         ('host',
          {'type' : 'string',
@@ -119,9 +119,9 @@
           'help': 'life time of query cache in minutes (default to two hours).',
           'group': 'ldap-source', 'inputlevel': 2,
           }),
-        
+
     )
-            
+
     def __init__(self, repo, appschema, source_config, *args, **kwargs):
         AbstractSource.__init__(self, repo, appschema, source_config,
                                 *args, **kwargs)
@@ -150,8 +150,8 @@
 
     def init(self):
         """method called by the repository once ready to handle request"""
-        self.repo.looping_task(self._interval, self.synchronize) 
-        self.repo.looping_task(self._query_cache.ttl.seconds/10, self._query_cache.clear_expired) 
+        self.repo.looping_task(self._interval, self.synchronize)
+        self.repo.looping_task(self._query_cache.ttl.seconds/10, self._query_cache.clear_expired)
 
     def synchronize(self):
         """synchronize content known by this repository with content in the
@@ -169,7 +169,7 @@
             for eid, extid in cursor.fetchall():
                 # if no result found, _search automatically delete entity information
                 res = self._search(session, extid, BASE)
-                if res: 
+                if res:
                     ldapemailaddr = res[0].get(ldap_emailattr)
                     if ldapemailaddr:
                         rset = session.execute('EmailAddress X,A WHERE '
@@ -192,13 +192,13 @@
         finally:
             session.commit()
             session.close()
-            
+
     def get_connection(self):
         """open and return a connection to the source"""
         if self._conn is None:
             self._connect()
         return ConnectionWrapper(self._conn)
-    
+
     def authenticate(self, session, login, password):
         """return CWUser eid for the given login/password if this account is
         defined in this source, else raise `AuthenticationError`
@@ -231,7 +231,7 @@
             relname = iter(var.stinfo['relations']).next().r_type
             return self.user_rev_attrs.get(relname)
         return None
-        
+
     def prepare_columns(self, mainvars, rqlst):
         """return two list describin how to build the final results
         from the result of an ldap search (ie a list of dictionnary)
@@ -270,11 +270,11 @@
             #    # probably a bug in rql splitting if we arrive here
             #    raise NotImplementedError
         return columns, global_transforms
-    
+
     def syntax_tree_search(self, session, union,
                            args=None, cachekey=None, varmap=None, debug=0):
-        """return result from this source for a rql query (actually from a rql 
-        syntax tree and a solution dictionary mapping each used variable to a 
+        """return result from this source for a rql query (actually from a rql
+        syntax tree and a solution dictionary mapping each used variable to a
         possible type). If cachekey is given, the query necessary to fetch the
         results (but not the results themselves) may be cached using this key.
         """
@@ -361,8 +361,8 @@
             result = trfunc.apply(result)
         #print '--> ldap result', result
         return result
-                
-    
+
+
     def _connect(self, userdn=None, userpwd=None):
         port, protocol = MODES[self.cnx_mode]
         if protocol == 'ldapi':
@@ -444,12 +444,12 @@
             result.append(rec_dict)
         #print '--->', result
         return result
-    
+
     def before_entity_insertion(self, session, lid, etype, eid):
         """called by the repository when an eid has been attributed for an
         entity stored here but the entity has not been inserted in the system
         table yet.
-        
+
         This method must return the an Entity instance representation of this
         entity.
         """
@@ -458,7 +458,7 @@
         for attr in entity.e_schema.indexable_attributes():
             entity[attr] = res[self.user_rev_attrs[attr]]
         return entity
-    
+
     def after_entity_insertion(self, session, dn, entity):
         """called by the repository after an entity stored here has been
         inserted in the system table.
@@ -492,13 +492,13 @@
 def _insert_email(session, emailaddr, ueid):
     session.execute('INSERT EmailAddress X: X address %(addr)s, U primary_email X '
                     'WHERE U eid %(x)s', {'addr': emailaddr, 'x': ueid}, 'x')
-    
+
 class GotDN(Exception):
     """exception used when a dn localizing the searched user has been found"""
     def __init__(self, dn):
         self.dn = dn
 
-        
+
 class RQL2LDAPFilter(object):
     """generate an LDAP filter for a rql query"""
     def __init__(self, source, session, args=None, mainvars=()):
@@ -510,7 +510,7 @@
             args = {}
         self._args = args
         self.mainvars = mainvars
-        
+
     def generate(self, selection, mainvarname):
         self._filters = res = self._base_filters[:]
         self._mainvarname = mainvarname
@@ -527,7 +527,7 @@
         if len(res) > 1:
             return self._eidfilters, '(&%s)' % ''.join(res)
         return self._eidfilters, res[0]
-    
+
     def visit_and(self, et):
         """generate filter for a AND subtree"""
         for c in et.children:
@@ -587,7 +587,7 @@
         else:
             raise NotImplementedError(relation)
         return res
-        
+
     def _visit_attribute_relation(self, relation):
         """generate filter for an attribute relation"""
         lhs, rhs = relation.get_parts()
@@ -623,18 +623,18 @@
 
     def visit_comparison(self, cmp):
         """generate filter for a comparaison"""
-        return '%s%s'% (cmp.operator, cmp.children[0].accept(self))            
+        return '%s%s'% (cmp.operator, cmp.children[0].accept(self))
 
     def visit_mathexpression(self, mexpr):
         """generate filter for a mathematic expression"""
         raise NotImplementedError
-        
+
     def visit_function(self, function):
         """generate filter name for a function"""
         if function.name == 'IN':
             return self.visit_in(function)
         raise NotImplementedError
-        
+
     def visit_in(self, function):
         grandpapa = function.parent.parent
         ldapattr = self._ldap_attrs[grandpapa.r_type]
@@ -649,7 +649,7 @@
             else:
                 part = '(%s=%s)' % (ldapattr, res[0])
         return part
-        
+
     def visit_constant(self, constant):
         """generate filter name for a constant"""
         value = constant.value
@@ -667,7 +667,7 @@
         else:
             value = str(value)
         return escape_filter_chars(value)
-        
+
     def visit_variableref(self, variableref):
         """get the sql name for a variable reference"""
         pass