[server/sources] add decode_extid method
avoids having the same dance in both eid_type_source variants
--- a/server/sources/__init__.py Wed Jul 29 10:18:56 2015 +0200
+++ b/server/sources/__init__.py Fri Jul 24 16:15:17 2015 +0200
@@ -21,6 +21,7 @@
from time import time
from logging import getLogger
+from base64 import b64decode
from logilab.common import configuration
from logilab.common.deprecation import deprecated
@@ -196,6 +197,12 @@
else:
self.urls = []
+ @staticmethod
+ def decode_extid(extid):
+ if extid is None:
+ return extid
+ return b64decode(extid)
+
# source initialization / finalization #####################################
def set_schema(self, schema):
--- a/server/sources/native.py Wed Jul 29 10:18:56 2015 +0200
+++ b/server/sources/native.py Fri Jul 24 16:15:17 2015 +0200
@@ -29,7 +29,7 @@
import cPickle as pickle
from threading import Lock
from datetime import datetime
-from base64 import b64decode, b64encode
+from base64 import b64encode
from contextlib import contextmanager
from os.path import basename
import re
@@ -852,10 +852,9 @@
"""return a tuple (type, source, extid) for the entity with id <eid>"""
sql = 'SELECT type, extid, asource FROM entities WHERE eid=%s' % eid
res = self._eid_type_source(cnx, eid, sql)
- if res[-2] is not None:
- if not isinstance(res, list):
- res = list(res)
- res[-2] = b64decode(res[-2])
+ if not isinstance(res, list):
+ res = list(res)
+ res[-2] = self.decode_extid(res[-2])
return res
def eid_type_source_pre_131(self, cnx, eid):
@@ -864,8 +863,7 @@
res = self._eid_type_source(cnx, eid, sql)
if not isinstance(res, list):
res = list(res)
- if res[-1] is not None:
- res[-1] = b64decode(res[-1])
+ res[-1] = self.decode_extid(extid)
res.append("system")
return res