27 |
27 |
28 from cPickle import loads, dumps |
28 from cPickle import loads, dumps |
29 import cPickle as pickle |
29 import cPickle as pickle |
30 from threading import Lock |
30 from threading import Lock |
31 from datetime import datetime |
31 from datetime import datetime |
32 from base64 import b64decode, b64encode |
32 from base64 import b64encode |
33 from contextlib import contextmanager |
33 from contextlib import contextmanager |
34 from os.path import basename |
34 from os.path import basename |
35 import re |
35 import re |
36 import itertools |
36 import itertools |
37 import zipfile |
37 import zipfile |
850 |
850 |
851 def eid_type_source(self, cnx, eid): # pylint: disable=E0202 |
851 def eid_type_source(self, cnx, eid): # pylint: disable=E0202 |
852 """return a tuple (type, source, extid) for the entity with id <eid>""" |
852 """return a tuple (type, source, extid) for the entity with id <eid>""" |
853 sql = 'SELECT type, extid, asource FROM entities WHERE eid=%s' % eid |
853 sql = 'SELECT type, extid, asource FROM entities WHERE eid=%s' % eid |
854 res = self._eid_type_source(cnx, eid, sql) |
854 res = self._eid_type_source(cnx, eid, sql) |
855 if res[-2] is not None: |
855 if not isinstance(res, list): |
856 if not isinstance(res, list): |
856 res = list(res) |
857 res = list(res) |
857 res[-2] = self.decode_extid(res[-2]) |
858 res[-2] = b64decode(res[-2]) |
|
859 return res |
858 return res |
860 |
859 |
861 def eid_type_source_pre_131(self, cnx, eid): |
860 def eid_type_source_pre_131(self, cnx, eid): |
862 """return a tuple (type, source, extid) for the entity with id <eid>""" |
861 """return a tuple (type, source, extid) for the entity with id <eid>""" |
863 sql = 'SELECT type, extid FROM entities WHERE eid=%s' % eid |
862 sql = 'SELECT type, extid FROM entities WHERE eid=%s' % eid |
864 res = self._eid_type_source(cnx, eid, sql) |
863 res = self._eid_type_source(cnx, eid, sql) |
865 if not isinstance(res, list): |
864 if not isinstance(res, list): |
866 res = list(res) |
865 res = list(res) |
867 if res[-1] is not None: |
866 res[-1] = self.decode_extid(extid) |
868 res[-1] = b64decode(res[-1]) |
|
869 res.append("system") |
867 res.append("system") |
870 return res |
868 return res |
871 |
869 |
872 def extid2eid(self, cnx, extid): |
870 def extid2eid(self, cnx, extid): |
873 """get eid from an external id. Return None if no record found.""" |
871 """get eid from an external id. Return None if no record found.""" |