
    -h                     
   S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SS	K
Jr  SS
K
Jr  SSK
Jr  / SQr\	R                  R!                  5       r " S S\5      r " S S\5      r " S S\5      rS r " S S\5      rS rS r " S S\5      r\R6                  " S5      r  " S S\5      rS?S jrS rS r S  r!S! r"S" r#S# r$S$ r%S% r&S?S& jr'S?S' jr(S?S( jr)S?S) jr*S* r+S+ r,\-\.4r/S, r0S- r1S. r2 " S/ S0\35      r4 " S1 S2\-5      r5 " S3 S4\65      r7\3\4\-\5\6\70r8\3S5S6S7S8.\+" 5       4\-S9S6S7S8.\2" 5       4\6\	Rr                  (       a  S:S;0\," 5       4O
S:S<0\," 5       40r: " S= S>\65      r;\!" \;5        \!" \45        \!" \55        g)@aN  Support for collections of mapped entities.

The collections package supplies the machinery used to inform the ORM of
collection membership changes.  An instrumentation via decoration approach is
used, allowing arbitrary types (including built-ins) to be used as entity
collections without requiring inheritance from a base class.

Instrumentation decoration relays membership change events to the
:class:`.CollectionAttributeImpl` that is currently managing the collection.
The decorators observe function call arguments and return values, tracking
entities entering or leaving the collection.  Two decorator approaches are
provided.  One is a bundle of generic decorators that map function arguments
and return values to events::

  from sqlalchemy.orm.collections import collection
  class MyClass(object):
      # ...

      @collection.adds(1)
      def store(self, item):
          self.data.append(item)

      @collection.removes_return()
      def pop(self):
          return self.data.pop()


The second approach is a bundle of targeted decorators that wrap appropriate
append and remove notifiers around the mutation methods present in the
standard Python ``list``, ``set`` and ``dict`` interfaces.  These could be
specified in terms of generic decorator recipes, but are instead hand-tooled
for increased efficiency.  The targeted decorators occasionally implement
adapter-like behavior, such as mapping bulk-set methods (``extend``,
``update``, ``__setslice__``, etc.) into the series of atomic mutation events
that the ORM requires.

The targeted decorators are used internally for automatic instrumentation of
entity collection classes.  Every collection class goes through a
transformation process roughly like so:

1. If the class is a built-in, substitute a trivial sub-class
2. Is this class already instrumented?
3. Add in generic decorators
4. Sniff out the collection interface through duck-typing
5. Add targeted decoration to any undecorated interface method

This process modifies the class at runtime, decorating methods and adding some
bookkeeping properties.  This isn't possible (or desirable) for built-in
classes like ``list``, so trivial sub-classes are substituted to hold
decoration::

  class InstrumentedList(list):
      pass

Collection classes can be specified in ``relationship(collection_class=)`` as
types or a function that returns an instance.  Collection classes are
inspected and instrumented during the mapper compilation phase.  The
collection_class callable will be executed once to produce a specimen
instance, and the type of that specimen will be instrumented.  Functions that
return built-in types like ``lists`` will be adapted to produce instrumented
instances.

When extending a known type like ``list``, additional decorations are not
generally not needed.  Odds are, the extension method will delegate to a
method that's already instrumented.  For example::

  class QueueIsh(list):
     def push(self, item):
         self.append(item)
     def shift(self):
         return self.pop(0)

There's no need to decorate these methods.  ``append`` and ``pop`` are already
instrumented as part of the ``list`` interface.  Decorating them would fire
duplicate events, which should be avoided.

The targeted decoration tries not to rely on other methods in the underlying
collection class, but some are unavoidable.  Many depend on 'read' methods
being present to properly instrument a 'write', for example, ``__setitem__``
needs ``__getitem__``.  "Bulk" methods like ``update`` and ``extend`` may also
reimplemented in terms of atomic appends and removes, so the ``extend``
decoration will actually perform many ``append`` operations and not call the
underlying method at all.

Tight control over bulk operation and the firing of events is also possible by
implementing the instrumentation internally in your methods.  The basic
instrumentation package works under the general assumption that collection
mutation will not raise unusual exceptions.  If you want to closely
orchestrate append and remove events with exception management, internal
instrumentation may be the answer.  Within your method,
``collection_adapter(self)`` will retrieve an object that you can use for
explicit control over triggering append and remove events.

The owning object and :class:`.CollectionAttributeImpl` are also reachable
through the adapter, allowing for some very sophisticated behavior.

    N)inspect_getfullargspec   )base   )exc)util)	coercions)
expression)roles)
collectioncollection_adaptermapped_collectioncolumn_mapped_collectionattribute_mapped_collectionc                   0    \ rS rSrSrS rS rS rS rSr	g)	_PlainColumnGetter   zPlain column getter, stores collection of Column objects
directly.

Serializes to a :class:`._SerializableColumnGetterV2`
which has more expensive __call__() performance
and some rare caveats.

c                 6    Xl         [        U5      S:  U l        g Nr   )colslen	composite)selfr   s     oC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/orm/collections.py__init___PlainColumnGetter.__init__   s    	TQ    c                 @    [         R                  U R                  5      $ N)_SerializableColumnGetterV2_reduce_from_colsr   r   s    r   
__reduce___PlainColumnGetter.__reduce__   s    *<<TYYGGr   c                     U R                   $ r   )r   )r   mappers     r   _cols_PlainColumnGetter._cols   s    yyr   c                    [         R                  " U5      n[         R                  " U5      nU R                  U5       Vs/ s H  nUR	                  X"R
                  U5      PM!     nnU R                  (       a  [        U5      $ US   $ s  snf Nr   )r   instance_state_state_mapperr'   _get_state_attr_by_columndictr   tuple)r   valuestatemcolkeys         r   __call___PlainColumnGetter.__call__   s~    ##E*u% zz!}
$ ''zz3?$ 	 

 >>:q6M
s    &B	)r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r#   r'   r5   __static_attributes__ r   r   r   r      s    'Hr   r   c                   *    \ rS rSrSrS rS rS rSrg)_SerializableColumnGetter   zdColumn-based getter used in version 0.7.6 only.

Remains here for pickle compatibility with 0.7.6.

c                 6    Xl         [        U5      S:  U l        g r   colkeysr   r   r   rC   s     r   r   "_SerializableColumnGetter.__init__       W)r   c                 (    [         U R                  44$ r   )r?   rC   r"   s    r   r#   $_SerializableColumnGetter.__reduce__   s    (4<</99r   c           	      @   [         R                  " U5      n[         R                  " U5      nU R                   Vs/ s H6  nUR	                  X"R
                  UR                  R                  U   5      PM8     nnU R                  (       a  [        U5      $ US   $ s  snf r*   )
r   r+   r,   rC   r-   r.   mapped_tablecolumnsr   r/   )r   r0   r1   r2   kr4   s         r   r5   "_SerializableColumnGetter.__call__   s    ##E*u%
 \\	
 " ''zz1>>#9#9!#< "	 	 
 >>:q6M
s   =BrC   r   N)	r7   r8   r9   r:   r;   r   r#   r5   r<   r=   r   r   r?   r?      s    *:r   r?   c                   :    \ rS rSrSrS rS r\S 5       rS r	Sr
g)	r       a   Updated serializable getter which deals with
multi-table mapped classes.

Two extremely unusual cases are not supported.
Mappings which have tables across multiple metadata
objects, or which are mapped to non-Table selectables
linked across inheriting mappers may fail to function
here.

c                 6    Xl         [        U5      S:  U l        g r   rB   rD   s     r   r   $_SerializableColumnGetterV2.__init__   rF   r   c                 4    U R                   U R                  44$ r   )	__class__rC   r"   s    r   r#   &_SerializableColumnGetterV2.__reduce__   s    ~~..r   c                 j    S nU Vs/ s H  o3R                   U" U5      4PM     nn[        U44$ s  snf )Nc                     [        U R                  [        R                  5      (       d  g U R                  R                  $ r   )
isinstancetabler
   TableClauser4   )cs    r   
_table_keyA_SerializableColumnGetterV2._reduce_from_cols.<locals>._table_key   s*    aggz'='=>>ww{{"r   )r4   r    )clsr   r\   r[   rC   s        r   r!   -_SerializableColumnGetterV2._reduce_from_cols   s:    	# 4884aEE:a=)48*WJ66 9s   0c                 "   / n[        UR                  SS 5      nU R                   He  u  pEUb  Ub  XS;  a*  UR                  UR                  R                  U   5        M:  UR                  UR
                  U   R                  U   5        Mg     U$ )Nmetadata)getattrlocal_tablerC   appendr[   tables)r   r&   r   ra   ckeytkeys         r   r'   !_SerializableColumnGetterV2._cols   s~    6--z4@ LLLT|x/43GF..0067HOOD133D9:	 )
 r   rN   N)r7   r8   r9   r:   r;   r   r#   classmethodr!   r'   r<   r=   r   r   r    r       s*    	*/ 7 7r   r    c           	         ^ [         R                  " U 5       Vs/ s H'  n[        R                  " [        R
                  USS9PM)     nn[        U5      mU4S j$ s  snf )a  A dictionary-based collection type with column-based keying.

Returns a :class:`.MappedCollection` factory with a keying function
generated from mapping_spec, which may be a Column or a sequence
of Columns.

The key value must be immutable for the lifetime of the object.  You
can not, for example, map on foreign key values if those key values will
change during the session, i.e. from None to a database-assigned integer
after a session flush.

mapping_spec)argnamec                     > [        T 5      $ r   MappedCollectionkeyfuncs   r   <lambda>*column_mapped_collection.<locals>.<lambda>       #G,r   )r   to_listr	   expectr   ColumnArgumentRoler   )rk   qr   rq   s      @r   r   r      sZ     l++A 	111nM+ 	  !&G,,s   .Ac                   &    \ rS rSrS rS rS rSrg)_SerializableAttrGetter   c                 F    Xl         [        R                  " U5      U l        g r   )nameoperator
attrgettergetter)r   r}   s     r   r    _SerializableAttrGetter.__init__   s    	))$/r   c                 $    U R                  U5      $ r   r   )r   targets     r   r5    _SerializableAttrGetter.__call__  s    {{6""r   c                 (    [         U R                  44$ r   )rz   r}   r"   s    r   r#   "_SerializableAttrGetter.__reduce__  s    &44r   )r   r}   N)r7   r8   r9   r:   r   r5   r#   r<   r=   r   r   rz   rz      s    0#5r   rz   c                 &   ^ [        U 5      mU4S j$ )a  A dictionary-based collection type with attribute-based keying.

Returns a :class:`.MappedCollection` factory with a keying based on the
'attr_name' attribute of entities in the collection, where ``attr_name``
is the string name of the attribute.

.. warning:: the key value must be assigned to its final value
   **before** it is accessed by the attribute mapped collection.
   Additionally, changes to the key attribute are **not tracked**
   automatically, which means the key in the dictionary is not
   automatically synchronized with the key value on the target object
   itself.  See the section :ref:`key_collections_mutations`
   for an example.

c                     > [        T 5      $ r   rn   r   s   r   rr   -attribute_mapped_collection.<locals>.<lambda>  s    #F+r   )rz   )	attr_namer   s    @r   r   r   
  s      %Y/F++r   c                    ^  U 4S j$ )a  A dictionary-based collection type with arbitrary keying.

Returns a :class:`.MappedCollection` factory with a keying function
generated from keyfunc, a callable that takes an entity and returns a
key value.

The key value must be immutable for the lifetime of the object.  You
can not, for example, map on foreign key values if those key values will
change during the session, i.e. from None to a database-assigned integer
after a session flush.

c                     > [        T 5      $ r   rn   rp   s   r   rr   #mapped_collection.<locals>.<lambda>+  rt   r   r=   rp   s   `r   r   r     s     -,r   c                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\\
R                  " SS5      S	 5       5       r\S
 5       r\S 5       r\S 5       r\S 5       rSrg)r   i.  aA  Decorators for entity collection classes.

The decorators fall into two groups: annotations and interception recipes.

The annotating decorators (appender, remover, iterator, converter,
internally_instrumented) indicate the method's purpose and take no
arguments.  They are not written with parens::

    @collection.appender
    def append(self, append): ...

The recipe decorators all require parens, even those that take no
arguments::

    @collection.adds('entity')
    def insert(self, position, entity): ...

    @collection.removes_return()
    def popitem(self): ...

c                     SU l         U $ )a  Tag the method as the collection appender.

The appender method is called with one positional argument: the value
to append. The method will be automatically decorated with 'adds(1)'
if not already decorated::

    @collection.appender
    def add(self, append): ...

    # or, equivalently
    @collection.appender
    @collection.adds(1)
    def add(self, append): ...

    # for mapping type, an 'append' may kick out a previous value
    # that occupies that slot.  consider d['a'] = 'foo'- any previous
    # value in d['a'] is discarded.
    @collection.appender
    @collection.replaces(1)
    def add(self, entity):
        key = some_key_func(entity)
        previous = None
        if key in self:
            previous = self[key]
        self[key] = entity
        return previous

If the value to append is not allowed in the collection, you may
raise an exception.  Something to remember is that the appender
will be called for each object mapped by a database query.  If the
database contains rows that violate your collection semantics, you
will need to get creative to fix the problem, as access via the
collection will not work.

If the appender method is internally instrumented, you must also
receive the keyword argument '_sa_initiator' and ensure its
promulgation to collection events.

appender_sa_instrument_rolefns    r   r   collection.appenderH  s    R ",	r   c                     SU l         U $ )a  Tag the method as the collection remover.

The remover method is called with one positional argument: the value
to remove. The method will be automatically decorated with
:meth:`removes_return` if not already decorated::

    @collection.remover
    def zap(self, entity): ...

    # or, equivalently
    @collection.remover
    @collection.removes_return()
    def zap(self, ): ...

If the value to remove is not present in the collection, you may
raise an exception or return None to ignore the error.

If the remove method is internally instrumented, you must also
receive the keyword argument '_sa_initiator' and ensure its
promulgation to collection events.

removerr   r   s    r   r   collection.removert  s    0 "+	r   c                     SU l         U $ )zTag the method as the collection remover.

The iterator method is called with no arguments.  It is expected to
return an iterator over all collection members::

    @collection.iterator
    def __iter__(self): ...

iteratorr   r   s    r   r   collection.iterator  s     ",	r   c                     SU l         U $ )ah  Tag the method as instrumented.

This tag will prevent any decoration from being applied to the
method. Use this if you are orchestrating your own calls to
:func:`.collection_adapter` in one of the basic SQLAlchemy
interface methods, or to prevent an automatic ABC method
decoration from wrapping your implementation::

    # normally an 'extend' method on a list-like class would be
    # automatically intercepted and re-implemented in terms of
    # SQLAlchemy events and append().  your implementation will
    # never be called, unless:
    @collection.internally_instrumented
    def extend(self, items): ...

T)_sa_instrumentedr   s    r   internally_instrumented"collection.internally_instrumented  s    $ #	r   z1.3zThe :meth:`.collection.converter` handler is deprecated and will be removed in a future release.  Please refer to the :class:`.AttributeEvents.bulk_replace` listener interface in conjunction with the :func:`.event.listen` function.c                     SU l         U $ )a	  Tag the method as the collection converter.

This optional method will be called when a collection is being
replaced entirely, as in::

    myobj.acollection = [newvalue1, newvalue2]

The converter method will receive the object being assigned and should
return an iterable of values suitable for use by the ``appender``
method.  A converter must not assign values or mutate the collection,
its sole job is to adapt the value the user provides into an iterable
of values for the ORM's use.

The default converter implementation will use duck-typing to do the
conversion.  A dict-like collection will be convert into an iterable
of dictionary values, and other types will simply be iterated::

    @collection.converter
    def convert(self, other): ...

If the duck-typing of the object does not match the type of this
collection, a TypeError is raised.

Supply an implementation of this method if you want to expand the
range of possible types that can be assigned in bulk or perform
validation on the values about to be assigned.

	converterr   r   s    r   r   collection.converter  s    J "-	r   c                    ^  U 4S jnU$ )a  Mark the method as adding an entity to the collection.

Adds "add to collection" handling to the method.  The decorator
argument indicates which method argument holds the SQLAlchemy-relevant
value.  Arguments can be specified positionally (i.e. integer) or by
name::

    @collection.adds(1)
    def push(self, item): ...

    @collection.adds('entity')
    def do_stuff(self, thing, entity=None): ...

c                    > ST4U l         U $ )Nfire_append_event_sa_instrument_beforer   args    r   	decorator"collection.adds.<locals>.decorator      (;S'AB$Ir   r=   r   r   s   ` r   addscollection.adds      "	 r   c                    ^  U 4S jnU$ )a  Mark the method as replacing an entity in the collection.

Adds "add to collection" and "remove from collection" handling to
the method.  The decorator argument indicates which method argument
holds the SQLAlchemy-relevant value to be added, and return value, if
any will be considered the value to remove.

Arguments can be specified positionally (i.e. integer) or by name::

    @collection.replaces(2)
    def __setitem__(self, index, item): ...

c                 (   > ST4U l         SU l        U $ )Nr   fire_remove_event)r   _sa_instrument_afterr   s    r   r   &collection.replaces.<locals>.decorator  s    (;S'AB$&9B#Ir   r=   r   s   ` r   replacescollection.replaces  s     	
 r   c                    ^  U 4S jnU$ )a  Mark the method as removing an entity in the collection.

Adds "remove from collection" handling to the method.  The decorator
argument indicates which method argument holds the SQLAlchemy-relevant
value to be removed. Arguments can be specified positionally (i.e.
integer) or by name::

    @collection.removes(1)
    def zap(self, item): ...

For methods where the value to remove is not known at call-time, use
collection.removes_return.

c                    > ST4U l         U $ Nr   r   r   s    r   r   %collection.removes.<locals>.decorator  r   r   r=   r   s   ` r   removescollection.removes  r   r   c                      S n U $ )au  Mark the method as removing an entity in the collection.

Adds "remove from collection" handling to the method.  The return
value of the method, if any, is considered the value to remove.  The
method arguments are not inspected::

    @collection.removes_return()
    def pop(self): ...

For methods where the value to remove is known at call-time, use
collection.remove.

c                     SU l         U $ r   )r   r   s    r   r   ,collection.removes_return.<locals>.decorator/  s    &9B#Ir   r=   )r   s    r   removes_returncollection.removes_return  s     	 r   r=   N)r7   r8   r9   r:   r;   staticmethodr   r   r   r   r   
deprecatedr   r   r   r   r   r<   r=   r   r   r   r   .  s    2 ) )V  4    ( 	__	? @  ,  ,  ,  r   r   _sa_adapterc                       \ rS rSrSrSrS rS r\S 5       r	\S 5       r
S rSS
 jrS rS rS rS rS rS rSS jrS rSS jrS rS rS rS r\rSS jrSS jrSS jrSS jrS rS r Sr!g	) CollectionAdapteri:  aQ  Bridges between the ORM and arbitrary Python collections.

Proxies base-level collection operations (append, remove, iterate)
to the underlying Python collection, and emits add/remove events for
entities entering or leaving the collection.

The ORM uses :class:`.CollectionAdapter` exclusively for interaction with
entity collections.


)attr_key_dataowner_state
_converterinvalidatedemptyc                     Xl         UR                  U l        [        R                  " U5      U l        X l        Xl        UR                  U l	        SU l
        SU l        g )NF)r   r4   r   weakrefrefr   r   r   _sa_converterr   r   r   )r   r   r   datas       r   r   CollectionAdapter.__init__Q  sJ    	HH	[[&
&,, 
r   c                 0    [         R                  " S5        g )Nz%This collection has been invalidated.)r   warnr"   s    r   _warn_invalidated#CollectionAdapter._warn_invalidated[  s    		9:r   c                 "    U R                  5       $ )z$The entity collection being adapted.)r   r"   s    r   r   CollectionAdapter.data^  s     zz|r   c                 h    U R                   R                  U R                     U R                  5       L $ )zreturn True if the owner state still refers to this collection.

This will return False within a bulk replace operation,
where this collection is the one being replaced.

)r   r.   r   r   r"   s    r   _referenced_by_owner&CollectionAdapter._referenced_by_ownerc  s*     $$TYY/4::<??r   c                 6    U R                  5       R                  $ r   r   _sa_appenderr"   s    r   bulk_appenderCollectionAdapter.bulk_appenderm  s    zz|(((r   Nc                 >    U R                  5       R                  XS9  g)z8Add an entity to the collection, firing mutation events._sa_initiatorNr   r   item	initiators      r   append_with_event#CollectionAdapter.append_with_eventp  s     	

!!$!@r   c                     U R                   (       a   S5       eSU l         XR                  R                  U R                  '   g )Nz7This collection adapter is already in the 'empty' stateT)r   r   _empty_collectionsr   )r   	user_datas     r   
_set_emptyCollectionAdapter._set_emptyu  s:    

	ED	E
9B++DII6r   c                     U R                   (       d   S5       eSU l         U R                  R                  R                  U R                  5      U R                  R
                  U R                  '   g )Nz3This collection adapter is not in the 'empty' stateF)r   r   r   popr   r.   r"   s    r   _reset_emptyCollectionAdapter._reset_empty|  s_    JJ	A@	A
 //33DII> 	II	
r   c                 .    [         R                  " S5      e)NzZThis is a special 'empty' collection which cannot accommodate internal mutation operations)sa_excInvalidRequestErrorr"   s    r   _refuse_emptyCollectionAdapter._refuse_empty  s    ((+
 	
r   c                     U R                   (       a  U R                  5         U R                  5       R                  USS9  gz=Add or restore an entity to the collection, firing no events.Fr   Nr   r   r   r   r   r   s     r   append_without_event&CollectionAdapter.append_without_event  s0     :: 

!!$e!<r   c                     U R                   (       a  U R                  5         U R                  5       R                  nU H
  nU" USS9  M     gr   r   )r   itemsr   r   s       r   append_multiple_without_event/CollectionAdapter.append_multiple_without_event  s:    :: ::<,,DT/ r   c                 6    U R                  5       R                  $ r   r   _sa_removerr"   s    r   bulk_removerCollectionAdapter.bulk_remover  s    zz|'''r   c                 >    U R                  5       R                  XS9  g)z=Remove an entity from the collection, firing mutation events.r   Nr  r   s      r   remove_with_event#CollectionAdapter.remove_with_event  s    

   ?r   c                     U R                   (       a  U R                  5         U R                  5       R                  USS9  g)z7Remove an entity from the collection, firing no events.Fr   N)r   r   r   r  r   s     r   remove_without_event&CollectionAdapter.remove_without_event  s.    :: 

  U ;r   c                     U R                   (       a  U R                  5         U R                  5       R                  n[	        U 5       H	  nU" X1S9  M     g)z>Empty the collection, firing a mutation event for each entity.r   Nr   r   r   r  list)r   r   r   r   s       r   clear_with_event"CollectionAdapter.clear_with_event  s>     :: **,**JDD2 r   c                     U R                   (       a  U R                  5         U R                  5       R                  n[	        U 5       H
  nU" USS9  M     g)z'Empty the collection, firing no events.Fr   Nr  )r   r   r   s      r   clear_without_event%CollectionAdapter.clear_without_event  s@     :: **,**JDD. r   c                 P    [        U R                  5       R                  5       5      $ )z(Iterate over entities in the collection.)iterr   _sa_iteratorr"   s    r   __iter__CollectionAdapter.__iter__  s     DJJL--/00r   c                 b    [        [        U R                  5       R                  5       5      5      $ )z!Count entities in the collection.)r   r  r   r  r"   s    r   __len__CollectionAdapter.__len__  s!    4

113455r   c                     gNTr=   r"   s    r   __bool__CollectionAdapter.__bool__  s    r   c                 
   USLa}  U R                   (       a  U R                  5         U R                  (       a  U R                  5         U R                  R                  U R                  U R                  R                  X5      $ U$ )a*  Notify that a entity is entering the collection but is already
present.


Initiator is a token owned by the InstrumentedAttribute that
initiated the membership mutation, and should be left as None
unless you are passing along an initiator value from a chained
operation.

.. versionadded:: 1.4.15

F)r   r   r   r   r   fire_append_wo_mutation_eventr   r.   r   s      r   r$  /CollectionAdapter.fire_append_wo_mutation_event  sk     E!&&(zz!!#99::  $"2"2"7"7  Kr   c                 
   USLa}  U R                   (       a  U R                  5         U R                  (       a  U R                  5         U R                  R                  U R                  U R                  R                  X5      $ U$ )zNotify that a entity has entered the collection.

Initiator is a token owned by the InstrumentedAttribute that
initiated the membership mutation, and should be left as None
unless you are passing along an initiator value from a chained
operation.

F)r   r   r   r   r   r   r   r.   r   s      r   r   #CollectionAdapter.fire_append_event  sk     E!&&(zz!!#99..  $"2"2"7"7  Kr   c                 
   USLa~  U R                   (       a  U R                  5         U R                  (       a  U R                  5         U R                  R                  U R                  U R                  R                  X5        gg)zNotify that a entity has been removed from the collection.

Initiator is the InstrumentedAttribute that initiated the membership
mutation, and should be left as None unless you are passing along
an initiator value from a chained operation.

FN)r   r   r   r   r   r   r   r.   r   s      r   r   #CollectionAdapter.fire_remove_event  sd     E!&&(zz!!#II''  $"2"2"7"7 "r   c                     U R                   (       a  U R                  5         U R                  R                  U R                  U R                  R
                  US9  g)zNotify that an entity is about to be removed from the collection.

Only called if the entity cannot be removed after calling
fire_remove_event().

r   N)r   r   r   fire_pre_remove_eventr   r.   )r   r   s     r   r,  'CollectionAdapter.fire_pre_remove_event
  sI     ""$		''d..33y 	( 	
r   c                     U R                   U R                  U R                  R                  U R                  U R                  U R
                  S.$ )N)r4   r   	owner_clsr   r   r   )r   r   class_r   r   r   r"   s    r   __getstate__CollectionAdapter.__getstate__  sB    99++))00II++ZZ
 	
r   c                 4   US   U l         US   U l        [        R                  " US   5      U l        US   R
                  U l        XS   l        US   U l        [        US   U R                   5      R                  U l        UR                  SS5      U l        g )Nr4   r   r   r   r/  r   F)r   r   r   r   r   r   r   r   r   rb   implr   getr   )r   ds     r   __setstate__CollectionAdapter.__setstate__!  s    eH	]+[[6+
F)11 $&	]+AkNDII6;;	UU7E*
r   )r   r   r   r   r   r   r   r   )"r7   r8   r9   r:   r;   	__slots__r   r   propertyr   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r!  __nonzero__r$  r   r   r,  r1  r7  r<   r=   r   r   r   r   :  s    
I;   @ @)A
C?
=0(@<3/1
6 K4,&

+r   r   c                    [        U [        5      (       d   e[        R                  nU" U=(       d    S5      nUR	                  U =(       d    S5      nU" U =(       d    S5      R                  U5      nUR                  U5      nUR                  5       n	U =(       d    S H  n
X;   a  U	" XS9  M  X;   d  M  U	" U
SS9  M      U(       a  U H  n
UR                  XS9  M     gg)a  Load a new collection, firing events based on prior like membership.

Appends instances in ``values`` onto the ``new_adapter``. Events will be
fired for any instance not present in the ``existing_adapter``.  Any
instances in ``existing_adapter`` not present in ``values`` will have
remove events fired upon them.

:param values: An iterable of collection member instances

:param existing_adapter: A :class:`.CollectionAdapter` of
 instances to be replaced

:param new_adapter: An empty :class:`.CollectionAdapter`
 to load with ``values``


r=   r   Fr+  N)rX   r  r   IdentitySetintersection
differencer   r   )valuesexisting_adapternew_adapterr   idsetexisting_idset	constants	additionsremovalsr   members              r   bulk_replacerI  ,  s    & fd####E+1r2N++FLb9Ifl#..y9I((3H((*H,B,V5 V51	  F..v.K  r   c                 `   U [         ;   a	  [         U    n [        U " 5       5      nU[         ;   a  [        X5      n U " 5       n[        R	                  5       (       a<   [        USS5      [        U5      :w  a  [        U5        [        R                  5         U $ U $ ! [        R                  5         f = f)aW  Prepare a callable for future use as a collection class factory.

Given a collection class factory (either a type or no-arg callable),
return another factory that will produce compatible instances when
called.

This function is responsible for converting collection_class=list
into the run-time behavior of collection_class=InstrumentedList.

r   N)	__canned_instrumentationtype__converting_factory__instrumentation_mutexacquirerb   id_instrument_classrelease)factoryr^   s     r   prepare_instrumentationrT  T  s     ***73 wy/C &&&s4i &&((	.s.5C@!#&#++-N7N $++-s   %B B-c                 t   ^^ [         U    mUU4S jnSTR                  -  Ul        TR                  Ul        U$ )zkReturn a wrapper that converts a "canned" collection like
set, dict, list into the Instrumented* version.

c                  "   > T" 5       n T" U 5      $ r   r=   )r   instrumented_clsoriginal_factorys    r   wrapper%__converting_factory.<locals>.wrapper  s    %'

++r   z	%sWrapper)rK  r7   r;   )specimen_clsrX  rY  rW  s    ` @r   rM  rM  w  s=     0=,
 #%5%>%>>G&..GONr   c                     U R                   S:X  a  [        R                  " S5      e[        U 5      u  p[	        XU5        [        XU5        [        XU5        g)z6Modify methods in a class and install instrumentation.__builtin__zGCan not instrument a built-in type. Use a subclass, even a trivial one.N)r8   r   ArgumentError_locate_roles_and_methods_setup_canned_roles_assert_required_roles_set_collection_attributesr^   r   methodss      r   rQ  rQ    sT     ~~&"",
 	

 /s3NEG,3w/s73r   c                    0 n0 nU R                    H  n[        U5      R                  5        H  u  pE[        U5      (       d  M  [	        US5      (       a&  UR
                  nUS;   d   eUR                  " Xd5        Su  px[	        US5      (       a  UR                  u  pU	S;   d   eX4n[	        US5      (       a  UR                  n	U	S;   d   eU	nU(       a	  Xx4-   X$'   M  U(       d  M  SSU4X$'   M     M     X4$ )z_search for _sa_instrument_role-decorated methods in
method resolution order, assign to roles.

r   )r   r   r   r   )NNr   )r   r   r   N)	__mro__varsr  callablehasattrr   
setdefaultr   r   )r^   r   rd  superclsr}   methodrolebeforeafteroparguments              r   r_  r_    s    EGKK N002LDF## v45511        , 'MFv677%;;GGGGv56600GGGG & 1 $dE 1; 3  > >r   c                 f   [         R                  " U 5      nU[        ;   a  [        U   u  pEUR                  5        H  u  pgUR                  " Xg5        M     UR                  5        HF  u  p[        XS5      n
U
(       d  M  X;  d  M!  [        U
S5      (       a  M4  [        XU	" U
5      5        MH     gg)zsee if this class has "canned" roles based on a known
collection type (dict, set, list).  Apply those roles
as needed to the "roles" dictionary, and also
prepare "decorator" methods

Nr   )r   duck_type_collection__interfacesr  rj  rb   ri  setattr)r^   r   rd  collection_typecanned_roles
decoratorsrm  r}   rl  r   r   s              r   r`  r`    s     //4O,&#/#@ &,,.JDT( / ",!1!1!3Fd+B)$677Yr]3 "4 'r   c                     SU;  d  [        XS   5      (       d#  [        R                  " SU R                  -  5      eUS   U;  a$  [        [	        XS   5      S5      (       d  SX!S   '   SU;  d  [        XS   5      (       d#  [        R                  " SU R                  -  5      eUS   U;  a$  [        [	        XS   5      S5      (       d  SX!S   '   SU;  d  [        XS   5      (       d#  [        R                  " S	U R                  -  5      eg
)zLensure all roles are present, and apply implicit instrumentation if
needed

r   z>Type %s must elect an appender method to be a collection classr   )r   r   Nr   z<Type %s must elect a remover method to be a collection class)r   r   Nr   z>Type %s must elect an iterator method to be a collection classN)ri  r   r^  r7   rb   rc  s      r   ra  ra    s1   
 gc3D&E&E""!#&<<0
 	
 
z	'	)':&');3 3 &Dj!"WS	2B%C%C""!#&<<0
 	
 
y		(9%&(:2 2 %Ci !gc3D&E&E""!#&<<0
 	
 'Fr   c                 D   UR                  5        H*  u  nu  pEn[        U U[        [        X5      XEU5      5        M,     UR                   " 5        H  u  ps[        U SU-  [        X5      5        M      SU l        [        U S5      (       d  SU l        [        U 5      U l        g)zcapply ad-hoc instrumentation from decorators, class-level defaults
and implicit role declarations

z_sa_%sNr   )	r  ru  _instrument_membership_mutatorrb   r   ri  r   rP  r   )r^   r   rd  method_namern  rq  ro  rm  s           r   rb  rb    s    
 3:--/..f*)6U	
 3B #[[]X_gc&?@ + CO3(( c7Cr   c                   ^ ^^^^^ T(       a  [        [        R                  " [        T 5      S   5      5      n[	        T[
        5      (       a&  Tm[        U5      T:  =(       a    UT   =(       d    SmOTU;   a  UR                  T5      mOSmTmAUUUU UU4S jnSUl        [        T S5      (       a  T R                  Ul
        T R                  Ul        T R                  Ul        U$ )zERoute method args and/or return value through the collection
adapter.r   Nc                    > T(       ab  Tc%  T
U;  a  [         R                  " ST-  5      eUT
   nO:[        U 5      T:  a  U T   nO%T
U;   a  UT
   nO[         R                  " ST-  5      eUR                  SS 5      nUSL a  S nOU S   R                  nT(       a  U(       a  [        UT5      " WU5        T(       a  U(       d  T	" U 0 UD6$ T	" U 0 UD6nUb  [        UT5      " XS5        U$ )NzMissing argument %sr   Fr   )r   r^  r   r   r   rb   )argskwr0   r   executorresro  rq  rn  rl  	named_argpos_args         r   rY  /_instrument_membership_mutator.<locals>.wrapper-  s    B& ..-8  9t9w& ME"_yME ..-8  FF?D1	HAw**HhHf%eY7H4&2&&$%"%C%(8Jr   Tr   )r  r   flatten_iteratorr   rX   intr   indexr   ri  r   r7   r;   )rl  rn  rq  ro  fn_argsrY  r  r  s   ````  @@r   r{  r{    s     !!"8"@"CD
 h$$GGx/EGH4EMI7"!--1 I! !F  $Gv,--&,&@&@#GnnGONr   c                 Z    USLa&  U R                   nU(       a  UR                  X5        ggg)z=Run set wo mutation events.

The collection is not mutated.

FN)r   r$  r   r   r   r  s       r   __set_wo_mutationr  X  s2     E!))224G  "r   c                 X    USLa$  U R                   nU(       a  UR                  X5      nU$ )zVRun set events.

This event always occurs before the collection is actually mutated.

F)r   r   r  s       r   __setr  d  s/     E!))--dBDKr   c                 Z    USLa&  U R                   nU(       a  UR                  X5        ggg)zRun del events.

This event occurs before the collection is actually mutated, *except*
in the case of a pop operation, in which case it occurs afterwards.
For pop operations, the __before_pop hook is called before the
operation occurs.

FN)r   r   r  s       r   __delr  r  s2     E!))&&t;  "r   c                 N    U R                   nU(       a  UR                  U5        gg)z;An event which occurs on a before a pop() operation occurs.N)r   r,  )r   r   r  s      r   __before_popr    s#    %%H&&}5 r   c                  8  ^ S mU4S jn U4S jnU4S jnU4S jnU4S jn[         R                  (       a  U4S jnU4S jnU4S	 jnU4S
 jnU4S jn	[         R                  (       d  U4S jn
[        5       R                  5       nUR	                  S5        U$ )z:Tailored instrumentation wrappers for any list-like class.c                 d    SU l         [        [        U R                  5      R                  U l        g r   )r   rb   r  r7   r;   r   s    r   _tidy_list_decorators.<locals>._tidy  "    "T2;;/77
r   c                 *   >^  SU 4S jjnT" U5        U$ )Nc                 .   > [        XU5      nT" X5        g r   r  )r   r   r   r   s      r   rd   0_list_decorators.<locals>.append.<locals>.append  s    ]3DtNr   r   r=   )r   rd   r  s   ` r   rd    _list_decorators.<locals>.append  s    	 	fr   c                 *   >^  SU 4S jjnT" U5        U$ )Nc                 .   > [        XU5        T" X5        g r   r  r   r0   r   r   s      r   remove0_list_decorators.<locals>.remove.<locals>.remove  s    $}-tOr   r   r=   r   r  r  s   ` r   r   _list_decorators.<locals>.remove  s    	
 	fr   c                 &   >^  U 4S jnT" U5        U$ )Nc                 .   > [        X5      nT" XU5        g r   r  )r   r  r0   r   s      r   insert0_list_decorators.<locals>.insert.<locals>.insert  s    $&EtE"r   r=   )r   r  r  s   ` r   r   _list_decorators.<locals>.insert  s    	# 	fr   c                 &   >^  U 4S jnT" U5        U$ )Nc                   > [        U[        5      (       d'  X   nUb  [        X5        [        X5      nT
" XU5        g UR                  =(       d    SnUR
                  =(       d    SnUS:  a  U[        U 5      -  nUR                  b  UR                  nO[        U 5      nUS:  a  U[        U 5      -  nUS:X  aT  X L a  g [        XVU5       H  n[        U 5      U:  d  M  X	 M     [        U5       H  u  pxU R                  Xu-   U5        M     g [        [        XVU5      5      n	[        U5      [        U	5      :w  a%  [        S[        U5      < S[        U	5      < 35      e[        X5       H  u  pxU R                  Xx5        M     g )Nr   r   z#attempt to assign sequence of size z to extended slice of size )rX   slicer  r  stepstartr   stoprange	enumerater  r  
ValueErrorzip__setitem__)r   r  r0   existingr  r  r  ir   rngr   s             r   r  :_list_decorators.<locals>.__setitem__.<locals>.__setitem__  sT   eU++;'$)d*4& zzQ(q19SY&E::) ::Dt9D!8CI%D19}"55t9u, $ 6 $-U#3AIt4 $4 uU$78C5zSX-(  #5z3s85 
 $'s?((1 $3r   r=   r   r  r  s   ` r   r  %_list_decorators.<locals>.__setitem__  s    &	2P 	kr   c                 &   >^  U 4S jnT" U5        U$ )Nc                    > [        U[        5      (       d  X   n[        X5        T" X5        g X    H  n[        X5        M     T" X5        g r   )rX   r  r  r   r  r   r   s      r   __delitem__:_list_decorators.<locals>.__delitem__.<locals>.__delitem__  sC    eU++{d!4
 !KD$% (4r   r=   r   r  r  s   ` r   r  %_list_decorators.<locals>.__delitem__  s    	  	kr   c                 &   >^  U 4S jnT" U5        U$ )Nc                    > XU  H  n[        X5        M     U Vs/ s H  n[        X5      PM     nnT" XX#5        g s  snf r   r  r  )r   r  endr@  r0   r   s        r   __setslice__<_list_decorators.<locals>.__setslice__.<locals>.__setslice__  sB    !_E$& -:@A&%,&A4, Bs   =r=   )r   r  r  s   ` r   r  &_list_decorators.<locals>.__setslice__  s    - ,r   c                 &   >^  U 4S jnT" U5        U$ )Nc                 D   > XU  H  n[        X5        M     T" XU5        g r   r  )r   r  r  r0   r   s       r   __delslice__<_list_decorators.<locals>.__delslice__.<locals>.__delslice__  s#    !_E$& -4$r   r=   )r   r  r  s   ` r   r  &_list_decorators.<locals>.__delslice__  s    %
 ,r   c                    > S nT" U5        U$ )Nc                 J    [        U5       H  nU R                  U5        M     g r   r  rd   r   iterabler0   s      r   extend0_list_decorators.<locals>.extend.<locals>.extend  s    hE" (r   r=   )r   r  r  s     r   r   _list_decorators.<locals>.extend  s    	# 	fr   c                    > S nT" U5        U$ )Nc                 L    [        U5       H  nU R                  U5        M     U $ r   r  r  s      r   __iadd__4_list_decorators.<locals>.__iadd__.<locals>.__iadd__  s#     hE" (Kr   r=   )r   r  r  s     r   r  "_list_decorators.<locals>.__iadd__      	 	hr   c                 *   >^  SU 4S jjnT" U5        U$ )Nc                 D   > [        U 5        T" X5      n[        X5        U$ r   r  r  r  s      r   r   *_list_decorators.<locals>.pop.<locals>.pop  s!    d?D$Kr   r=   r   r   r  s   ` r   r   _list_decorators.<locals>.pop  s    	 	c

r   c                 *   >^  SU 4S jjnT" U5        U$ )Nc                 >   > U  H  n[        X5        M     T" U 5        g r   r  r  s      r   clear._list_decorators.<locals>.clear.<locals>.clear  s     D$% !4r   r  r=   r   r  r  s   ` r   r  _list_decorators.<locals>.clear  s    
 %LLr   r  )r   py2klocalscopyr   )rd   r  r  r  r  r  r  r  r  r   r  lr  s               @r   _list_decoratorsr    sq    8*X" yy	 	 	 99	 	AEE'NHr   c                    ^^	 S m	[         R                  " S5      mU	4S jn U	4S jnU	4S jnUU	4S jnU	4S jnU	4S jnUU	4S	 jn[        5       R                  5       nUR	                  S
5        UR	                  S5        U$ )zBTailored instrumentation wrappers for any dict-like mapping class.c                 d    SU l         [        [        U R                  5      R                  U l        g r   )r   rb   r.   r7   r;   r   s    r   r  _dict_decorators.<locals>._tidy/  r  r   Unspecifiedc                 *   >^  SU 4S jjnT" U5        U$ )Nc                 X   > X;   a  [        X U   U5        [        XU5      nT" XU5        g r   r  )r   r4   r0   r   r   s       r   r  :_dict_decorators.<locals>.__setitem__.<locals>.__setitem__6  s,    {dI}5$}5Et% r   r   r=   r  s   ` r   r  %_dict_decorators.<locals>.__setitem__5  s    	! 	kr   c                 *   >^  SU 4S jjnT" U5        U$ )Nc                 >   > X;   a  [        X U   U5        T" X5        g r   r  )r   r4   r   r   s      r   r  :_dict_decorators.<locals>.__delitem__.<locals>.__delitem__@  s    {dI}5tMr   r   r=   r  s   ` r   r  %_dict_decorators.<locals>.__delitem__?  s    	
 	kr   c                 &   >^  U 4S jnT" U5        U$ )Nc                 D   > U  H  n[        X U   5        M     T" U 5        g r   r  )r   r4   r   s     r   r  ._dict_decorators.<locals>.clear.<locals>.clearI  s     dI& tHr   r=   r  s   ` r   r  _dict_decorators.<locals>.clearH  s    	
 	er   c                 .   >^  T4UU 4S jjnT" U5        U$ )Nc                 x   > [        U 5        X;   nUTL a	  T" X5      nO	T" XU5      nU(       a  [        X5        U$ r   r  )r   r4   default_to_delr   r  r   s        r   r   *_dict_decorators.<locals>.pop.<locals>.popR  s?    kG+%$}$W-d!Kr   r=   )r   r   r  r  s   ` r   r   _dict_decorators.<locals>.popQ  s    #. 		 		 	c

r   c                 &   >^  U 4S jnT" U5        U$ )Nc                 J   > [        U 5        T" U 5      n[        XS   5        U$ r   r  r   r   r   s     r   popitem2_dict_decorators.<locals>.popitem.<locals>.popitema  s%    d8D$Q Kr   r=   )r   r  r  s   ` r   r  !_dict_decorators.<locals>.popitem`  s    	 	gr   c                 "   > SS jnT" U5        U$ )Nc                 x    X;  a  U R                  X5        U$ U R                  U5      nX2L a  [        XS 5        U$ r   )r  __getitem__r  )r   r4   r  r0   s       r   rj  8_dict_decorators.<locals>.setdefault.<locals>.setdefaultk  s?      .((-#%d48r   r   r=   )r   rj  r  s     r   rj  $_dict_decorators.<locals>.setdefaultj  s    		 	jr   c                 *   > T4U4S jjnT" U5        U$ )Nc                 P  > UTLar  [        US5      (       a8  [        U5       H(  nX0;  d	  X   X   La  X   X'   M  [        XU   S 5        M*     O)U H#  u  p4X0;  d  X   ULa  X@U'   M  [        XS 5        M%     U H(  nX0;  d	  X   X#   La  X#   X'   M  [        XU   S 5        M*     g )Nkeys)ri  r  r  )r   __otherr  r4   r0   r  s        r   update0_dict_decorators.<locals>.update.<locals>.updatez  s    k)7F++#G}?diw|.K(/DI-dCL$G	  - '.
?diu.D(-I-d4@	 '.
 ?dirw&> "DI%dsGT:	 r   r=   )r   r  r  r  s     r   r   _dict_decorators.<locals>.updatey  s    !, 	;( 	fr   r  r   symbolr  r  r   )
r  r  r  r   r  rj  r  r  r  r  s
           @@r   _dict_decoratorsr  ,  sf    8 ++m,K0 	AEE'NEE-Hr   c                 >    [        U[        U R                  4-   5      $ )zGAllow only set, frozenset and self.__class__-derived
objects in binops.)rX   _set_binop_basesrT   r   objs     r   _set_binops_check_strictr    s     c+t~~.??@@r   c                     [        U[        U R                  4-   5      =(       d    [        R                  " U5      [
        :H  $ )z5Allow anything set-like to participate in set binops.)rX   r  rT   r   rs  setr  s     r   _set_binops_check_looser!    s8     	3(DNN+<<= 	1$$S)S0r   c                  J  ^ S m[         R                  " S5      n U4S jnU4S jnU4S jnU4S jnU4S jnU4S jnU4S	 jnU4S
 jnU4S jn	U4S jn
U4S jnU4S jnU4S jn[        5       R                  5       nUR	                  S5        UR	                  S5        U$ )z9Tailored instrumentation wrappers for any set-like class.c                 d    SU l         [        [        U R                  5      R                  U l        g r   )r   rb   r   r7   r;   r   s    r   r  _set_decorators.<locals>._tidy  s"    "S"++.66
r   r  c                 *   >^  SU 4S jjnT" U5        U$ )Nc                 R   > X;  a  [        XU5      nO[        XU5        T" X5        g r   )r  r  r  s      r   add)_set_decorators.<locals>.add.<locals>.add  s&     d=9!$}=tOr   r   r=   )r   r'  r  s   ` r   r'  _set_decorators.<locals>.add  s    	 	c

r   c                 *   >^  SU 4S jjnT" U5        U$ )Nc                 8   > X;   a  [        XU5        T" X5        g r   r  r  s      r   discard1_set_decorators.<locals>.discard.<locals>.discard      }d=1tOr   r   r=   )r   r,  r  s   ` r   r,   _set_decorators.<locals>.discard  s    	 	gr   c                 *   >^  SU 4S jjnT" U5        U$ )Nc                 8   > X;   a  [        XU5        T" X5        g r   r  r  s      r   r  /_set_decorators.<locals>.remove.<locals>.remove  r.  r   r   r=   r  s   ` r   r  _set_decorators.<locals>.remove  s    	 	fr   c                 &   >^  U 4S jnT" U5        U$ )Nc                 D   > [        U 5        T" U 5      n[        X5        U$ r   r  r  s     r   r   )_set_decorators.<locals>.pop.<locals>.pop  s#    d8D $Kr   r=   r  s   ` r   r   _set_decorators.<locals>.pop  s    	 	c

r   c                    > S nT" U5        U$ )Nc                 J    [        U 5       H  nU R                  U5        M     g r   )r  r  r   s     r   r  -_set_decorators.<locals>.clear.<locals>.clear  s    T
D! #r   r=   r  s     r   r  _set_decorators.<locals>.clear  s    	" 	er   c                    > S nT" U5        U$ )Nc                 8    U H  nU R                  U5        M     g r   )r'  r   r0   r   s      r   r  /_set_decorators.<locals>.update.<locals>.update  s     r   r=   )r   r  r  s     r   r  _set_decorators.<locals>.update  s    	 	fr   c                    > S nT" U5        U$ )Nc                 f    [        X5      (       d  [        $ U H  nU R                  U5        M     U $ r   )r  NotImplementedr'  r>  s      r   __ior__1_set_decorators.<locals>.__ior__.<locals>.__ior__  s-    +D88%% Kr   r=   )r   rD  r  s     r   rD   _set_decorators.<locals>.__ior__  s    	 	gr   c                    > S nT" U5        U$ )Nc                 8    U H  nU R                  U5        M     g r   )r,  r>  s      r   difference_updateE_set_decorators.<locals>.difference_update.<locals>.difference_update  s    T" r   r=   )r   rI  r  s     r   rI  *_set_decorators.<locals>.difference_update  s    	# 	   r   c                    > S nT" U5        U$ )Nc                 f    [        X5      (       d  [        $ U H  nU R                  U5        M     U $ r   )r  rC  r,  r>  s      r   __isub__3_set_decorators.<locals>.__isub__.<locals>.__isub__  s.    +D88%%T" Kr   r=   )r   rN  r  s     r   rN  !_set_decorators.<locals>.__isub__  r  r   c                    > S nT" U5        U$ )Nc                     U R                  U5      [        U 5      p2X2-
  X#-
  pTU H  nU R                  U5        M     U H  nU R                  U5        M     g r   )r>  r   r  r'  r   otherwanthaver  r'  r   s          r   intersection_updateI_set_decorators.<locals>.intersection_update.<locals>.intersection_update  sN    **513t9$+t{CD!  r   r=   )r   rW  r  s     r   rW  ,_set_decorators.<locals>.intersection_update  s    	 	!"""r   c                    > S nT" U5        U$ )Nc                     [        X5      (       d  [        $ U R                  U5      [        U 5      p2X2-
  X#-
  pTU H  nU R	                  U5        M     U H  nU R                  U5        M     U $ r   )r  rC  r>  r   r  r'  rS  s          r   __iand__3_set_decorators.<locals>.__iand__.<locals>.__iand__  sd    +D88%%**513t9$+t{CD!  Kr   r=   )r   r\  r  s     r   r\  !_set_decorators.<locals>.__iand__      
	 	hr   c                    > S nT" U5        U$ )Nc                     U R                  U5      [        U 5      p2X2-
  X#-
  pTU H  nU R                  U5        M     U H  nU R                  U5        M     g r   )symmetric_differencer   r  r'  rS  s          r   symmetric_difference_updateY_set_decorators.<locals>.symmetric_difference_update.<locals>.symmetric_difference_update+  sN    22593t9$+t{CD!  r   r=   )r   rc  r  s     r   rc  4_set_decorators.<locals>.symmetric_difference_update*  s    	 	)***r   c                    > S nT" U5        U$ )Nc                     [        X5      (       d  [        $ U R                  U5      [        U 5      p2X2-
  X#-
  pTU H  nU R	                  U5        M     U H  nU R                  U5        M     U $ r   )r  rC  rb  r   r  r'  rS  s          r   __ixor__3_set_decorators.<locals>.__ixor__.<locals>.__ixor__8  sd    +D88%%22593t9$+t{CD!  Kr   r=   )r   rh  r  s     r   rh  !_set_decorators.<locals>.__ixor__7  r_  r   r  r  )r  r'  r,  r  r   r  r  rD  rI  rN  rW  r\  rc  rh  r  r  s                  @r   _set_decoratorsrk    s    7 ++m,K
		
	!	# +  	AEE'NEE-Hr   c                       \ rS rSrSrSrg)InstrumentedListiM  z-An instrumented version of the built-in list.r=   Nr7   r8   r9   r:   r;   r<   r=   r   r   rm  rm  M      7r   rm  c                       \ rS rSrSrSrg)InstrumentedSetiQ  z,An instrumented version of the built-in set.r=   Nrn  r=   r   r   rq  rq  Q  s    6r   rq  c                       \ rS rSrSrSrg)InstrumentedDictiU  z-An instrumented version of the built-in dict.r=   Nrn  r=   r   r   rs  rs  U  ro  r   rs  rd   r  r  )r   r   r   r'  r   r@  
itervaluesc                       \ rS rSrSrS r\R                  \R                  SS j5       5       r	\R                  \R                  SS j5       5       rSrg)	ro   io  a  A basic dictionary-based collection class.

Extends dict with the minimal bag semantics that collection
classes require. ``set`` and ``remove`` are implemented in terms
of a keying function: any callable that takes an object and
returns an object for use as a dictionary key.

c                     Xl         g)a   Create a new collection with keying provided by keyfunc.

keyfunc may be any callable that takes an object and returns an object
for use as a dictionary key.

The keyfunc will be called every time the ORM needs to add a member by
value-only (such as when loading instances from the database) or
remove a member.  The usual cautions about dictionary keying apply-
``keyfunc(object)`` should return the same output for the life of the
collection.  Keying based on mutable properties can result in
unreachable instances "lost" in the collection.

Nrp   )r   rq   s     r   r   MappedCollection.__init__y  s	     r   Nc                 J    U R                  U5      nU R                  X1U5        g)z9Add an item by value, consulting the keyfunc for the key.N)rq   r  r   r0   r   r4   s       r   r   MappedCollection.set  s"    
 ll5!]3r   c           	          U R                  U5      nX   U:w  a%  [        R                  " SU< SX   < SU< S35      eU R                  X25        g)z<Remove an item by value, consulting the keyfunc for the key.zCan not remove 'z': collection holds 'z' for key 'z'. Possible cause: is the MappedCollection key function based on mutable properties or properties that only obtain values after flush?N)rq   r   r   r  ry  s       r   r  MappedCollection.remove  sR    
 ll5! 9,, */	3@  	,r   rp   r   )r7   r8   r9   r:   r;   r   r   r   r   r   r   r  r<   r=   r   r   ro   ro   o  s\      ''4 ( 4 ''- ( -r   ro   r   )<r;   r~   r   sqlalchemy.util.compatr    r   r   r   r   sqlr	   r
   r   __all__	threadingLockrN  objectr   r?   r    r   rz   r   r   r   r   r   r   rI  rT  rM  rQ  r_  r`  ra  rb  r{  r  r  r  r  r  r  r   	frozensetr  r  r!  rk  r  rm  rq  r.   rs  rK  py3krt  ro   r=   r   r   <module>r     s  `D   9       ..--/    F :&"4 &R-*	5f 	5,(- E EP ((7  =o+ o+d%LP F&4*(V40
@#0;|	H<6aHhV # AbJ8t 87c 78t 8
 	

  	(
K xZH

 	yy !#3#5
6|
$&6&8	9 1-t 1-r " # " # / "r   