equal
deleted
inserted
replaced
30 from collections import defaultdict |
30 from collections import defaultdict |
31 import logging |
31 import logging |
32 |
32 |
33 from logilab.mtconverter import xml_escape |
33 from logilab.mtconverter import xml_escape |
34 |
34 |
|
35 from cubicweb import Binary |
|
36 |
35 |
37 |
36 def cwuri2eid(cnx, etypes, source_eid=None): |
38 def cwuri2eid(cnx, etypes, source_eid=None): |
37 """Return a dictionary mapping cwuri to eid for entities of the given entity types and / or |
39 """Return a dictionary mapping cwuri to eid for entities of the given entity types and / or |
38 source. |
40 source. |
39 """ |
41 """ |
135 |
137 |
136 * ``etype`` (entity type), a string which must be the name of one entity type in the schema |
138 * ``etype`` (entity type), a string which must be the name of one entity type in the schema |
137 (eg. ``'Person'``, ``'Animal'``, ...), |
139 (eg. ``'Person'``, ``'Animal'``, ...), |
138 |
140 |
139 * ``values``, a dictionary whose keys are attribute or relation names from the schema (eg. |
141 * ``values``, a dictionary whose keys are attribute or relation names from the schema (eg. |
140 ``'first_name'``, ``'friend'``), and whose values are *sets* |
142 ``'first_name'``, ``'friend'``), and whose values are *sets*. For |
|
143 attributes of type Bytes, byte strings should be inserted in `values`. |
141 |
144 |
142 For instance: |
145 For instance: |
143 |
146 |
144 .. code-block:: python |
147 .. code-block:: python |
145 |
148 |
211 if key != rtype: |
214 if key != rtype: |
212 del entity_dict[key] |
215 del entity_dict[key] |
213 if (rschema.final and eschema.has_metadata(rtype, 'format') |
216 if (rschema.final and eschema.has_metadata(rtype, 'format') |
214 and not rtype + '_format' in entity_dict): |
217 and not rtype + '_format' in entity_dict): |
215 entity_dict[rtype + '_format'] = u'text/plain' |
218 entity_dict[rtype + '_format'] = u'text/plain' |
|
219 if rschema.final and rschema.objects()[0].type == 'Bytes': |
|
220 entity_dict[rtype] = Binary(entity_dict[rtype]) |
216 else: |
221 else: |
217 del entity_dict[key] |
222 del entity_dict[key] |
218 else: |
223 else: |
219 for target_extid in entity_dict.pop(key): |
224 for target_extid in entity_dict.pop(key): |
220 if role == 'subject': |
225 if role == 'subject': |