B 4]q@s*dZddlmZddlZddlZddlZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z e ZGd d d eZGd ddeZGdddeZGdddeZGdddeeZGdddeZGdddeZGdddeeZGdddeZGdddeZGdd d eZGd!d"d"eZGd#d$d$eZGd%d&d&eZ eZ!eZ"eZ#e Z$e ej%Z&e d'd(Z'dHd)d*Z(Gd+d,d,eZ)d-d.Z*dId/d0Z+d1d2Z,d3d4Z-d5d6Z.dJd7d8Z/d9d:Z0Gd;d<dd?Z3Gd@dAdAeZ4GdBdCdCe4Z5dDdEZ6dFdGZ7dS)KzCollection classes and helpers.)absolute_importN) binary_types)collections_abc)itertools_filterfalse)py2k) string_types) threadingc@seZdZdZddZdS)AbstractKeyedTuplecCs t|jS)zReturn a list of string key names for this :class:`.KeyedTuple`. .. seealso:: :attr:`.KeyedTuple._fields` )list_fields)selfr r O/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/util/_collections.pykeyss zAbstractKeyedTuple.keysN)__name__ __module__ __qualname__ __slots__rr r r rr sr c@s6eZdZdZd ddZeddZddZd d ZdS) KeyedTuplea``tuple`` subclass that adds labeled names. E.g.:: >>> k = KeyedTuple([1, 2, 3], labels=["one", "two", "three"]) >>> k.one 1 >>> k.two 2 Result rows returned by :class:`.Query` that contain multiple ORM entities and/or column expressions make use of this class to return rows. The :class:`.KeyedTuple` exhibits similar behavior to the ``collections.namedtuple()`` construct provided in the Python standard library, however is architected very differently. Unlike ``collections.namedtuple()``, :class:`.KeyedTuple` is does not rely on creation of custom subtypes in order to represent a new series of keys, instead each :class:`.KeyedTuple` instance receives its list of keys in place. The subtype approach of ``collections.namedtuple()`` introduces significant complexity and performance overhead, which is not necessary for the :class:`.Query` object's use case. .. seealso:: :ref:`ormtutorial_querying` NcCs6t||}|r$|jt||ng}||jd<|S)N_labels)tuple__new____dict__updatezip)clsvalslabelstr r rrJs   zKeyedTuple.__new__cCstdd|jDS)zReturn a tuple of string key names for this :class:`.KeyedTuple`. This method provides compatibility with ``collections.namedtuple()``. .. seealso:: :meth:`.KeyedTuple.keys` cSsg|]}|dk r|qS)Nr ).0lr r r ^sz&KeyedTuple._fields..)rr)rr r rr Ss zKeyedTuple._fieldscCstd|dS)NzCan't set attribute: %s)AttributeError)rkeyvaluer r r __setattr__`szKeyedTuple.__setattr__csfddDS)zReturn the contents of this :class:`.KeyedTuple` as a dictionary. This method provides compatibility with ``collections.namedtuple()``, with the exception that the dictionary returned is **not** ordered. csi|]}j||qSr )r)r r$)rr r jsz&KeyedTuple._asdict..)r)rr )rr_asdictcszKeyedTuple._asdict)N) rrr__doc__rpropertyr r&r(r r r rr*s  rc@s(eZdZdZddZddZddZdS) _LWr cCs t||S)N)rr)rrr r rrpsz _LW.__new__cCstt||jffS)N)rr _real_fields)rr r r __reduce__ssz_LW.__reduce__cCs tt|j|}|dd|S)zAReturn the contents of this :class:`.KeyedTuple` as a dictionary.N)dictrr,pop)rdr r rr(ys z _LW._asdictN)rrrrrr-r(r r r rr+msr+c@s eZdZddZeZZZdS)ImmutableContainercOstd|jjdS)Nz%s object is immutable) TypeError __class__r)rargkwr r r _immutableszImmutableContainer._immutableN)rrrr6 __delitem__ __setitem__r&r r r rr1sr1c@sJeZdZejZZZZZ ddZ ddZ ddZ ddZ d d Zd S) immutabledictcGst|}tj|f||S)N)r.r__init__)rargsnewr r rrs zimmutabledict.__new__cGsdS)Nr )rr;r r rr:szimmutabledict.__init__cCstt|ffS)N)r9r.)rr r rr-szimmutabledict.__reduce__cCs@|s|S|s$t|tr|St|Snt|}t|||SdS)N) isinstancer9r.r)rr0Zd2r r runions   zimmutabledict.unioncCsdt|S)Nzimmutabledict(%s))r.__repr__)rr r rr?szimmutabledict.__repr__N)rrrr1r6clearr/popitem setdefaultrrr:r-r>r?r r r rr9s  r9cseZdZdZdZddZddZddZfd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdd Zd.d"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZZS)/ Propertiesz8Provide a __getattr__/__setattr__ interface over a dict.)_datacCst|d|dS)NrD)objectr&)rdatar r rr:szProperties.__init__cCs t|jS)N)lenrD)rr r r__len__szProperties.__len__cCstt|jS)N)iterr rDvalues)rr r r__iter__szProperties.__iter__cs"ttt|dd|jDS)NcSsg|] }t|qSr )str)r kr r rr"sz&Properties.__dir__..)dirsuperrCrDr)r)r3r r__dir__s zProperties.__dir__cCst|t|S)N)r )rotherr r r__add__szProperties.__add__cCs||j|<dS)N)rD)rr$objr r rr8szProperties.__setitem__cCs |j|S)N)rD)rr$r r r __getitem__szProperties.__getitem__cCs |j|=dS)N)rD)rr$r r rr7szProperties.__delitem__cCs||j|<dS)N)rD)rr$rSr r rr&szProperties.__setattr__cCs d|jiS)NrD)rD)rr r r __getstate__szProperties.__getstate__cCst|d|ddS)NrD)rEr&)rstater r r __setstate__szProperties.__setstate__cCs,y |j|Stk r&t|YnXdS)N)rDKeyErrorr#)rr$r r r __getattr__s zProperties.__getattr__cCs ||jkS)N)rD)rr$r r r __contains__szProperties.__contains__cCs t|jS)z8Return an immutable proxy for this :class:`.Properties`.)ImmutablePropertiesrD)rr r r as_immutableszProperties.as_immutablecCs|j|dS)N)rDr)rr%r r rrszProperties.updateNcCs||kr||S|SdS)Nr )rr$defaultr r rgetszProperties.getcCs t|jS)N)r rD)rr r rrszProperties.keyscCst|jS)N)r rDrJ)rr r rrJszProperties.valuescCst|jS)N)r rDitems)rr r rr_szProperties.itemscCs ||jkS)N)rD)rr$r r rhas_keyszProperties.has_keycCs|jdS)N)rDr@)rr r rr@szProperties.clear)N)rrrr)rr:rHrKrPrRr8rTr7r&rUrWrYrZr\rr^rrJr_r`r@ __classcell__r r )r3rrCs.  rCc@seZdZdZdZddZdS)OrderedPropertieszUProvide a __getattr__/__setattr__ interface with an OrderedDict as backing store.r cCst|tdS)N)rCr: OrderedDict)rr r rr:szOrderedProperties.__init__N)rrrr)rr:r r r rrbsrbc@seZdZdZdZdS)r[zDProvide immutable dict/object attribute to an underlying dictionary.r N)rrrr)rr r r rr[sr[c@seZdZdZdZddZd*ddZdd Zd d Zd d Z ddZ d+ddZ ddZ ddZ ddZddZddZerddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)ZdS),rczCA dict that returns keys/values/items in the order they were added.)_listcCst|ffS)N)rcr_)rr r rr- szOrderedDict.__reduce__NcKs2g|_|dkr |r.|jf|n|j|f|dS)N)rdr)r_OrderedDict____sequencekwargsr r rr:s zOrderedDict.__init__cCsg|_t|dS)N)rdr.r@)rr r rr@szOrderedDict.clearcCs|S)N)__copy__)rr r rcopyszOrderedDict.copycCst|S)N)rc)rr r rrgszOrderedDict.__copy__cOs|jj||dS)N)rdsort)rr4r5r r rri!szOrderedDict.sortcKsb|dk rPt|dr6x<|D]}||||qWnx|D]\}}|||<q.)rd)rr )rrrJ<szOrderedDict.valuescsfddjDS)Ncsg|]}||fqSr r )r r$)rr rr"@sz%OrderedDict.items..)rd)rr )rrr_?szOrderedDict.itemscCs t|S)N)rIrJ)rr r r itervaluesDszOrderedDict.itervaluescCst|S)N)rI)rr r riterkeysGszOrderedDict.iterkeyscCs t|S)N)rIr_)rr r r iteritemsJszOrderedDict.iteritemscCsH||kr6y|j|Wntk r4|g|_YnXt|||dS)N)rdappendr#r.r8)rr$rSr r rr8Ms zOrderedDict.__setitem__cCst|||j|dS)N)r.r7rdremove)rr$r r rr7Ws zOrderedDict.__delitem__cGs.||k}tj||f|}|r*|j||S)N)r.r/rdro)rr$r]Zpresentr%r r rr/[s  zOrderedDict.popcCst|}|j|d|S)Nr)r.rArdro)ritemr r rrAbs zOrderedDict.popitem)N)N)rrrr)rr-r:r@rhrgrirrBrKrrJr_rrkrlrmr8r7r/rAr r r rrcs,   rcc@seZdZd&ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ e Z ddZeZddZeZddZeZddZeZddZeZd d!ZeZd"d#ZeZd$d%ZeZdS)' OrderedSetNcCs<t|g|_|dk r2t||_t||jng|_dS)N)setr:rd unique_listr)rr0r r rr:is   zOrderedSet.__init__cCs$||kr|j|t||dS)N)rdrnrradd)relementr r rrtrs zOrderedSet.addcCst|||j|dS)N)rrrord)rrur r rrows zOrderedSet.removecCs&||kr|j||t||dS)N)rdinsertrrrt)rposrur r rrv{szOrderedSet.insertcCs$||kr |j|t||dS)N)rdrorr)rrur r rdiscards zOrderedSet.discardcCst|g|_dS)N)rrr@rd)rr r rr@s zOrderedSet.clearcCs |j|S)N)rd)rr$r r rrTszOrderedSet.__getitem__cCs t|jS)N)rIrd)rr r rrKszOrderedSet.__iter__cCs ||S)N)r>)rrQr r rrRszOrderedSet.__add__cCsd|jj|jfS)Nz%s(%r))r3rrd)rr r rr?szOrderedSet.__repr__cCs2x,|D]$}||kr|j|t||qW|S)N)rdrnrrrt)riterableer r rrs   zOrderedSet.updatecCs||}|||S)N)r3r)rrQresultr r rr>s  zOrderedSet.unioncs t|fdd|DS)Nc3s|]}|kr|VqdS)Nr )r a)rQr r sz*OrderedSet.intersection..)rrr3)rrQr )rQr intersectionszOrderedSet.intersectioncs<tfddD}|fddD|S)Nc3s|]}|kr|VqdS)Nr )r r|)rQr rr}sz2OrderedSet.symmetric_difference..c3s|]}|kr|VqdS)Nr )r r|)rr rr}s)rrr3r)rrQr{r )rQrrsymmetric_differenceszOrderedSet.symmetric_differencecs t|fdd|DS)Nc3s|]}|kr|VqdS)Nr )r r|)rQr rr}sz(OrderedSet.difference..)rrr3)rrQr )rQr differenceszOrderedSet.differencecs.tt|fdd|jD|_|S)Ncsg|]}|kr|qSr r )r r|)rQr rr"sz2OrderedSet.intersection_update..)rrintersection_updaterd)rrQr )rQrrs zOrderedSet.intersection_updatecsDt|fddjD_jfdd|jD7_S)Ncsg|]}|kr|qSr r )r r|)rr rr"sz:OrderedSet.symmetric_difference_update..csg|]}|kr|qSr r )r r|)rr rr"s)rrsymmetric_difference_updaterd)rrQr )rrrs z&OrderedSet.symmetric_difference_updatecs&t|fddjD_S)Ncsg|]}|kr|qSr r )r r|)rr rr"sz0OrderedSet.difference_update..)rrdifference_updaterd)rrQr )rrrs zOrderedSet.difference_update)N)rrrr:rtrorvrxr@rTrKrRr?__str__r__ior__r>__or__r~__and__r__xor__r__sub__r__iand__r__ixor__r__isub__r r r rrqhs6 rqc@sJeZdZdZeZdOddZddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Z d9d:Z!d;d<Z"d=d>Z#d?d@Z$dAdBZ%dCdDZ&dEdFZ'e'Z(dGdHZ)dIdJZ*dKdLZ+dMdNZ,dS)P IdentitySetzA set that considers only object id() for uniqueness. This strategy has edge cases for builtin types- it's possible to have two 'foo' strings in one of these sets, for example. Use sparingly. NcCs(t|_|r$x|D]}||qWdS)N)r._membersrt)rryor r rr:s zIdentitySet.__init__cCs||jt|<dS)N)rid)rr%r r rrtszIdentitySet.addcCst||jkS)N)rr)rr%r r rrZszIdentitySet.__contains__cCs|jt|=dS)N)rr)rr%r r rroszIdentitySet.removecCs(y||Wntk r"YnXdS)N)rorX)rr%r r rrxszIdentitySet.discardcCs4y|j}|dStk r.tdYnXdS)Nrzpop from an empty set)rrArX)rZpairr r rr/s  zIdentitySet.popcCs|jdS)N)rr@)rr r rr@szIdentitySet.clearcCs tddS)Nzcannot compare sets using cmp())r2)rrQr r r__cmp__szIdentitySet.__cmp__cCst|tr|j|jkSdSdS)NF)r=rr)rrQr r r__eq__s  zIdentitySet.__eq__cCst|tr|j|jkSdSdS)NT)r=rr)rrQr r r__ne__s  zIdentitySet.__ne__cCsHt||}t|t|kr dSx"t|jjt|jD]}dSWdS)NFT)typerGrrrZrIr)rryrQmr r rissubset s zIdentitySet.issubsetcCst|tstS||S)N)r=rNotImplementedr)rrQr r r__le__s zIdentitySet.__le__cCs(t|tstSt|t|ko&||S)N)r=rrrGr)rrQr r r__lt__s zIdentitySet.__lt__cCsHt||}t|t|kr dSx"t|jjt|jD]}dSWdS)NFT)rrGrrrZrIr)rryrQrr r r issuperset s zIdentitySet.issupersetcCst|tstS||S)N)r=rrr)rrQr r r__ge__,s zIdentitySet.__ge__cCs(t|tstSt|t|ko&||S)N)r=rrrGr)rrQr r r__gt__1s zIdentitySet.__gt__cCs6t|}|}t|}|j||||S)N)r_member_id_tuples_iter_idrr _working_setr>)rryr{membersrQr r rr>6s  zIdentitySet.unioncCst|tstS||S)N)r=rrr>)rrQr r rr>s zIdentitySet.__or__cCs||j|_dS)N)r>r)rryr r rrCszIdentitySet.updatecCst|tstS|||S)N)r=rrr)rrQr r rrFs  zIdentitySet.__ior__cCs6t|}|}t|}|j||||S)N)rrrrrrr)rryr{rrQr r rrLs  zIdentitySet.differencecCst|tstS||S)N)r=rrr)rrQr r rrTs zIdentitySet.__sub__cCs||j|_dS)N)rr)rryr r rrYszIdentitySet.difference_updatecCst|tstS|||S)N)r=rrr)rrQr r rr\s  zIdentitySet.__isub__cCs6t|}|}t|}|j||||S)N)rrrrrrr~)rryr{rrQr r rr~bs  zIdentitySet.intersectioncCst|tstS||S)N)r=rrr~)rrQr r rrjs zIdentitySet.__and__cCs||j|_dS)N)r~r)rryr r rroszIdentitySet.intersection_updatecCst|tstS|||S)N)r=rrr)rrQr r rrrs  zIdentitySet.__iand__cCs6t|}|}t|}|j||||S)N)rrrrrrr)rryr{rrQr r rrxs  z IdentitySet.symmetric_differencecCsdd|jDS)Ncss|]}t||fVqdS)N)r)r vr r rr}sz0IdentitySet._member_id_tuples..)rrJ)rr r rrszIdentitySet._member_id_tuplescCst|tstS||S)N)r=rrr)rrQr r rrs zIdentitySet.__xor__cCs||j|_dS)N)rr)rryr r rrsz'IdentitySet.symmetric_difference_updatecCst|tstS|||S)N)r=rrr)rrQr r rrs  zIdentitySet.__ixor__cCst|t|jS)N)rrIrrJ)rr r rrhszIdentitySet.copycCs t|jS)N)rGr)rr r rrHszIdentitySet.__len__cCst|jS)N)rIrrJ)rr r rrKszIdentitySet.__iter__cCs tddS)Nzset objects are unhashable)r2)rr r r__hash__szIdentitySet.__hash__cCsdt|jt|jfS)Nz%s(%r))rrr rrJ)rr r rr?szIdentitySet.__repr__)N)-rrrr)rrrr:rtrZrorxr/r@rrrrrrrrrr>rrrrrrrr~rrrrrrrrrhrgrHrKrr?r r r rrsR    rc@s>eZdZdddZddZddZdd Zd d Zd d ZdS) WeakSequencer csfdd|D_dS)Ncsg|]}t|jqSr )weakrefref_remove)r ru)rr rr"sz)WeakSequence.__init__..)_storage)rZ_WeakSequence__elementsr )rrr:szWeakSequence.__init__cCs|jt||jdS)N)rrnrrr)rrpr r rrnszWeakSequence.appendcCs|j|dS)N)rro)rrr r rrszWeakSequence._removecCs t|jS)N)rGr)rr r rrHszWeakSequence.__len__cCsdddd|jDDS)Ncss|]}|dk r|VqdS)Nr )r rSr r rr}sz(WeakSequence.__iter__..css|] }|VqdS)Nr )r rr r rr}s)r)rr r rrKszWeakSequence.__iter__cCs:y|j|}Wn tk r.td|YnX|SdS)NzIndex %s out of range)rrX IndexError)rindexrSr r rrTs zWeakSequence.__getitem__N)r ) rrrr:rnrrHrKrTr r r rrs  rc@s&eZdZGdddeZdddZdS)OrderedIdentitySetc@seZdZdZdS)zOrderedIdentitySet._working_setTN)rrrZ__sa_hash_exempt__r r r rrsrNcCs2t|t|_|r.x|D]}||qWdS)N)rr:rcrrt)rryrr r rr:s   zOrderedIdentitySet.__init__)N)rrrrqrr:r r r rrsrc@s eZdZdZddZddZdS) PopulateDictzA dict which populates missing values via a creation function. Note the creation function takes a key, unlike collections.defaultdict. cCs ||_dS)N)creator)rrr r rr:szPopulateDict.__init__cCs||||<}|S)N)r)rr$valr r r __missing__szPopulateDict.__missing__N)rrrr)r:rr r r rrsrcCstt|S)N)r*operator itemgetter)idxr r rrcs>tjs$fdd|DSfdd|DSdS)Ncs g|]}|kr|s|qSr r )r x)seenseen_addr rr"szunique_list..cs(g|] }|kr|s|qSr r )r r)hashfuncrrr rr"s)rrrt)seqrr )rrrrrss rsc@s*eZdZdZd ddZddZddZdS) UniqueAppenderzAppends items to a collection ensuring uniqueness. Additional appends() of the same object are ignored. Membership is determined by identity (``is a``) not equality (``==``). NcCsH||_i|_|rt|||_n&t|dr2|j|_nt|drD|j|_dS)Nrnrt)rF_uniquegetattr_data_appenderrjrnrt)rrFZviar r rr:s   zUniqueAppender.__init__cCs*t|}||jkr&||d|j|<dS)NT)rrr)rrpZid_r r rrns  zUniqueAppender.appendcCs t|jS)N)rIrF)rr r rrKszUniqueAppender.__iter__)N)rrrr)r:rnrKr r r rrs rcCs0t|dkr(t|dtjr(t|dS|SdS)Nrr)rGr=types GeneratorTyper )r4r r rcoerce_generator_args rcCsF|dkr |St|tjr&t|ttr,|gSt|tr:|St|SdS)N)r=rIterablerrr )rr]r r rto_list"s  rcCst|dd|DS)zreturn True if any items of set\_ are present in iterable. Goes through special effort to ensure __hash__ is not called on items in iterable that don't support it. cSsg|]}|jr|qSr )r)r ir r rr"7sz$has_intersection..)boolr~)Zset_ryr r rhas_intersection/srcCs,|dkrtSt|ts$tt|S|SdS)N)rrr=r)rr r rto_set:s   rcCs,|dkrtSt|ts$tt|S|SdS)N) column_setr=r)rr r r to_column_setCs   rcKs&|}|r|||jf||S)z5Copy the given dict and update with the given values.)rhr)r0Z_newr5r r r update_copyLs   rccsFx@|D]8}t|ts8t|dr8xt|D] }|Vq(Wq|VqWdS)zGiven an iterator of which further sub-elements may also be iterators, flatten the sub-elements into a single iterator. rKN)r=rLrjflatten_iterator)relemyr r rrVs   rc@sdeZdZdZdZdddZdd Zdd d Zd d ZddZ ddZ ddZ e ddZ ddZdS)LRUCachezDictionary with 'squishy' removal of least recently used items. Note that either get() or [] should be used here, but generally its not safe to do an "in" check first as the dictionary can change subsequent to that call. )capacity threshold size_alert_counter_mutexd?NcCs&||_||_||_d|_t|_dS)Nr)rrrrr ZLockr)rrrrr r rr:os zLRUCache.__init__cCs|jd7_|jS)Nr)r)rr r r _inc_countervszLRUCache._inc_countercCs2t|||}||k r*||d<|dS|SdS)Nr)r.r^r)rr$r]rpr r rr^zs  z LRUCache.getcCs t||}||d<|dS)Nrr)r.rTr)rr$rpr r rrTs  zLRUCache.__getitem__cCsddt|DS)NcSsg|] }|dqS)rr )r rr r rr"sz#LRUCache.values..)r.rJ)rr r rrJszLRUCache.valuescCs ||kr||S|||<|SdS)Nr )rr$r%r r rrBszLRUCache.setdefaultcCsFt||}|dkr2|||g}t|||n||d<|dS)Nr)r.r^rr8 _manage_size)rr$r%rpr r rr8s  zLRUCache.__setitem__cCs|j|j|jS)N)rr)rr r rsize_thresholdszLRUCache.size_thresholdc Cs|jdsdSzt|j}xt||j|j|jkr|rJd}||tt |t ddd}x<||jdD]*}y||d=Wqtt k rwtYqtXqtWqWWd|j XdS)NFrT)r$reverser)racquirerrrGrrsortedr.rJrrrXrelease)rrZ by_counterrpr r rrs    zLRUCache._manage_size)rrN)N)rrrr)rr:rr^rTrJrBr8r*rrr r r rrcs   rrcCsl|ft|}t|}|r |St|tftddt|Ddg}||_tdd|D|_|t|<|S)NcSs$g|]\}}|dk r|t|fqS)N)_property_getters)r rZfieldr r rr"sz+lightweight_named_tuple..)rr cSsg|]}|dk r|qS)Nr )r fr r rr"s) r _lw_tuplesr^rr+r. enumerater,r )nameZfieldsZhash_Ztp_clsr r rlightweight_named_tuples   rc@s8eZdZdZddZddZddZdd Zd d Zd S) ScopedRegistryaA Registry that can store one or multiple instances of a single class on the basis of a "scope" function. The object implements ``__call__`` as the "getter", so by calling ``myregistry()`` the contained object is returned for the current scope. :param createfunc: a callable that returns a new object to be placed in the registry :param scopefunc: a callable that will return a key to store/retrieve an object. cCs||_||_i|_dS)aVConstruct a new :class:`.ScopedRegistry`. :param createfunc: A creation function that will generate a new value for the current scope, if none is present. :param scopefunc: A function that returns a hashable token representing the current scope (such as, current thread identifier). N) createfunc scopefuncregistry)rrrr r rr:s zScopedRegistry.__init__cCs:|}y |j|Stk r4|j||SXdS)N)rrrXrBr)rr$r r r__call__s  zScopedRegistry.__call__cCs||jkS)z9Return True if an object is present in the current scope.)rr)rr r rhasszScopedRegistry.hascCs||j|<dS)z$Set the value for the current scope.N)rr)rrSr r rrrszScopedRegistry.setcCs*y|j|=Wntk r$YnXdS)z Clear the current scope, if any.N)rrrX)rr r rr@szScopedRegistry.clearN) rrrr)r:rrrrr@r r r rrs  rc@s8eZdZdZddZddZddZdd Zd d Zd S) ThreadLocalRegistryz\A :class:`.ScopedRegistry` that uses a ``threading.local()`` variable for storage. cCs||_t|_dS)N)rr Zlocalr)rrr r rr:szThreadLocalRegistry.__init__cCs2y|jjStk r,|}|j_|SXdS)N)rr%r#r)rrr r rrs zThreadLocalRegistry.__call__cCs t|jdS)Nr%)rjr)rr r rrszThreadLocalRegistry.hascCs ||j_dS)N)rr%)rrSr r rrrszThreadLocalRegistry.setcCs$y |j`Wntk rYnXdS)N)rr%r#)rr r rr@ s zThreadLocalRegistry.clearN) rrrr)r:rrrrr@r r r rr s rccs x|D]}t||fVqWdS)z*Generator: ((id(o), o) for o in iterable).N)r)ryrpr r rr's rcCs2d}x(|D] }||kr |d7}|dkr dSq WdS)zrGiven a sequence and search object, return True if there's more than one, False if zero or one of them. rrTFr )Zsequencetargetcrpr r r has_dupes.s  r)N)N)N)8r)Z __future__rrrrcompatrrrrrr frozensetZ EMPTY_SETrr rr+rEr1r.r9rCrbr[rcrrrqrrrrrZ column_dictZordered_column_setZpopulate_column_dictrZ_gettersrrsrrrrrrrrrrrrrrrr r r rsb       C O akS        Q8