[repo api] deprecates source.extid2eid, only the system source should implement it, stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 26 Jul 2011 16:34:42 +0200
branchstable
changeset 7697 ef50074a0314
parent 7695 2f6e37661cf6
child 7698 1c7411535c2d
[repo api] deprecates source.extid2eid, only the system source should implement it, and one should directly use the repo api instead of this confusing and error-prone short-cut. Deprecates eid2ext as well for consistency.
server/sources/__init__.py
server/sources/datafeed.py
server/sources/ldapuser.py
server/sources/pyrorql.py
server/test/unittest_ldapuser.py
--- a/server/sources/__init__.py	Tue Jul 26 16:33:43 2011 +0200
+++ b/server/sources/__init__.py	Tue Jul 26 16:34:42 2011 +0200
@@ -25,6 +25,7 @@
 from logging import getLogger
 
 from logilab.common import configuration
+from logilab.common.deprecation import deprecated
 
 from yams.schema import role_name
 
@@ -269,12 +270,6 @@
 
     # external source api ######################################################
 
-    def eid2extid(self, eid, session=None):
-        return self.repo.eid2extid(self, eid, session)
-
-    def extid2eid(self, value, etype, session=None, **kwargs):
-        return self.repo.extid2eid(self, value, etype, session, **kwargs)
-
     def support_entity(self, etype, write=False):
         """return true if the given entity's type is handled by this adapter
         if write is true, return true only if it's a RW support
@@ -522,6 +517,15 @@
         pass
 
 
+    @deprecated('[3.13] use repo.eid2extid(source, eid, session)')
+    def eid2extid(self, eid, session=None):
+        return self.repo.eid2extid(self, eid, session)
+
+    @deprecated('[3.13] use extid2eid(source, value, etype, session, **kwargs)')
+    def extid2eid(self, value, etype, session=None, **kwargs):
+        return self.repo.extid2eid(self, value, etype, session, **kwargs)
+
+
 class TrFunc(object):
     """lower, upper"""
     def __init__(self, trname, index, attrname=None):
--- a/server/sources/datafeed.py	Tue Jul 26 16:33:43 2011 +0200
+++ b/server/sources/datafeed.py	Tue Jul 26 16:34:42 2011 +0200
@@ -267,14 +267,15 @@
         """return an entity for the given uri. May return None if it should be
         skipped
         """
+        session = self._cw
         # if cwsource is specified and repository has a source with the same
         # name, call extid2eid on that source so entity will be properly seen as
         # coming from this source
-        source = self._cw.repo.sources_by_uri.get(
+        source = session.repo.sources_by_uri.get(
             sourceparams.pop('cwsource', None), self.source)
         sourceparams['parser'] = self
         try:
-            eid = source.extid2eid(str(uri), etype, self._cw,
+            eid = session.repo.extid2eid(source, str(uri), etype, session,
                                    sourceparams=sourceparams)
         except ValidationError, ex:
             self.source.error('error while creating %s: %s', etype, ex)
@@ -285,14 +286,14 @@
             # Don't give etype to entity_from_eid so we get UnknownEid if the
             # entity has been removed
             try:
-                entity = self._cw.entity_from_eid(-eid)
+                entity = session.entity_from_eid(-eid)
             except UnknownEid:
                 return None
             self.notify_updated(entity) # avoid later update from the source's data
             return entity
         if self.sourceuris is not None:
             self.sourceuris.pop(str(uri), None)
-        return self._cw.entity_from_eid(eid, etype)
+        return session.entity_from_eid(eid, etype)
 
     def process(self, url, partialcommit=True):
         """main callback: process the url"""
--- a/server/sources/ldapuser.py	Tue Jul 26 16:33:43 2011 +0200
+++ b/server/sources/ldapuser.py	Tue Jul 26 16:34:42 2011 +0200
@@ -310,7 +310,7 @@
         except Exception:
             self.error('while trying to authenticate %s', user, exc_info=True)
             raise AuthenticationError()
-        eid = self.extid2eid(user['dn'], 'CWUser', session)
+        eid = self.repo.extid2eid(self, user['dn'], 'CWUser', session)
         if eid < 0:
             # user has been moved away from this source
             raise AuthenticationError()
@@ -423,7 +423,7 @@
             filteredres = []
             for resdict in res:
                 # get sure the entity exists in the system table
-                eid = self.extid2eid(resdict['dn'], 'CWUser', session)
+                eid = self.repo.extid2eid(self, resdict['dn'], 'CWUser', session)
                 for eidfilter in eidfilters:
                     if not eidfilter(eid):
                         break
@@ -537,7 +537,7 @@
             res = cnx.result(all=0)[1]
         except ldap.NO_SUCH_OBJECT:
             self.info('ldap NO SUCH OBJECT')
-            eid = self.extid2eid(base, 'CWUser', session, insert=False)
+            eid = self.repo.extid2eid(self, base, 'CWUser', session, insert=False)
             if eid:
                 self.warning('deleting ldap user with eid %s and dn %s',
                              eid, base)
@@ -646,6 +646,7 @@
     """generate an LDAP filter for a rql query"""
     def __init__(self, source, session, args=None, mainvars=()):
         self.source = source
+        self.repo = source.repo
         self._ldap_attrs = source.user_rev_attrs
         self._base_filters = source.base_filters
         self._session = session
@@ -751,7 +752,7 @@
                           }[rhs.operator]
                 self._eidfilters.append(filter)
                 return
-            dn = self.source.eid2extid(eid, self._session)
+            dn = self.repo.eid2extid(self.source, eid, self._session)
             raise GotDN(dn)
         try:
             filter = '(%s%s)' % (self._ldap_attrs[relation.r_type],
--- a/server/sources/pyrorql.py	Tue Jul 26 16:33:43 2011 +0200
+++ b/server/sources/pyrorql.py	Tue Jul 26 16:34:42 2011 +0200
@@ -281,8 +281,8 @@
                     continue
             for etype, extid in deleted:
                 try:
-                    eid = self.extid2eid(str(extid), etype, session,
-                                         insert=False)
+                    eid = self.repo.extid2eid(self, str(extid), etype, session,
+                                              insert=False)
                     # entity has been deleted from external repository but is not known here
                     if eid is not None:
                         entity = session.entity_from_eid(eid, etype)
@@ -423,7 +423,7 @@
 
     def _entity_relations_and_kwargs(self, session, entity):
         relations = []
-        kwargs = {'x': self.eid2extid(entity.eid, session)}
+        kwargs = {'x': self.repo.eid2extid(self, entity.eid, session)}
         for key, val in entity.cw_attr_cache.iteritems():
             relations.append('X %s %%(%s)s' % (key, key))
             kwargs[key] = val
@@ -449,15 +449,15 @@
             return
         cu = session.cnxset[self.uri]
         cu.execute('DELETE %s X WHERE X eid %%(x)s' % entity.__regid__,
-                   {'x': self.eid2extid(entity.eid, session)})
+                   {'x': self.repo.eid2extid(self, entity.eid, session)})
         self._query_cache.clear()
 
     def add_relation(self, session, subject, rtype, object):
         """add a relation to the source"""
         cu = session.cnxset[self.uri]
         cu.execute('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
-                   {'x': self.eid2extid(subject, session),
-                    'y': self.eid2extid(object, session)})
+                   {'x': self.repo.eid2extid(self, subject, session),
+                    'y': self.repo.eid2extid(self, object, session)})
         self._query_cache.clear()
         session.entity_from_eid(subject).cw_clear_all_caches()
         session.entity_from_eid(object).cw_clear_all_caches()
@@ -470,8 +470,8 @@
             return
         cu = session.cnxset[self.uri]
         cu.execute('DELETE X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
-                   {'x': self.eid2extid(subject, session),
-                    'y': self.eid2extid(object, session)})
+                   {'x': self.repo.eid2extid(self, subject, session),
+                    'y': self.repo.eid2extid(self, object, session)})
         self._query_cache.clear()
         session.entity_from_eid(subject).cw_clear_all_caches()
         session.entity_from_eid(object).cw_clear_all_caches()
@@ -481,6 +481,7 @@
     """translate a local rql query to be executed on a distant repository"""
     def __init__(self, source):
         self.source = source
+        self.repo = source.repo
         self.current_operator = None
 
     def _accept_children(self, node):
@@ -676,7 +677,7 @@
 
     def eid2extid(self, eid):
         try:
-            return self.source.eid2extid(eid, self._session)
+            return self.repo.eid2extid(self.source, eid, self._session)
         except UnknownEid:
             operator = self.current_operator
             if operator is not None and operator != '=':
--- a/server/test/unittest_ldapuser.py	Tue Jul 26 16:33:43 2011 +0200
+++ b/server/test/unittest_ldapuser.py	Tue Jul 26 16:34:42 2011 +0200
@@ -61,7 +61,7 @@
         # no such user
         raise AuthenticationError()
     # don't check upassword !
-    return self.extid2eid(user['dn'], 'CWUser', session)
+    return self.repo.extid2eid(self, user['dn'], 'CWUser', session)
 
 def setUpModule(*args):
     create_slapd_configuration(LDAPUserSourceTC.config)