diff -r 76b3cd5d4f31 -r 01152fffd593 server/sources/ldapuser.py --- a/server/sources/ldapuser.py Mon Apr 06 12:37:45 2009 +0200 +++ b/server/sources/ldapuser.py Tue Apr 07 09:30:23 2009 +0200 @@ -3,7 +3,7 @@ this source is for now limited to a read-only EUser source :organization: Logilab -:copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr @@ -20,8 +20,6 @@ FOR A PARTICULAR PURPOSE. """ -from datetime import datetime, timedelta - from logilab.common.textutils import get_csv from rql.nodes import Relation, VariableRef, Constant, Function @@ -30,9 +28,10 @@ from ldap.filter import filter_format, escape_filter_chars from ldapurl import LDAPUrl -from cubicweb.common import AuthenticationError, UnknownEid, RepositoryError -from cubicweb.server.sources import AbstractSource, TrFunc, GlobTrFunc, ConnectionWrapper +from cubicweb import AuthenticationError, UnknownEid, RepositoryError from cubicweb.server.utils import cartesian_product +from cubicweb.server.sources import (AbstractSource, TrFunc, GlobTrFunc, + ConnectionWrapper, TimedCache) # search scopes BASE = ldap.SCOPE_BASE @@ -50,24 +49,7 @@ 2: (0, 'ldapi'), } -class TimedCache(dict): - def __init__(self, ttlm, ttls=0): - # time to live in minutes - self.ttl = timedelta(0, ttlm*60 + ttls, 0) - - def __setitem__(self, key, value): - dict.__setitem__(self, key, (datetime.now(), value)) - - def __getitem__(self, key): - return dict.__getitem__(self, key)[1] - - def clear_expired(self): - now_ = datetime.now() - ttl = self.ttl - for key, (timestamp, value) in self.items(): - if now_ - timestamp > ttl: - del self[key] - + class LDAPUserSource(AbstractSource): """LDAP read-only EUser source""" support_entities = {'EUser': False}