# HG changeset patch # User Julien Cristau # Date 1443695689 -7200 # Node ID a34edc1057c077e335936ea315a812be438384a9 # Parent f73a9a884534460b89c3e0e3eb8bcd28ad44838d [datafeed] use explicit encode/decode instead of casting to str diff -r f73a9a884534 -r a34edc1057c0 server/sources/datafeed.py --- a/server/sources/datafeed.py Thu Oct 01 12:33:58 2015 +0200 +++ b/server/sources/datafeed.py Thu Oct 01 12:34:49 2015 +0200 @@ -23,6 +23,7 @@ from os.path import exists from datetime import datetime, timedelta +from six import text_type from six.moves.urllib.parse import urlparse from six.moves.urllib.request import Request, build_opener, HTTPCookieProcessor from six.moves.urllib.error import HTTPError @@ -390,11 +391,11 @@ else: source = self.source sourceparams['parser'] = self - if isinstance(uri, unicode): + if isinstance(uri, text_type): uri = uri.encode('utf-8') try: - eid = cnx.repo.extid2eid(source, str(uri), etype, cnx, - sourceparams=sourceparams) + eid = cnx.repo.extid2eid(source, uri, etype, cnx, + sourceparams=sourceparams) except ValidationError as ex: if raise_on_error: raise diff -r f73a9a884534 -r a34edc1057c0 server/sources/native.py --- a/server/sources/native.py Thu Oct 01 12:33:58 2015 +0200 +++ b/server/sources/native.py Thu Oct 01 12:34:49 2015 +0200 @@ -872,8 +872,8 @@ def extid2eid(self, cnx, extid): """get eid from an external id. Return None if no record found.""" - assert isinstance(extid, str) - args = {'x': b64encode(extid)} + assert isinstance(extid, binary_type) + args = {'x': b64encode(extid).decode('ascii')} cursor = self.doexec(cnx, 'SELECT eid FROM entities WHERE extid=%(x)s', args) @@ -913,8 +913,8 @@ # begin by inserting eid/type/source/extid into the entities table if extid is not None: assert isinstance(extid, binary_type) - extid = b64encode(extid) - attrs = {'type': text_type(entity.cw_etype), 'eid': entity.eid, 'extid': extid and text_type(extid), + extid = b64encode(extid).decode('ascii') + attrs = {'type': text_type(entity.cw_etype), 'eid': entity.eid, 'extid': extid, 'asource': text_type(source.uri)} self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs) # insert core relations: is, is_instance_of and cw_source diff -r f73a9a884534 -r a34edc1057c0 sobjects/cwxmlparser.py --- a/sobjects/cwxmlparser.py Thu Oct 01 12:33:58 2015 +0200 +++ b/sobjects/cwxmlparser.py Thu Oct 01 12:34:49 2015 +0200 @@ -206,7 +206,7 @@ * `rels` is for relations and structured as {role: {relation: [(related item, related rels)...]} """ - entity = self.extid2entity(str(item['cwuri']), item['cwtype'], + entity = self.extid2entity(item['cwuri'].encode('ascii'), item['cwtype'], cwsource=item['cwsource'], item=item, raise_on_error=raise_on_error) if entity is None: