# HG changeset patch # User Julien Cristau # Date 1445007972 -7200 # Node ID 359cbdf3a515fe79d53d511bdd3550d9734f945d # Parent b6b2e1bcd1b2a960dc6b272597e81227fbdced84 [dataimport] extid must be a bytes object diff -r b6b2e1bcd1b2 -r 359cbdf3a515 dataimport/importer.py --- a/dataimport/importer.py Fri Oct 16 17:04:30 2015 +0200 +++ b/dataimport/importer.py Fri Oct 16 17:06:12 2015 +0200 @@ -69,7 +69,7 @@ def use_extid_as_cwuri_filter(extentities): for extentity in extentities: if extentity.extid not in extid2eid: - extentity.values.setdefault('cwuri', set([unicode(extentity.extid)])) + extentity.values.setdefault('cwuri', set([extentity.extid.decode('utf-8')])) yield extentity return use_extid_as_cwuri_filter diff -r b6b2e1bcd1b2 -r 359cbdf3a515 dataimport/stores.py --- a/dataimport/stores.py Fri Oct 16 17:04:30 2015 +0200 +++ b/dataimport/stores.py Fri Oct 16 17:06:12 2015 +0200 @@ -61,6 +61,8 @@ from datetime import datetime from copy import copy +from six import text_type + from logilab.common.deprecation import deprecated from logilab.common.decorators import cached @@ -298,7 +300,7 @@ genfunc = self.generate(attr) if genfunc: entity.cw_edited.edited_attribute(attr, genfunc(entity)) - if isinstance(extid, unicode): + if isinstance(extid, text_type): extid = extid.encode('utf-8') return self.source, extid diff -r b6b2e1bcd1b2 -r 359cbdf3a515 dataimport/test/unittest_importer.py --- a/dataimport/test/unittest_importer.py Fri Oct 16 17:04:30 2015 +0200 +++ b/dataimport/test/unittest_importer.py Fri Oct 16 17:06:12 2015 +0200 @@ -152,14 +152,14 @@ class UseExtidAsCwuriTC(TestCase): def test(self): - personne = ExtEntity('Personne', 1, {'nom': set([u'de la lune']), - 'prenom': set([u'Jean'])}) + personne = ExtEntity('Personne', b'1', {'nom': set([u'de la lune']), + 'prenom': set([u'Jean'])}) mapping = {} set_cwuri = use_extid_as_cwuri(mapping) list(set_cwuri((personne,))) self.assertIn('cwuri', personne.values) - self.assertEqual(personne.values['cwuri'], set(['1'])) - mapping[1] = 'whatever' + self.assertEqual(personne.values['cwuri'], set([u'1'])) + mapping[b'1'] = 'whatever' personne.values.pop('cwuri') list(set_cwuri((personne,))) self.assertNotIn('cwuri', personne.values)