# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1445438092 -7200
# Wed Oct 21 16:34:52 2015 +0200
# Node ID 8c703ddabf1d9f95c7049d24358a60a7119aeebe
# Parent 07308a09ce1af23f8738a317da596585b581303c
[dataimport] methods that modify in-place shouldn't return value
Also mark those methods private and drop some useless comments in passing.
Related to #5414760
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1445438092 -7200
# Wed Oct 21 16:34:52 2015 +0200
# Node ID 8c703ddabf1d9f95c7049d24358a60a7119aeebe
# Parent 07308a09ce1af23f8738a317da596585b581303c
[dataimport] methods that modify in-place shouldn't return value
Also mark those methods private and drop some useless comments in passing.
Related to #5414760
@@ -415,28 +415,24 @@
1 while True: 2 last_eid = self._cnx.repo.system_source.create_eid(self._cnx, self._eids_seq_range) 3 for eid in xrange(last_eid - self._eids_seq_range + 1, last_eid + 1): 4 yield eid 5 6 - def apply_size_constraints(self, etype, kwargs): 7 - """ Apply the size constraints for a given etype, attribute and value 8 - """ 9 + def _apply_size_constraints(self, etype, kwargs): 10 + """Apply the size constraints for a given etype, attribute and value.""" 11 size_constraints = self.size_constraints[etype] 12 for attr, value in kwargs.items(): 13 if value: 14 maxsize = size_constraints.get(attr) 15 if maxsize is not None and len(value) > maxsize: 16 kwargs[attr] = value[:maxsize-4] + '...' 17 - return kwargs 18 19 - def apply_default_values(self, etype, kwargs): 20 - """ Apply the default values for a given etype, attribute and value 21 - """ 22 + def _apply_default_values(self, etype, kwargs): 23 + """Apply the default values for a given etype, attribute and value.""" 24 default_values = self.default_values[etype] 25 missing_keys = set(default_values) - set(kwargs) 26 kwargs.update((key, default_values[key]) for key in missing_keys) 27 - return kwargs 28 29 # store api ################################################################ 30 31 def prepare_insert_entity(self, etype, **kwargs): 32 """Given an entity type, attributes and inlined relations, returns the inserted entity's
@@ -457,17 +453,13 @@
33 self._count_cwuri += 1 34 if 'eid' not in kwargs and self._eids_seq_range is not None: 35 # If eid is not given and the eids sequence is set, 36 # use the value from the sequence 37 kwargs['eid'] = self.get_next_eid() 38 - # Check size constraints 39 - kwargs = self.apply_size_constraints(etype, kwargs) 40 - # Apply default values 41 - kwargs = self.apply_default_values(etype, kwargs) 42 - # Push data 43 + self._apply_size_constraints(etype, kwargs) 44 + self._apply_default_values(etype, kwargs) 45 self._data_entities[etype].append(kwargs) 46 - # Return eid 47 return kwargs.get('eid') 48 49 def prepare_insert_relation(self, eid_from, rtype, eid_to, **kwargs): 50 """Insert into the database a relation ``rtype`` between entities with eids ``eid_from`` 51 and ``eid_to``.