# HG changeset patch # User Julien Cristau # Date 1437747317 -7200 # Node ID 5fbdbbe518675f63d97e4be2e95cb84510d837a5 # Parent 9af9d59a19727a57186116f71b0fd434e6a58e76 [server/sources] add decode_extid method avoids having the same dance in both eid_type_source variants diff -r 9af9d59a1972 -r 5fbdbbe51867 server/sources/__init__.py --- 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): diff -r 9af9d59a1972 -r 5fbdbbe51867 server/sources/native.py --- 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 """ 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