Exemplo n.º 1
0
 def __setitem__(self, new_key, value, _sa_initiator=None):
     # TODO We could check if the object's type is correct.
     assert self.linked
     # This is the only difference with the standard behavior.
     setattr(value, self.child_key_name, new_key)
     self.inverse_map[id(value)] = new_key
     MappedCollection.__setitem__(self, new_key, value, _sa_initiator)
Exemplo n.º 2
0
 def __setitem__(self, new_key, value, _sa_initiator=None):
     # TODO We could check if the object's type is correct.
     assert self.linked
     # This is the only difference with the standard behavior.
     setattr(value, self.child_key_name, new_key)
     self.inverse_map[id(value)] = new_key
     MappedCollection.__setitem__(self, new_key, value, _sa_initiator)
Exemplo n.º 3
0
 def __init__(self, *args, **kw):
     rdb_key = directive.key.bind().get(self)
     if rdb_key:
         keyfunc = lambda node:getattr(node, rdb_key)
     elif hasattr(self, 'keyfunc'):
         keyfunc = self.keyfunc
     else:
         keyfunc = default_keyfunc
     MappedCollection.__init__(self, keyfunc=keyfunc)
Exemplo n.º 4
0
    def __init__(self, column_name):
        # Whether the collection is currently being used for a parent's
        # relationship attribute or not.
        self.linked = False

        # Useful references, that will be obtained upon linking.
        self.parent_obj = None
        self.child_cls = None
        self.child_rel_name = None
        self.child_rel_prop = None
        self.child_key_name = column_name

        MappedCollection.__init__(self, lambda x: getattr(x, column_name))
Exemplo n.º 5
0
 def on_key_update(self, value, new_key, unused_old_key,
                   unused_sa_initiator=None):
     assert self.linked
     old_key = self.get_key_of_value(value)
     if value in self.itervalues() and new_key != old_key:
         if new_key in self.iterkeys():
             # We use the method of MappedCollection because we want
             # it to trigger all the necessary Alchemy machinery to
             # detach the child from the parent.
             MappedCollection.__delitem__(self, new_key)
         # We use the methods of dict directly because we want this
         # to be transparent to Alchemy: the child was and remains
         # bound, only its key changes, and Alchemy doesn't care
         # about this.
         dict.__delitem__(self, old_key)
         dict.__setitem__(self, new_key, value)
Exemplo n.º 6
0
 def on_key_update(self, value, new_key, unused_old_key,
                   unused_sa_initiator=None):
     assert self.linked
     old_key = self.inverse_map.get(id(value), None)
     if old_key is not None and new_key != old_key:
         if dict.__contains__(self, new_key):
             other_value = dict.__getitem__(self, new_key)
             del self.inverse_map[id(other_value)]
             # We use the method of MappedCollection because we want
             # it to trigger all the necessary Alchemy machinery to
             # detach the child from the parent.
             MappedCollection.__delitem__(self, new_key)
         # We use the methods of dict directly because we want this
         # to be transparent to Alchemy: the child was and remains
         # bound, only its key changes, and Alchemy doesn't care
         # about this.
         self.inverse_map[id(value)] = new_key
         dict.__delitem__(self, old_key)
         dict.__setitem__(self, new_key, value)
Exemplo n.º 7
0
    def __init__(self, column_name):
        # Whether the collection is currently being used for a parent's
        # relationship attribute or not.
        self.linked = False

        # Map the id() of values to their key. This is well defined
        # because we ensure uniqueness of values (as the key is a
        # function of the value: the attribute we're mapping from).
        # This speeds up key retrieval.
        self.inverse_map = dict()

        self.event_wrapper = None

        # Useful references, that will be obtained upon linking.
        self.child_cls = None
        self.child_rel_name = None
        self.child_rel_prop = None
        self.child_key_name = column_name

        MappedCollection.__init__(self, lambda x: getattr(x, column_name))
Exemplo n.º 8
0
    def __init__(self, column_name):
        # Whether the collection is currently being used for a parent's
        # relationship attribute or not.
        self.linked = False

        # Map the id() of values to their key. This is well defined
        # because we ensure uniqueness of values (as the key is a
        # function of the value: the attribute we're mapping from).
        # This speeds up key retrieval.
        self.inverse_map = dict()

        self.event_wrapper = None

        # Useful references, that will be obtained upon linking.
        self.child_cls = None
        self.child_rel_name = None
        self.child_rel_prop = None
        self.child_key_name = column_name

        MappedCollection.__init__(self, lambda x: getattr(x, column_name))
Exemplo n.º 9
0
 def on_key_update(self,
                   value,
                   new_key,
                   unused_old_key,
                   unused_sa_initiator=None):
     assert self.linked
     old_key = self.inverse_map.get(id(value), None)
     if old_key is not None and new_key != old_key:
         if dict.__contains__(self, new_key):
             other_value = dict.__getitem__(self, new_key)
             del self.inverse_map[id(other_value)]
             # We use the method of MappedCollection because we want
             # it to trigger all the necessary Alchemy machinery to
             # detach the child from the parent.
             MappedCollection.__delitem__(self, new_key)
         # We use the methods of dict directly because we want this
         # to be transparent to Alchemy: the child was and remains
         # bound, only its key changes, and Alchemy doesn't care
         # about this.
         self.inverse_map[id(value)] = new_key
         dict.__delitem__(self, old_key)
         dict.__setitem__(self, new_key, value)
Exemplo n.º 10
0
 def __init__(self, *args, **kw):
     MappedCollection.__init__(self, keyfunc=lambda p: p.email_address)
     OrderedDict.__init__(self, *args, **kw)
Exemplo n.º 11
0
 def __init__(self, *args, **kw):
     MappedCollection.__init__(self, keyfunc=lambda p: p.email_address)
     OrderedDict.__init__(self, *args, **kw)
Exemplo n.º 12
0
 def __init__(self):
     MappedCollection.__init__(self, keyfunc=lambda node: node.project_id)
Exemplo n.º 13
0
 def __init__(self, keyfunc, *args, **kwargs):
     MappedCollection.__init__(self, keyfunc=keyfunc)
     OrderedDict.__init__(self, *args, **kwargs)
Exemplo n.º 14
0
 def __setitem__(self, key, item):
     key = unicode(key)
     self._receive(item, key)
     MappedCollection.__setitem__(self, key, item)
Exemplo n.º 15
0
 def __init__(self, *args, **kw):
     MappedCollection.__init__(self, keyfunc=lambda widget: widget.widget_identifier)
     OrderedDict.__init__(self, *args, **kw)
Exemplo n.º 16
0
 def __init__(self, *args, **kw):
     MappedCollection.__init__(self, keyfunc=lambda span: span.span_name)
     OrderedDict.__init__(self, *args, **kw)
Exemplo n.º 17
0
 def __init__(self, *args, **kw):
     MappedCollection.__init__(self, keyfunc=default_keyfunc)
Exemplo n.º 18
0
 def __init__(self, *args, **kw):
     MappedCollection.__init__(self, keyfunc=lambda obj: obj.category)
     OrderedDict.__init__(self, *args, **kw)
Exemplo n.º 19
0
 def __init__(self, keyfunc, *args, **kwargs):
     MappedCollection.__init__(self, keyfunc=keyfunc)
     OrderedDict.__init__(self, *args, **kwargs)
Exemplo n.º 20
0
 def __init__(self, keyfunc):
     MappedCollection.__init__(self, keyfunc)
     OrderedDict.__init__(self) #@UndefinedVariable
Exemplo n.º 21
0
 def __delitem__(self, key):
     key = unicode(key)
     self._release(self[key])
     MappedCollection.__delitem__(self, key)
Exemplo n.º 22
0
 def __init__(self):
     MappedCollection.__init__(self, keyfunc=lambda node: node.project_id)