id.dZddlZddlZddlmZddlmZddlmZddlm Z dd l m Z gd Z e j ZGd d eZGd deZGddeZdZGddeZdZdZGddeZejdZ GddeZdz/_PlainColumnGetter.__call__..s=     ' 'uz3 ? ?   rr)rinstance_state _state_mapperr"rtuplervaluekeyr*r+s @@r__call__z_PlainColumnGetter.__call__s|#E**  u % %     zz!}}    > :: q6MrN)__name__ __module__ __qualname____doc__rrr"r3r%rrrrs]'''HHH     rrc$eZdZdZdZdZdZdS)_SerializableColumnGetterzlColumn-based getter used in version 0.7.6 only. Remains here for pickle compatibility with 0.7.6. cD||_t|dk|_dSrcolkeysrrrr<s rrz"_SerializableColumnGetter.__init__ W)rc t|jffSr)r9r<rs rrz$_SerializableColumnGetter.__reduce__s(4.sN     ' 'uz1>#9!#<     rr)rr-r.r<rr/r0s @@rr3z"_SerializableColumnGetter.__call__sv#E**  u % %     \     > :: q6MrN)r4r5r6r7rrr3r%rrr9r9sK ***:::     rr9c:eZdZdZdZdZedZdZdS)ra<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. cD||_t|dk|_dSrr;r=s rrz$_SerializableColumnGetterV2.__init__r>rc |j|jffSr) __class__r<rs rrz&_SerializableColumnGetterV2.__reduce__s~ ..rc:dfd|D}t|ffS)Nc\t|jtjsdS|jjSr) isinstancetabler TableClauser2)cs r _table_keyzA_SerializableColumnGetterV2._reduce_from_cols.._table_keys(agz'=>> #tw{"rc4g|]}|j|fSr%)r2)r(rNrOs rr,zA_SerializableColumnGetterV2._reduce_from_cols..s(888aAE::a==)888r)r)clsrr<rOs @rrz-_SerializableColumnGetterV2._reduce_from_colss: # # # 98884888*WJ66rcg}t|jdd}|jD]^\}}||||vr&||jj|3||j|j|_|S)Nmetadata)getattr local_tabler<appendrNtables)rr!rrSckeytkeys rr"z!_SerializableColumnGetterV2._colss6-z4@@ L ; ;LT4|x/4x3G3G F.067777 HOD13D9:::: rN) r4r5r6r7rr classmethodrr"r%rrrrsf  ***///77[7rrchdtj|D}t|fdS)aA 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. c8g|]}tj|dS) mapping_spec)r _only_column_elements)r(qs rr,z,column_mapped_collection..s5     (N;;   rc"tSrMappedCollectionkeyfuncsrz*column_mapped_collection..#G,,r)rto_listr)r]rrds @rr r sI  l++   D!&&G , , , ,,rc eZdZdZdZdZdS)_SerializableAttrGettercF||_tj||_dSr)nameoperator attrgettergetter)rrks rrz _SerializableAttrGetter.__init__s )$// rc,||Srrn)rtargets rr3z _SerializableAttrGetter.__call__s{{6"""rc t|jffSr)rirkrs rrz"_SerializableAttrGetter.__reduce__s& 44rN)r4r5r6rr3rr%rrririsA000###55555rric,t|fdS)aA 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"tSrrarpsrrez-attribute_mapped_collection..s#F++r)ri) attr_namerns @rrr s! %Y / /F + + + ++rcfdS)aA 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"tSrrarcsrrez#mapped_collection..*rfrr%rcs`rr r s - , , ,,rcPeZdZdZedZedZedZedZee j dddZ e Z ee j d d d Z ed Zed ZedZedZdS)r a}Decorators for entity collection classes. The decorators fall into two groups: annotations and interception recipes. The annotating decorators (appender, remover, iterator, linker, 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): ... cd|_|S)aTag 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_rolefns rrzzcollection.appenderGsR", rcd|_|S)aTag 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 rrzcollection.removerss0"+ rcd|_|S)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 rrzcollection.iterators", rcd|_|S)aTag 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 rinternally_instrumentedz"collection.internally_instrumenteds$# rz1.0zThe :meth:`.collection.linker` handler is deprecated and will be removed in a future release. Please refer to the :meth:`.AttributeEvents.init_collection` and :meth:`.AttributeEvents.dispose_collection` event handlers. cd|_|S)aTag the method as a "linked to attribute" event handler. This optional event handler will be called when the collection class is linked to or unlinked from the InstrumentedAttribute. It is invoked immediately after the '_sa_adapter' property is set on the instance. A single argument is passed: the collection adapter that has been linked, or None if unlinking. linkerr{r}s rrzcollection.linkers&"* rz1.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.cd|_|S)aTag 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 rrzcollection.convertersJ"- rcfd}|S)aMark 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): ... cdf|_|S)Nfire_append_event_sa_instrument_beforer~args r decoratorz"collection.adds..decorator(;S'AB $Irr%rrs` raddszcollection.adds$"     rcfd}|S)aMark 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(df|_d|_|S)Nrfire_remove_event)r_sa_instrument_afterrs rrz&collection.replaces..decorators(;S'AB $&9B #Irr%rs` rreplaceszcollection.replacess$       rcfd}|S)aMark 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. cdf|_|SNrrrs rrz%collection.removes..decorator6rrr%rs` rremoveszcollection.removes%rrc d}|S)aMark 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. cd|_|Sr)rr}s rrz,collection.removes_return..decoratorLs&9B #Irr%)rs rremoves_returnzcollection.removes_return<s    rN)r4r5r6r7 staticmethodrzrrrr deprecatedrlinkrrrrrr%rrr r -s2))\)V\4  \ \(T_  K  \  DT_  ?\@\,\,\,\rr _sa_adapterceZdZdZdZdZdZedZedZ dZ dd Z d Z d Z d Zdd ZdZddZdZdZdZdZeZddZddZddZdZdZdS)CollectionAdapteraiBridges 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 invalidatedc||_|j|_tj||_||_||_|j|_ d|_ dS)NF) rr2rweakrefrefrrr _sa_converterrr)rrrdatas rrzCollectionAdapter.__init__msK H [&& &, rc.tjddS)Nz%This collection has been invalidated.)rwarnrs r_warn_invalidatedz#CollectionAdapter._warn_invalidatedvs 9:::::rc*|S)z$The entity collection being adapted.)rrs rrzCollectionAdapter.datayszz||rcX|jj|j|uS)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. )rr'rrrs r_referenced_by_ownerz&CollectionAdapter._referenced_by_owner~s$$TY/4::<<??rc4|jSrr _sa_appenderrs r bulk_appenderzCollectionAdapter.bulk_appenderszz||((rNcX|||dS)z8Add an entity to the collection, firing mutation events. _sa_initiatorNrritem initiators rappend_with_eventz#CollectionAdapter.append_with_events+ !!$i!@@@@@rcX||ddSz=Add or restore an entity to the collection, firing no events.FrNrrrs rappend_without_eventz&CollectionAdapter.append_without_events) !!$e!<<<<Empty the collection, firing a mutation event for each entity.rNrrlist)rrrrs rclear_with_eventz"CollectionAdapter.clear_with_eventsK**,,*JJ 3 3D GD 2 2 2 2 2 3 3rcv|j}t|D]}||ddS)z'Empty the collection, firing no events.FrNr)rrrs rclear_without_eventz%CollectionAdapter.clear_without_eventsK**,,*JJ / /D GD . . . . . / /rcht|S)z(Iterate over entities in the collection.)iterr _sa_iteratorrs r__iter__zCollectionAdapter.__iter__s&DJJLL--//000rctt|S)z!Count entities in the collection.)rrrrrs r__len__zCollectionAdapter.__len__s,4 113344555rcdSNTr%rs r__bool__zCollectionAdapter.__bool__strc|durG|jr||j|j|jj||S|S)a Notify 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)rrrrrr'rs rrz#CollectionAdapter.fire_append_events_ E ! ! )&&(((9.. $"2"7y Krc|durI|jr||j|j|jj||dSdS)aNotify 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)rrrrrr'rs rrz#CollectionAdapter.fire_remove_eventsj E ! ! )&&((( I ' ' $"2"7y      " !rc|jr||j|j|jj|dS)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(). rN)rrrfire_pre_remove_eventrr')rrs rrz'CollectionAdapter.fire_pre_remove_eventsZ   %  " " $ $ $ ''  d.3y (     rcN|j|j|jj|j|jdS)N)r2r owner_clsrr)rrclass_rrrs r __getstate__zCollectionAdapter.__getstate__s09+)0I+    rc|d|_|d|_tj|d|_|dj|_||d_|d|_t|d|jj |_ dS)Nr2rrrr) rrrrrrrrrrTimplr)rds r __setstate__zCollectionAdapter.__setstate__steH ]+[6++ F)1 $& ]+AkNDI66; rr)r4r5r6r7 __slots__rrpropertyrrrrrrrrrrrrrr __nonzero__rrrrrr%rrrrWs  I!!!;;;X@@X@)))AAAA ===000 (((@@@@<<<3333///111 666K$            <<<<.wrapperUs"%%''  +++rz %sWrapper)rr4r7) specimen_clsrrr s ` @rrrMsQ 0 =,,,,,, #%5%>>G&.GO Nrc|jdkrtjdt|\}}t |||t |||t |||dS)z6Modify methods in a class and install instrumentation. __builtin__zGCan not instrument a built-in type. Use a subclass, even a trivial one.N)r5sa_exc ArgumentError_locate_roles_and_methods_setup_canned_roles_assert_required_roles_set_collection_attributesrQrolesmethodss rrr`sz  ~&&" ,   /s33NE7UG,,,3w///sE733333rci}i}|jD]}t|D]\}}tj|st |dr|j}|||d\}}t |dr|j\} } | | f}t |dr |j } | }|r ||fz||<|rdd|f||<||fS)zgsearch for _sa_instrument_role-decorated methods in method resolution order, assign to roles. r|)NNrrN) __mro__varsrrcallablehasattrr| setdefaultrr) rQrrsuperclsrkmethodrolebeforeafteroparguments rrrus% EGK22 NN0022 2 2LD&=(( v455 -1  t,,,'MFEv677 &%; HXv566 0 2 &% 1  2 $dE 1 = 2> '>rcztj|}|tvrt|\}}|D]\}}||||D]H\}} t ||d} | r.||vr*t | dst||| | GdSdS)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)rduck_type_collection __interfacesrr!rTr setattr) rQrrcollection_type canned_roles decoratorsr$rkr#rr~s rrrs/44O,&&#/#@ j&,,.. ) )JD$   T4 ( ( ( (",!1!1!3!3 4 4 FIfd++B 4'))$677*VYYr]]333'&  4 4rc.d|vst||dstjd|jz|d|vr/tt ||dds d||d<d|vst||dstjd|jz|d|vr/tt ||dds d||d<d|vst||dstjd |jzd S) zTensure all roles are present, and apply implicit instrumentation if needed rzz>Type %s must elect an appender method to be a collection classr)rrNrzType %s must elect an iterator method to be a collection classN)r rrr4rTrs rrrse gc53D&E&E" !#&< 0    z ' ) )'U:&'');33 )&Dj!"WS% 2B%C%C" !#&< 0    y  ( (U9%&&(:22 (%Ci !gc53D&E&E" !#&< 0   rc ||D]8\}\}}}t||tt|||||9|D]'\}}t|d|zt||(d|_t |dsd|_t||_dS)zkapply ad-hoc instrumentation from decorators, class-level defaults and implicit role declarations z_sa_%sNr) rr,_instrument_membership_mutatorrTrr rrr)rQrr method_namer%r(r&r$s rrrs 3:--//  . .fh   *[))68U      #[[]]AAkX_gc;&?&?@@@@CO 3 ( (! c77Crcrttjtd}t t r t |kr|pdn|vr|nd~fd}d|_tdr j |_ j |_ j |_ |S)zIRoute method args and/or return value through the collection adapter.rNcrf $ |vrtjdz| }n@t| kr | }n$ |vr | }ntjdz|dd}|durd}n |dj}r|rt |||r|s |i|S |i|}|t ||||S)NzMissing argument %srFr)rrrpoprrT) argskwr1rexecutorresr&r(r%r# named_argpos_args rrz/_instrument_membership_mutator..wrappersN  B&& .-89 t99w&& MEE"__yMEE .-8FF?D11   HHAw*H  8h 8 %GHf % %eY 7 7 7 H 64&2&& &&$%"%%C(%((i888JrTr|) rrflatten_iteratorrrKintrindexrr r|r4r7)r#r%r(r&fn_argsrr;r<s```` @@rr2r2s   !"8"@"@"C D D   h $ $ !GG x/EGH4EMII7""!--11 I !!!!!!!!!!F $Gv,--A&,&@#GnGO NrcL|dur|j}|r|||}|S)z^Run set events. This event always occurs before the collection is actually mutated. F)rrr rrr9s r__setrC/s:E!!)  C--dMBBD KrcT|dur!|j}|r|||dSdSdS)aRun 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)rrrBs r__delrE=sME!!)  <  & &t] ; ; ; ; ;"! < ._tidyV$"T2;//7 rc,dfd }||S)NcBt|||}||dSrrC)rrrr~s rrVz0_list_decorators..append..append[s't]33D BtTNNNNNrrr%)r~rVrJs` rrVz _list_decorators..appendZs6       f  rc,dfd }||S)NcBt|||||dSrrErr1rr~s rremovez0_list_decorators..remove..removecs( $} - - - BtUOOOOOrrr%r~rSrJs` rrSz _list_decorators..removebs6       f  rc*fd}||S)NcBt||}|||dSrrN)rr?r1r~s rinsertz0_list_decorators..insert..insertls,$&&E BtUE " " " " "rr%)r~rWrJs` rrWz _list_decorators..insertks1 # # # # # f  rc*fd}||S)Ncbt|ts9||}|t||t||} |||dS|jpd}|jpd}|dkr|t |z }|j|j}nt |}|dkr|t |z }|dkr`||urdSt|||D]}t ||kr||=t|D]\}}| ||z|dStt|||} t |t | kr/tdt |dt | t| |D]\}}|||dS)Nrrz#attempt to assign sequence of size z to extended slice of size )rKslicerErCstepstartrstoprange enumeraterWr ValueErrorzip __setitem__) rr?r1existingr[r\r]irrngr~s rrbz:_list_decorators..__setitem__..__setitem__tseU++% 2;'$)))dE**4&&&&&zQ (q199SYY&E:) :DDt99D!88CII%D199}}"5$55,,t99u,, $U #,U#3#3554 AIt444455uUD$7788C5zzSXX--(j #5zzzz3s8885 $'sE??224((D111122rr%r~rbrJs` rrbz%_list_decorators..__setitem__ss6& 2& 2& 2& 2& 2P krc*fd}||S)Nct|ts&||}t||||dS||D]}t||||dSr)rKrZrErr?rr~s r __delitem__z:_list_decorators..__delitem__..__delitem__s|eU++ E{dD!!!4 !K&&D$%%%%4rr%r~rjrJs` rrjz%_list_decorators..__delitem__s5  krc*fd}||S)Nc|||D]}t|fd|D}|||dS)Nc0g|]}t|Sr%rN)r(r1rs rr,zP_list_decorators..__setslice__..__setslice__..s#AAA%e,,AAArrQ)rr\endrr1r~s` r __setslice__z<_list_decorators..__setslice__..__setslice__sc!%)_''E$&&&&AAAA&AAA4V,,,,,rr%)r~rprJs` rrpz&_list_decorators..__setslice__s5 - - - - - E,    rc*fd}||S)Nc\|||D]}t|||||dSrrQ)rr\ror1r~s r __delslice__z<_list_decorators..__delslice__..__delslice__sG!%)_''E$&&&&4$$$$$rr%)r~rsrJs` rrsz&_list_decorators..__delslice__s5 % % % % % E,    rc$d}||S)Nc:|D]}||dSrrVriterabler1s rextendz0_list_decorators..extend..extends0! # # E"""" # #rr%)r~ryrJs rryz _list_decorators..extends& # # # f  rc$d}||S)Nc:|D]}|||Srrvrws r__iadd__z4_list_decorators..__iadd__..__iadd__s-" # # E""""Krr%)r~r|rJs rr|z"_list_decorators..__iadd__&    hrc,dfd }||S)Nc^t|||}t|||SrrGrEris rr6z*_list_decorators..pop..pops5    2dE??D $   Krrr%r~r6rJs` rr6z_list_decorators..pops6       c  rc,dfd }||S)NrcH|D]}t|||dSrrQris rclearz._list_decorators..clear..clears6 &&D$%%%%4rrr%r~rrJs` rrz_list_decorators..clears6       E%LLLLrrJ)rpy2klocalscopyr6) rVrSrWrbrjrprsryr|r6rlrJs @r_list_decoratorsrSse888*****X" y                 9        AEE'NNN Hrc d tjd fd} fd} fd} fd} fd} fd} fd }t}|d |d|S) zBTailored instrumentation wrappers for any dict-like mapping class.c\d|_tt|jj|_dSr)rrTr'r4r7r}s rrJz_dict_decorators.._tidyrKr Unspecifiedc,dfd }||S)Ncz||vrt||||t|||}|||dSr)rErC)rr2r1rr~s rrbz:_dict_decorators..__setitem__..__setitem__sMd{{dDI}555$}55E BtS% rrr%rfs` rrbz%_dict_decorators..__setitem__s: ! ! ! ! ! ! krc,dfd }||S)NcV||vrt||||||dSrrQ)rr2rr~s rrjz:_dict_decorators..__delitem__..__delitem__ s5d{{dDI}555 BtSMMMMMrrr%rks` rrjz%_dict_decorators..__delitem__ s:       krc*fd}||S)NcT|D]}t||||dSrrQ)rr2r~s rrz._dict_decorators..clear..clears: ' 'dDI&&&& BtHHHHHrr%rs` rrz_dict_decorators..clears1      e  rc0ffd }||S)Nct|||v}|ur ||}n |||}|rt|||Srr)rr2default_to_delrrr~s rr6z*_dict_decorators..pop..popsf    TkG+%%r$}}r$W-- "dD!!!Krr%)r~r6rrJs` rr6z_dict_decorators..pops>#.        c  rc*fd}||S)Ncht||}t||d|Srrrrr~s rpopitemz2_dict_decorators..popitem..popitem,s7    2d88D $Q Krr%)r~rrJs` rrz!_dict_decorators..popitem+s1      grc&dd}||S)Ncd||vr||||S||Sr)rb __getitem__)rr2rs rr!z8_dict_decorators..setdefault..setdefault6s:$  g...'',,,rrr%)r~r!rJs rr!z$_dict_decorators..setdefault5s/ - - - - jrc,ffd }||S)Nc|ur]t|dr2t|D]!}||vs||||ur ||||<"n|D]\}}||vs |||ur|||<|D]!}||vs||||ur ||||<"dS)Nkeys)r r)r__otherr8r2r1rs rupdatez0_dict_decorators..update..updateAsk))7F++.#G}}55d??d3iws|.K.K(/ DI5'... Ud??d3iu.D.D(-DI ( (d??d3ir#w&>&> "3DI ( (rr%)r~rrrJs rrz _dict_decorators..update@s8!, ( ( ( ( ( ( f  rrJrsymbolrrr6) rbrjrr6rr!rrrrJs @@r_dict_decoratorsrs888+m,,K           $  AEE'NNNEE- Hrc>t|t|jfzS)zKAllow only set, frozenset and self.__class__-derived objects in binops.)rK_set_binop_basesrHrobjs r_set_binops_check_strictr[s c+t~.?? @ @@rcxt|t|jfzptj|t kS)z5Allow anything set-like to participate in set binops.)rKrrHrr*setrs r_set_binops_check_looseras9 3(DN+<<== 1  $S ) )S 0rcLdtjd}fd}fd}fd}fd}fd}fd}fd }fd }fd } fd } fd } fd} fd} t}|d|d|S)z9Tailored instrumentation wrappers for any set-like class.c\d|_tt|jj|_dSr)rrTrr4r7r}s rrJz_set_decorators.._tidyls$"S"+..6 rrc,dfd }||S)NcJ||vrt|||}||dSrrNrRs raddz)_set_decorators..add..addss2D  dE=99 BtUOOOOOrrr%)r~rrJs` rrz_set_decorators..addrs6       c  rc,dfd }||S)NcJ||vrt|||||dSrrQrRs rdiscardz1_set_decorators..discard..discard}1}}dE=111 BtUOOOOOrrr%)r~rrJs` rrz _set_decorators..discard|s6       grc,dfd }||S)NcJ||vrt|||||dSrrQrRs rrSz/_set_decorators..remove..removerrrr%rTs` rrSz_set_decorators..removes6       f  rc*fd}||S)Nc\t||}t|||Srrrs rr6z)_set_decorators..pop..pops5    2d88D $   Krr%rs` rr6z_set_decorators..pops1      c  rc$d}||S)NcTt|D]}||dSr)rrSrs rrz-_set_decorators..clear..clears6T  " " D!!!! " "rr%rs rrz_set_decorators..clears& " " " e  rc$d}||S)Nc:|D]}||dSr)rrr1rs rrz/_set_decorators..update..updates,    rr%)r~rrJs rrz_set_decorators..updates&    f  rc$d}||S)Ncht||stS|D]}|||Sr)rNotImplementedrrs r__ior__z1_set_decorators..__ior__..__ior__s?+D%88 &%%  Krr%)r~rrJs rrz _set_decorators..__ior__s&    grc$d}||S)Nc:|D]}||dSr)rrs rdifference_updatezE_set_decorators..difference_update..difference_updates0 # # T"""" # #rr%)r~rrJs rrz*_set_decorators..difference_updates+ # # #      rc$d}||S)Ncht||stS|D]}|||Sr)rrrrs r__isub__z3_set_decorators..__isub__..__isub__sC+D%88 &%% # # T""""Krr%)r~rrJs rrz!_set_decorators..__isub__r}rc$d}||S)Nc||t|}}||z ||z }}|D]}|||D]}||dSr)rrrSrrotherwanthaverSrrs rintersection_updatezI_set_decorators..intersection_update..intersection_updates~**5113t99$D+td{CF " " D!!!!    rr%)r~rrJs rrz,_set_decorators..intersection_updates+    !"""""rc$d}||S)Nct||stS||t|}}||z ||z }}|D]}|||D]}|||Sr)rrrrrSrrs r__iand__z3_set_decorators..__iand__..__iand__s+D%88 &%%**5113t99$D+td{CF " " D!!!!  Krr%)r~rrJs rrz!_set_decorators..__iand__&    hrc$d}||S)Nc||t|}}||z ||z }}|D]}|||D]}||dSr)symmetric_differencerrSrrs rsymmetric_difference_updatezY_set_decorators..symmetric_difference_update..symmetric_difference_updates~225993t99$D+td{CF " " D!!!!    rr%)r~rrJs rrz4_set_decorators..symmetric_difference_updates+    )*****rc$d}||S)Nct||stS||t|}}||z ||z }}|D]}|||D]}|||Sr)rrrrrSrrs r__ixor__z3_set_decorators..__ixor__..__ixor__s+D%88 &%%225993t99$D+td{CF " " D!!!!  Krr%)r~rrJs rrz!_set_decorators..__ixor__rrrJr)rrrrSr6rrrrrrrrrrrJs @r_set_decoratorsris777+m,,K                    !!!!!      # # # # # + + + + +  AEE'NNNEE- HrceZdZdZdS)InstrumentedListz-An instrumented version of the built-in list.Nr4r5r6r7r%rrrr 7777rrceZdZdZdS)InstrumentedSetz,An instrumented version of the built-in set.Nrr%rrrrs6666rrceZdZdZdS)InstrumentedDictz-An instrumented version of the built-in dict.Nrr%rrrrrrrrVrSr)rzrrrrr itervaluesceZdZdZdZejejddZej ejddZ dS)rba)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||_dS)ahCreate 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. Nrc)rrds rrzMappedCollection.__init__8s rNc^||}||||dS)z9Add an item by value, consulting the keyfunc for the key.N)rdrbrr1rr2s rrzMappedCollection.setHs3 ll5!! e]33333rc ||}|||kr$tjd|d||d|d|||dS)zrs``D999999   .--//        F:&&&&&"4&&&R---* 5 5 5 5 5f 5 5 5,,,( - - - ccccccccL )X(77=h<h<h<h<h<h<h<h