[Jc @sdZddkZddkZddkZddkZddkZddkiZddk l Z ddk l Z l Z ddddd gZe iiZd Zd Zd Zdefd YZdZdZdefdYZdZdZdZdZdZedZ edZ!edZ"dZ#dZ$e i%oe&e'fZ(nddk)Z)e&e'e)i*fZ(dZ+dZ,dZ-de.fd YZ/d!e&fd"YZ0d#e1fd$YZ2he/e.6e0e&6e2e16Z3hhd%d&6d'd(6d)d*6e#d+6e.6hd,d&6d'd(6d)d*6e-d+6e&6hd-d*6e$d+6e16he6Z4d.e1fd/YZ5dS(0sJSupport 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 ``InstrumentedCollectionAttribute`` 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 ``relation(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 InstrumentedCollectionAttribute are also reachable through the adapter, allowing for some very sophisticated behavior. iN(t expression(tschematutilt collectiontcollection_adaptertmapped_collectiontcolumn_mapped_collectiontattribute_mapped_collectioncsddklddklg}tiD]}|ti|q4~tdjofdn"t fdfdS(sA dictionary-based collection type with column-based keying. Returns a 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. i(t _state_mapper(tinstance_stateics,|}|}|i|dS(Ni(t_get_state_attr_by_column(tvaluetstatetm(tcolsR R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytkeyfuncs  cs5|tfdDS(Nc3s%x|]}i|VqWdS(N(R (t.0tc(R R (s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pys s (ttuple(R (t mapping_specR R(R R s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  cs tS((tMappedCollection((R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyts( tsqlalchemy.orm.utilRtsqlalchemy.orm.attributesR Rtto_listRt _no_literalstlenR(Rt_[1]tq((RRR RRs>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRus 3 cs fdS(sA dictionary-based collection type with attribute-based keying. Returns a MappedCollection factory with a keying based on the 'attr_name' attribute of entities in the collection. 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. csttiS((Rtoperatort attrgetter((t attr_name(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs((R((Rs>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs cs fdS(sA dictionary-based collection type with arbitrary keying. Returns a 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. cs tS((R((R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs((R((Rs>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs cBseZdZedZedZedZedZedZedZ edZ edZ ed Z ed Z RS( sDecorators for entity collection classes. The decorators fall into two groups: annotations and interception recipes. The annotating decorators (appender, remover, iterator, internally_instrumented, on_link) 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): ... Decorators can be specified in long-hand for Python 2.3, or with the class-level dict attribute '__instrumentation__'- see the source for details. cCst|dd|S(sTag 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. t_sa_instrument_roletappender(tsetattr(tfn((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR!s)cCst|dd|S(s 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 '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. R tremover(R"(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR$scCst|dd|S(sTag 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): ... R titerator(R"(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR%s cCst|dt|S(sTag 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 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_instrumented(R"tTrue(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytinternally_instrumented"scCst|dd|S(sTag the method as a the "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. R ton_link(R"(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR)6s cCst|dd|S(sTag 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, it's 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. R t converter(R"(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR*Dscsfd}|S(sMark 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): ... cst|ddf|S(Nt_sa_instrument_beforetfire_append_event(R"(R#(targ(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt decoratorus((R-R.((R-s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytaddsescsfd}|S(sMark 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): ... cs*t|ddft|dd|S(NR+R,t_sa_instrument_aftertfire_remove_event(R"(R#(R-(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR.s((R-R.((R-s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytreplaceszscsfd}|S(sMark 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. cst|ddf|S(NR+R1(R"(R#(R-(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR.s((R-R.((R-s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytremovesscCs d}|S(sMark 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. cSst|dd|S(NR0R1(R"(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR.s((R.((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytremoves_returns (t__name__t __module__t__doc__t staticmethodR!R$R%R(R)R*R/R2R3R4(((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs,!cCst|ddS(s-Fetch the CollectionAdapter for a collection.t _sa_adapterN(tgetattrtNone(R((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRsc CsSy t|dt|dSWn,tj o tdt|inXdS(sIterate over an object supporting the @iterator or __iter__ protocols. If the collection is an ORM collection, it need not be attached to an object to be iterable. t _sa_iteratort__iter__s'%s' object is not iterableN(R:tAttributeErrort TypeErrorttypeR5(R((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytcollection_iters  tCollectionAdaptercBseZdZdZedddZdZdZdZddZ d Z dd Z d Z dd Zd ZdZdZdZddZddZddZdZdZRS(saBridges 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 an CollectionAdapter exclusively for interaction with entity collections. cCs5||_ti||_||_|i|dS(N(tattrtweakreftreft_datat owner_statet link_to_self(tselfRCRGtdata((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__init__s  cCs |iS((RF(ts((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRstdocs$The entity collection being adapted.cCs;t|d|t|dot|d|ndS(s9Link a collection to this adapter, and fire a link event.R9t _sa_on_linkN(R"thasattrR:(RIRJ((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRHscCs;t|ddt|dot|ddndS(s<Unlink a collection from any adapter, and fire a link event.R9RNN(R"R;ROR:(RIRJ((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytunlinkscCs3t|idd}|dj o ||Sti|}ti|i}|djp ||jof|djodp |ii}|djo|iii}n |i}td||fnt|dddj ot|dS|tjot|dt|dSt |SdS(sConverts collection-compatible objects to an iterable of values. Can be passed any type of object, and if the underlying collection determines that it can be adapted into a stream of values it can use, returns an iterable of values suitable for append()ing. This method may raise TypeError or any other suitable exception if adaptation fails. If a converter implementation is not supplied on the collection, a default duck-typing-based implementation is used. t _sa_converterR;s/Incompatible collection type: %s is not %s-likeR9t itervaluestvaluesN( R:RFR;Rtduck_type_collectiont __class__R5R?tdicttiter(RItobjR*t setting_typetreceiving_typetgiventwanted((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytadapt_like_to_iterables$      cCs#t|id|d|dS(s8Add an entity to the collection, firing mutation events.t _sa_appendert _sa_initiatorN(R:RF(RItitemt initiator((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytappend_with_eventscCs#t|id|dtdS(s=Add or restore an entity to the collection, firing no events.R^R_N(R:RFtFalse(RIR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytappend_without_eventscCs#t|id|d|dS(s=Remove an entity from the collection, firing mutation events.t _sa_removerR_N(R:RF(RIR`Ra((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytremove_with_event scCs#t|id|dtdS(s7Remove an entity from the collection, firing no events.ReR_N(R:RFRc(RIR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytremove_without_event$scCs+x$t|D]}|i||q WdS(s>Empty the collection, firing a mutation event for each entity.N(tlistRf(RIRaR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytclear_with_event(s cCs(x!t|D]}|i|q WdS(s'Empty the collection, firing no events.N(RhRg(RIR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytclear_without_event-s cCst|idS(s(Iterate over entities in the collection.R<(R:RF(RI((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR=2scCs"ttt|idS(s!Count entities in the collection.R<(RRhR:RF(RI((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__len__6scCstS(N(R'(RI((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt __nonzero__:scCsE|tj o0|dj o#|ii|i|ii||S|SdS(sNotify that a entity has entered 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. N(RcR;RCR,RGRV(RIR`Ra((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR,=s#cCsD|tj o3|dj o&|ii|i|ii||ndS(sNotify 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. N(RcR;RCR1RGRV(RIR`Ra((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR1JscCs&|ii|i|iid|dS(sNotify that an entity is about to be removed from the collection. Only called if the entity cannot be removed after calling fire_remove_event(). RaN(RCtfire_pre_remove_eventRGRV(RIRa((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRmUscCs%h|iid6|id6|id6S(NtkeyRGRJ(RCRnRGRJ(RI((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt __getstate__^s cCsMt|dii|di|_|d|_ti|d|_dS(NRGRnRJ( R:RXRUtimplRCRGRDRERF(RItd((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt __setstate__cs& N(R5R6R7RKtpropertyRJRHRPR]R;RbRdRfRgRiRjR=RkRlR,R1RmRoRr(((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRBs*       )          cCst|tpt|}nti}||pdi|pd}||pdi|}||pdi|}xQ|pdD]B}||jo|i|q||jo|i|qqW|o"x|D]}|i|qWndS(s"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. values An iterable of collection member instances existing_adapter A CollectionAdapter of instances to be replaced new_adapter An empty CollectionAdapter to load with ``values`` N(((((( t isinstanceRhRt IdentitySett intersectiont differenceRbRdRf(RStexisting_adaptert new_adaptertidsett constantst additionstremovalstmember((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt bulk_replaceis  #  cCs|tjot|}nt|}|tjot|}|}ntioCz1t|ddt|jot|nWdti Xn|S(soPrepare 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( t__canned_instrumentationR@t__converting_factoryt__instrumentation_mutextacquireR:R;tidt_instrument_classtrelease(tfactorytcls((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytprepare_instrumentations     cs=fd}y di|_i|_WnnX|S(sConvert the type returned by collection factories on the fly. Given a collection factory that returns a builtin type (e.g. a list), return a wrapped function that converts that type to one of our instrumented types. csD}t|}|tjot||StiddS(NsDCollection class factories must produce instances of a single class.(R@Rtsa_exctInvalidRequestError(Rttype_(toriginal_factory(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytwrappers    s %sWrapper(R5R7(RR((Rs>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs c Cs|idjotidnti|}|tjo&t|i}|idh}nhh}}t|do#|i ti t |dn|idh}xt |D]}t ||d}ti|pqnt|do|i}|||Type %s must elect an appender method to be a collection classR,R$s<Type %s must elect a remover method to be a collection classR1R%s>Type %s must elect an iterator method to be a collection classs_sa_%sN(NN(sfire_append_eventiN(sfire_remove_eventiN(R6Rt ArgumentErrorRRTt __interfacestcopytpopROtupdatetdeepcopyR:tdirR;tcallableR R+R0titemsR"R5t_instrument_membership_mutatorR(Rtcollection_typetrolest decoratorsRtnametmethodtroletbeforetaftertoptargumentR.R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs~   #      """   !csottitid}ttjo.t|jo |pdn-|jo|i nd~nfd}y%t |_ i |_ i |_ WnnX|S(sERoute method args and/or return value through the collection adapter.ics\odjo2|jotidn|}qt|jo|}q|jo|}qtidn|idd}|tjo d}nt|ddd}o!|ot|||n p| o||S||}|dj ot|||n|SdS(NsMissing argument %sR_iR9(R;RRRRRcR:(targstkwR Ratexecutortres(t named_argRtpos_argRRR(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRGs0      N(RhRtflatten_iteratortinspectt getargspecR@tintRR;tindexR'R&R5R7(RRRRtfn_argsR((RRRRRRs>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR7s$"(    cCsW|tj oF|dj o9t|dd}|ot|d||}qSn|S(s:Run set events, may eventually be inlined into decorators.R9R,N(RcR;R:(RR`R_R((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__setos  cCsU|tj oD|dj o7t|dd}|ot|d||qQndS(s:Run del events, may eventually be inlined into decorators.R9R1N(RcR;R:(RR`R_R((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__delxscCs4t|dd}|ot|d|ndS(s5Special method to run 'commit existing value' methodsR9RmN(R:R;(RR_R((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__before_deletesc sdfd}fd}fd}fd}fd}fd}fd}fd }fd }fd } ti} | id | S( s:Tailored instrumentation wrappers for any list-like class.cSs2t|dtttt|id|_dS(NR&R7(R"R'R:RhR5R7(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt_tidyscs dfd}||S(Ncs#t|||}||dS(N(R(RIR`R_(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytappends(R;(R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs cs dfd}||S(Ncs.t||||t|||dS(N(RR(RIR R_(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytremoves  (R;(R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csfd}||S(Ncs#t||}|||dS(N(R(RIRR (R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytinserts((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csfd}||S(Nc st|tpK||}|dj ot||nt||}|||nF|idjo d}n1|idjot||i}n |i}|ipd}t|i pd||}|djoSx|D]}||i =qW|i }x|D] }|i |||d7}q Wnpt|t|jo&t dt|t|fnx-t ||D]\}}|i ||qWdS(NiisBattempt to assign sequence of size %s to extended slice of size %s(RttsliceR;RRtstopRtsteptrangetstartRt ValueErrortzipt __setitem__( RIRR texistingRRtrngtiR`(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs<        ((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csfd}||S(Ncskt|tp(||}t||||n0x||D]}t||qCW||dS(N(RtRR(RIRR`(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt __delitem__s   ((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csfd}||S(Nc sfx"|||!D]}t||qWg}|D]}|t||q0~}||||dS(N(RR(RIRtendRSR R(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt __setslice__s *((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csfd}||S(Ncs9x"|||!D]}t||qW|||dS(N(R(RIRRR (R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt __delslice__s((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csd}||S(NcSs"x|D]}|i|qWdS(N(R(RItiterableR ((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytextends((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  csd}||S(NcSs"x|D]}|i|qW|S(N(R(RIRR ((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__iadd__s((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  cs dfd}||S(Nics*t|||}t|||S(N(RR(RIRR`(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  ((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs R(tlocalsRR( RRRRRRRRRRtl((Rs>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt_list_decoratorss  $   c sdtidfd}fd}fd}fd}fd}fd}tidjofd }nfd }ti}|id |id|S(sBTailored instrumentation wrappers for any dict-like mapping class.cSs2t|dtttt|id|_dS(NR&R7(R"R'R:RVR5R7(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRst Unspecifiedcs dfd}||S(NcsK||jot||||nt|||}|||dS(N(RR(RIRnR R_(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs (R;(R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs cs dfd}||S(Ncs6||jot||||n||dS(N(R(RIRnR_(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs (R;(R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csfd}||S(Ncs0x|D]}t|||qW|dS(N(R(RIRn(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytclear&s((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR%s cs#fd}||S(NcsQ||jot|||n|jo||S|||SdS(N(R(RIRntdefault(RR#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR.s   ((R#R(RR(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR-s csfd}||S(Ncs+t||}t||d|S(Ni(RR(RIR`(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytpopitem9s  ((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR8s csdd}||S(NcSs3||jo|i|||S|i|SdS(N(Rt __getitem__(RIRnR((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt setdefaultBs (R;(R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRAs  iicsd}||S(NcSsOxH|iD]:}||jp||||j o||||/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRMs "((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRLs  cs fd}||S(Ncs|j ot|doOx|iD]:}||jp||||j o||||/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRUs    "((R#R(RR(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRTs R(ii(Rtsymboltsyst version_infoRRR(RRRRRRRR((RRs>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt_dict_decorators s       cCst|t|ifS(sGAllow only set, frozenset and self.__class__-derived objects in binops.(Rtt_set_binop_basesRU(RIRX((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt_set_binops_check_strictqscCs-t|t|ifpti|tjS(s5Allow anything set-like to participate in set binops.(RtRRURRTtset(RIRX((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt_set_binops_check_looseuscs+dtid}fd}tidjofd}nfd}fd}fd }fd }fd }fd }fd }fd} fd} fd} fd} fd} ti}|id|id|S(s9Tailored instrumentation wrappers for any set-like class.cSs2t|dtttt|id|_dS(NR&R7(R"R'R:RR5R7(R#((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR~sRcs dfd}||S(Ncs4||jot|||}n||dS(N(R(RIR R_(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytadds (R;(R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs iicsdd}||S(NcSs%||jo|i||ndS(N(R(RIR R_((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytdiscards (R;(R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  cs dfd}||S(Ncs2||jot|||n||dS(N(R(RIR R_(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs (R;(R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs cs dfd}||S(Ncs2||jot|||n||dS(N(R(RIR R_(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs (R;(R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csfd}||S(Ncs't||}t|||S(N(RR(RIR`(R#(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs   ((R#R(R(R#s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csd}||S(NcSs(x!t|D]}|i|q WdS(N(RhR(RIR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs ((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  csd}||S(NcSs"x|D]}|i|qWdS(N(R(RIR R`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  csd}||S(NcSs7t||ptSx|D]}|i|qW|S(N(RtNotImplementedR(RIR R`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__ior__s ((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  csd}||S(NcSs"x|D]}|i|qWdS(N(R(RIR R`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytdifference_updates((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  csd}||S(NcSs7t||ptSx|D]}|i|qW|S(N(RRR(RIR R`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__isub__s ((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  csd}||S(NcSsq|i|t|}}||||}}x|D]}|i|q8Wx|D]}|i|qVWdS(N(RvRRR(RIRtwantthaveRRR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytintersection_updates((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  csd}||S(NcSst||ptS|i|t|}}||||}}x|D]}|i|qMWx|D]}|i|qkW|S(N(RRRvRRR(RIRRRRRR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__iand__s((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs csd}||S(NcSsq|i|t|}}||||}}x|D]}|i|q8Wx|D]}|i|qVWdS(N(tsymmetric_differenceRRR(RIRRRRRR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytsymmetric_difference_updates((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs  csd}||S(NcSst||ptS|i|t|}}||||}}x|D]}|i|qMWx|D]}|i|qkW|S(N(RRRRRR(RIRRRRRR`((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt__ixor__s((R#R(R(s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs R(ii(RRRRRRR(RRRRRRRRRRRRRRR((Rs>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt_set_decorators{s*           tInstrumentedListcBs)eZdZhdd6dd6dd6ZRS(s-An instrumented version of the built-in list.RR!RR$R=R%(R5R6R7R(((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs tInstrumentedSetcBs)eZdZhdd6dd6dd6ZRS(s,An instrumented version of the built-in set.RR!RR$R=R%(R5R6R7R(((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRs tInstrumentedDictcBseZdZhdd6ZRS(s-An instrumented version of the built-in dict.RRR%(R5R6R7R(((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR'sRR!RR$R=R%RRRRRcBseZdZdZddZeieZeieZddZ eie Z ei e Z dZ ei e Z RS(s)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. cCs ||_dS(suCreate a new collection with keying provided by keyfunc. keyfunc may be any callable 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. N(R(RIR((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRKMscCs&|i|}|i|||dS(s9Add an item by value, consulting the keyfunc for the key.N(RR(RIR R_Rn((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyR]scCsX|i|}|||jo$tid||||fn|i||dS(s<Remove an item by value, consulting the keyfunc for the key.sCan not remove '%s': collection holds '%s' for key '%s'. Possible cause: is the MappedCollection key function based on mutable properties or properties that only obtain values after flush?N(RRRR(RIR R_Rn((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRes ccsbx[ti|D]J\}}|i|}||jotd|||fn|VqWdS(sValidate and convert a dict-like object into values for set()ing. This is called behind the scenes when a MappedCollection is replaced entirely by another collection, as in:: myobj.mappedcollection = {'a':obj1, 'b': obj2} # ... Raises a TypeError if the key in any (key, value) pair in the dictlike object does not match the key that this collection's keyfunc would have assigned for that value. snFound incompatible key %r for value %r; this collection's keying function requires a key of %r for this value.N(Rtdictlike_iteritemsRR?(RItdictliket incoming_keyR tnew_key((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyt_convertvs   N( R5R6R7RKR;RRR(R!RR$RR*(((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pyRCs    (6R7RRRRRDtsqlalchemy.exceptionst exceptionsRtsqlalchemy.sqlRt sqlalchemyRRt__all__t threadingtLockRRRRtobjectRRRARBRRRRRR;RRRRRtpy3kRt frozensetRtsetstBaseSetRRRRhRRRVRRRR(((s>/usr/lib/python2.6/site-packages/sqlalchemy/orm/collections.pytasr            % "  l 8   `