id#r>dZddlmZddlZddlZddlZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z e ZGd d eZGd deZGddeZGddeZGddeeZGddeZGddeZGddeeZGddeZGddeZGdd eZGd!d"eZGd#d$eZGd%d&eZ Gd'd(eZ!eZ"eZ#eZ$e ej%Z&e d)Z'd=d*Z(Gd+d,eZ)d-Z*d=d.Z+d/Z,d0Z-d1Z.d=d2Z/d3Z0Gd4d5eZ1e1d6Z2d7Z3Gd8d9eZ4Gd:d;e4Z5d<Z6dS)>zCollection classes and helpers.)absolute_importN) binary_types)collections_abc)itertools_filterfalse)py2k) string_types) threadingceZdZdZdZdS)AbstractKeyedTuplec*t|jS)zReturn a list of string key names for this :class:`.KeyedTuple`. .. seealso:: :attr:`.KeyedTuple._fields` )list_fieldsselfs Q/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/util/_collections.pykeyszAbstractKeyedTuple.keyssDL!!!N)__name__ __module__ __qualname__ __slots__rr rrr r s(I " " " " "rr c<eZdZdZddZedZdZdZdS) 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.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.Query` object's use case. .. seealso:: :ref:`ormtutorial_querying` Nct||}|r)|jt ||ng}||jd<|S)N_labels)tuple__new____dict__updatezip)clsvalslabelsts rrzKeyedTuple.__new__JsV MM#t $ $   J  c&$// 0 0 0 0F & 9rc>td|jDS)zReturn a tuple of string key names for this :class:`.KeyedTuple`. This method provides compatibility with ``collections.namedtuple()``. .. seealso:: :meth:`.KeyedTuple.keys` cg|]}||SNr ).0ls r z&KeyedTuple._fields..^s???Aar)rrrs rrzKeyedTuple._fieldsSs#?????@@@rc&td|z)NzCan't set attribute: %s)AttributeErrorrkeyvalues r __setattr__zKeyedTuple.__setattr__`s6<===rcDfdDS)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. c,i|]}|j|Sr )r r*r0rs r z&KeyedTuple._asdict..js"???CT]3'???r)rrs`r_asdictzKeyedTuple._asdictcs(@???499;;????rr)) rrr__doc__rpropertyrr2r7r rrrr*ss> A AX A>>>@@@@@rrc$eZdZdZdZdZdZdS)_LWr c8t||Sr))rr)r#r$s rrz _LW.__new__ps}}S$'''rc<tt||jffSr))rr _real_fieldsrs r __reduce__z_LW.__reduce__ssDJJ(9:::rcvtt|j|}|dd|S)zAReturn the contents of this :class:`.KeyedTuple` as a dictionary.N)dictr"r>poprds rr7z _LW._asdictys7 T&-- . . dDrN)rrrrrr?r7r rrr;r;msFI(((;;; rr;c eZdZdZexZxZZdS)ImmutableContainerc:td|jjz)Nz%s object is immutable) TypeError __class__rrargkws r _immutablezImmutableContainer._immutables04>3JJKKKrN)rrrrM __delitem__ __setitem__r2r rrrFrFs1LLL/98K8+ rrFcJeZdZejxZxZxZxZZ dZ dZ dZ dZ dZdS) immutabledictc^t|}tj|g|R|Sr))rAr__init__)r#argsnews rrzimmutabledict.__new__s0ll3 c!D!!!! rcdSr)r )rrTs rrSzimmutabledict.__init__s rc0tt|ffSr))rQrArs rr?zimmutabledict.__reduce__stDzzm++rc|s|S|s&t|tr|St|St|}t|||Sr)) isinstancerQrAr!)rrDd2s runionzimmutabledict.unionsb K !]++ ($Q'''t$$B KKA   Irc<dt|zS)Nzimmutabledict(%s))rA__repr__rs rr]zimmutabledict.__repr__s"T]]4%8%888rN)rrrrFrMclearrBpopitem setdefaultr!rrSr?r[r]r rrrQrQs{2D2OOEOCO'OJ    ,,,   99999rrQceZdZdZdZdZdZdZfdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZddZdZdZdZdZdZxZS) Propertiesz8Provide a __getattr__/__setattr__ interface over a dict._datac>t|d|dSNrdobjectr2)rdatas rrSzProperties.__init__s 4$/////rc*t|jSr))lenrdrs r__len__zProperties.__len__s4:rchtt|jSr))iterrrdvaluesrs r__iter__zProperties.__iter__s&D**,,--...rcttt|d|jDzS)Nc,g|]}t|Sr )str)r*ks rr,z&Properties.__dir__..s+/ / / CFF/ / / r)dirsuperrbrdr)rrIs r__dir__zProperties.__dir__sJ5T**++/ /  JOO--/ / /   rc@t|t|zSr)rrothers r__add__zProperties.__add__sDzzDKK''rc||j|<dSr)rcrr0objs rrOzProperties.__setitem__ 3rc|j|Sr)rcrr0s r __getitem__zProperties.__getitem__z#rc|j|=dSr)rcrs rrNzProperties.__delitem__s JsOOOrc||j|<dSr)rcr~s rr2zProperties.__setattr__rrcd|jiSrfrcrs r __getstate__zProperties.__getstate__s$$rcJt|d|ddSrfrg)rstates r __setstate__zProperties.__setstate__s$4%.99999rcX |j|S#t$rt|wxYwr))rdKeyErrorr.rs r __getattr__zProperties.__getattr__s< &:c? " & & & %% % &s )c||jvSr)rcrs r __contains__zProperties.__contains__dj  rc*t|jS)z8Return an immutable proxy for this :class:`.Properties`.)ImmutablePropertiesrdrs r as_immutablezProperties.as_immutables#4:...rc:|j|dSr))rdr!rr1s rr!zProperties.updates %     rNc||vr||S|Sr)r )rr0defaults rgetzProperties.gets $;;9 Nrc*t|jSr))rrdrs rrzProperties.keysDJrcNt|jSr))rrdrors rrozProperties.valuessDJ%%''(((rcNt|jSr))rrditemsrs rrzProperties.itemssDJ$$&&'''rc||jvSr)rcrs rhas_keyzProperties.has_keyrrc8|jdSr))rdr^rs rr^zProperties.clears rr))rrrr8rrSrlrprwr|rOrrNr2rrrrrr!rrrorrr^ __classcell__)rIs@rrbrbstBBI000///     (((%%%:::&&& !!!/// !!!    )))(((!!!rrbceZdZdZdZdZdS)OrderedPropertieszUProvide a __getattr__/__setattr__ interface with an OrderedDict as backing store.r cTt|tdSr))rbrS OrderedDictrs rrSzOrderedProperties.__init__s"D+--00000rN)rrrr8rrSr rrrrs4I11111rrceZdZdZdZdS)rzDProvide immutable dict/object attribute to an underlying dictionary.r N)rrrr8rr rrrrsNNIIIrrceZdZdZdZdZddZdZdZdZ d Z dd Z d Z d Z d ZdZdZer dZdZdZdZdZdZdZdS)rzCA dict that returns keys/values/items in the order they were added._listc:t|ffSr))rrrs rr?zOrderedDict.__reduce__ sTZZ\\O++rNc Zg|_||r|jdi|dSdS|j|fi|dS)Nr )rr!)r_OrderedDict____sequencekwargss rrSzOrderedDict.__init__sa   & %%f%%%%% & & DK / / / / / / /rcHg|_t|dSr))rrAr^rs rr^zOrderedDict.clears!  4rc*|Sr))__copy__rs rcopyzOrderedDict.copys}}rc t|Sr))rrs rrzOrderedDict.__copy__s4   rc*|jj|i|dSr))rsortrJs rrzOrderedDict.sort!s! ######rc |Qt|dr4|D]}||||n |D] \}}|||< |r||dSdS)Nr)hasattrrrOr!)rrrr0r1s rr!zOrderedDict.update$s  #|V,, &',,..==C$$S,s*;<<<<=#/&&JC %DII  KK       rcd||vr||||S||Sr))rOrr/s rr`zOrderedDict.setdefault/s: d??   S% ( ( (L##C(( (rc*t|jSr)rnrrs rrpzOrderedDict.__iter__6rrc t|Sr)ryrs rrzOrderedDict.keys9sDzzrc*fdjDS)Nc g|] }| Sr r r5s rr,z&OrderedDict.values..=s000cS 000rrrs`rrozOrderedDict.values<s0000TZ0000rc*fdjDS)Nc$g|] }||f Sr r r5s rr,z%OrderedDict.items..@s"777Sd3i 777rrrs`rrzOrderedDict.items?s7777DJ7777rcDt|Sr))rnrors r itervalueszOrderedDict.itervaluesDs && &rc t|Sr))rnrs riterkeyszOrderedDict.iterkeysGs:: rcDt|Sr))rnrrs r iteritemszOrderedDict.iteritemsJs %% %rc||vr4 |j|n#t$r |g|_YnwxYwt|||dSr))rappendr.rArOr~s rrOzOrderedDict.__setitem__Mss d?? # !!#&&&&! # # #"U  # sC(((((s !66cpt|||j|dSr))rArNrremovers rrNzOrderedDict.__delitem__Ws4 s### #rcl||v}tj||g|R}|r|j||Sr))rArBrr)rr0rpresentr1s rrBzOrderedDict.pop[sG+s-W---  # J  c " " " rczt|}|j|d|SNr)rAr_rrritems rr_zOrderedDict.popitembs2||D!! $q'""" rr))rrrr8rr?rSr^rrrr!r`rprrorrrrrrOrNrBr_r rrrrsPMMI,,,0000!!!$$$     )))   111888 & ' ' '    & & &)))rrceZdZddZdZdZdZdZdZdZ d Z d Z d Z e Z d ZeZd ZeZdZeZdZeZdZeZdZeZdZeZdZeZdS) OrderedSetNct|g|_|6t||_t||jdSg|_dSr))setrSr unique_listr!rCs rrSzOrderedSet.__init__isT T =$QDJ JJtTZ ( ( ( ( (DJJJrcx||vr|j|t||dSr)rrraddrelements rrzOrderedSet.addrs= $   J  g & & & grcpt|||j|dSr))rrrrs rrzOrderedSet.removews2 4!!! '"""""rcz||vr|j||t||dSr))rinsertrr)rposrs rrzOrderedSet.insert{s? $   J  c7 + + + grc|||vr7|j|t||dSdSr))rrrrs rdiscardzOrderedSet.discardsB d?? J  g & & & JJtW % % % % % ?rcHt|g|_dSr))rr^rrs rr^zOrderedSet.clears $ rc|j|Sr)rrs rrzOrderedSet.__getitem__rrc*t|jSr)rrs rrpzOrderedSet.__iter__rrc,||Sr))r[rzs rr|zOrderedSet.__add__szz%   rc0|jjd|jdSN())rIrrrs rr]zOrderedSet.__repr__s>222DJJJ??rc|D];}||vr5|j|t||<|Sr)r)riterablees rr!zOrderedSet.updatesJ ! !A}} !!!$$$a    rcZ||}|||Sr))rIr!rr{results rr[zOrderedSet.unions*%% e rcdt|fd|DS)Nc3$K|] }|v|V dSr)r r*ar{s r z*OrderedSet.intersection..s'<.s'BBa1E>>>>>>BBrc3$K|] }|v|V dSr)r r*rrs rrz2OrderedSet.symmetric_difference..s'88A!4--a----88r)rrIr!rs`` rsymmetric_differencezOrderedSet.symmetric_differencesaE BBBB4BBBBB 8888888888 rcdt|fd|DS)Nc3$K|] }|v|V dSr)r rs rrz(OrderedSet.difference..s'@@A%a@@rrrzs `r differencezOrderedSet.differences5E ~~@@@@@@@@@@rctt|fd|jD|_|S)Ncg|]}|v| Sr r rs rr,z2OrderedSet.intersection_update..s:::AqEzzazzzr)rintersection_updaterrzs `rrzOrderedSet.intersection_updatesFE  e,,,:::::::  rct|fdjD_xjfd|jDz c_S)Ncg|]}|v| Sr r rs rr,z:OrderedSet.symmetric_difference_update..999AqDyyayyyrcg|]}|v| Sr r rs rr,z:OrderedSet.symmetric_difference_update..s;;;Qdqr)rsymmetric_difference_updaterrzs` rrz&OrderedSet.symmetric_difference_updatesb ''e4449999999  ;;;;%+;;;;  rcnt|fdjD_S)Ncg|]}|v| Sr r rs rr,z0OrderedSet.difference_update..rr)rdifference_updaterrzs` rrzOrderedSet.difference_updates; dE***9999999  rr))rrrrSrrrrr^rrpr|r]__str__r!__ior__r[__or__r__and__r__xor__r__sub__r__iand__r__ixor__r__isub__r rrrrhsf ### &&&    !!!@@@GG F===G #GAAAG #H +H !HHHrrceZdZdZd(dZdZdZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ d Z!d!Z"d"Z#d#Z$e$Z%d$Z&d%Z'd&Z(d'Z)dS)) 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. Nc^t|_|r||dSdSr))rA_membersr!rrs rrSzIdentitySet.__init__s7  " KK ! ! ! ! ! " "rc4||jt|<dSr)ridrs rrzIdentitySet.adds#( bii   rc.t||jvSr))rrrs rrzIdentitySet.__contains__s%yyDM))rc0|jt|=dSr)rrs rrzIdentitySet.removes M"U)) $ $ $rcT ||dS#t$rYdSwxYwr))rrrs rrzIdentitySet.discardsA  KK         DD s  ''c |j}|dS#t$rtdwxYw)Nrzpop from an empty set)rr_r)rpairs rrBzIdentitySet.popsM 4=((**D7N 4 4 4233 3 4s #=c8|jdSr))rr^rs rr^zIdentitySet.clears rc td)Nzcannot compare sets using cmp()rHrzs r__cmp__zIdentitySet.__cmp__s9:::rcPt|tr|j|jkSdS)NFrYrrrzs r__eq__zIdentitySet.__eq__s( e[ ) ) =EN2 25rcPt|tr|j|jkSdSNTr#rzs r__ne__zIdentitySet.__ne__s( e[ ) ) =EN2 24rc||}t|t|krdSt|jjt |jD]}dSdSNFTrIrkrrrrnrrrr{ms rissubsetzIdentitySet.issubsetsvx(( t99s5zz ! !5& N 'dm.@.@.B.B)C)C    A55trcdt|tstS||Sr))rYrNotImplementedr-rzs r__le__zIdentitySet.__le__s,%-- "! !}}U###rct|tstSt|t|ko||Sr))rYrr/rkr-rzs r__lt__zIdentitySet.__lt__sB%-- "! !4yy3u::%>$--*>*>>rc||}t|t|krdSt|jjt |jD]}dSdSr)r*r+s r issupersetzIdentitySet.issupersetsvx(( t99s5zz ! !5& M &U^-@-@-B-B(C(C    A55trcdt|tstS||Sr))rYrr/r4rzs r__ge__zIdentitySet.__ge__),%-- "! !u%%%rct|tstSt|t|ko||Sr))rYrr/rkr4rzs r__gt__zIdentitySet.__gt__.sB%-- "! !4yy3u::%@$//%*@*@@rc|}|j}|j||jd|D|S)Nc38K|]}t||fVdSr)rr*rs rrz$IdentitySet.union..7s,BB#3~BBBBBBr)rIrr!)rrrmemberss rr[zIdentitySet.union3sX!!-w'''BBBBBBBB rcdt|tstS||Sr))rYrr/r[rzs rr zIdentitySet.__or__:s,%-- "! !zz%   rcN|jd|DdS)Nc38K|]}t||fVdSr)r<r=s rrz%IdentitySet.update..@s,@@bggs^@@@@@@r)rr!rs rr!zIdentitySet.update?s- @@x@@@@@@@@rcht|tstS|||Sr))rYrr/r!rzs rr zIdentitySet.__ior__Bs1%-- "! ! E rc|}|j}d|D|jfd|D|S)Nc,h|]}t|Sr r<r=s r z)IdentitySet.difference..K---SC---rc3.K|]\}}|v ||fVdSr)r r*rtvr{s rrz)IdentitySet.difference..M/ B B11E>>aV>>>> B BrrIrr!rrrrr>r{s @rrzIdentitySet.differenceHsl!!---H--- B B B B  B B B    rcdt|tstS||Sr))rYrr/rrzs rr zIdentitySet.__sub__Qr7rcD||j|_dSr))rrrs rrzIdentitySet.difference_updateVs11: rcht|tstS|||Sr))rYrr/rrzs rrzIdentitySet.__isub__Ys3%-- "! ! u%%% rc|}|j}d|D|jfd|D|S)Nc,h|]}t|Sr r<r=s rrEz+IdentitySet.intersection..brFrc3.K|]\}}|v ||fVdSr)r rHs rrz+IdentitySet.intersection..cs8  q!!u**QF****  rrKrLs @rrzIdentitySet.intersection_s{!!---H---    &}}       rcdt|tstS||Sr))rYrr/rrzs rr zIdentitySet.__and__hs.%-- "! !  '''rcD||j|_dSr))rrrs rrzIdentitySet.intersection_updatems))(33< rcht|tstS|||Sr))rYrr/rrzs rrzIdentitySet.__iand__ps3%-- "! !   ''' rc8|}|jd|D|jfdD|jfdD|S)Nc.i|]}t||Sr r<r=s rr6z4IdentitySet.symmetric_difference..ys 222#C#222rc3.K|]\}}|v ||fVdSr)r rHs rrz3IdentitySet.symmetric_difference..{rJrc3.K|]\}}|v ||fVdSr)r )r*rtrIr>s rrz3IdentitySet.symmetric_difference..~s5 B B1'1A1AaV1A1A1A1A B BrrKrLs @@rrz IdentitySet.symmetric_differencevs!!-22222 B B B B  B B B     B B B B B B B    rcdt|tstS||Sr)rYrr/rrzs rr zIdentitySet.__xor__s.%-- "! !((///rcD||j|_dSr))rrrs rrz'IdentitySet.symmetric_difference_updates11(;;D rcht|tstS|||Sr)r[rzs rrzIdentitySet.__ixor__s3%-- "! ! !!%((( rczt|t|jSr))typernrrors rrzIdentitySet.copys.tDzz$t}335566777rc*t|jSr))rkrrs rrlzIdentitySet.__len__4=!!!rcNt|jSr))rnrrors rrpzIdentitySet.__iter__sDM((**+++rc td)Nzset objects are unhashabler rs r__hash__zIdentitySet.__hash__s4555rc~t|jdt|jdSr)r_rrrrors rr]zIdentitySet.__repr__s8::...T]5I5I5K5K0L0L0L0LMMrr))*rrrr8rSrrrrrBr^r!r$r'r-r0r2r4r6r9r[r r!r rr rrrr rrrr rrrrrlrprdr]r rrrrsc"""" )))***%%% 444;;;    $$$ ???   &&& AAA !!! AAA &&& ;;; ((( ===   000 EEE 888H""",,,666NNNNNrrc.eZdZddZdZdZdZdZdS) WeakSequencer cjtj|fd|_fd|D|_dS)NcV|}||j|dSdSr))_storager)rselfrefrs r_removez&WeakSequence.__init__.._removes7799D $$T***** rc:g|]}tj|Sr )weakrefref)r*rrls rr,z)WeakSequence.__init__..s2   .5GK ) )   r)rnrorlrj)r_WeakSequence__elementsrls @rrSzWeakSequence.__init__s]#*+d"3"3 + + + +      9C    rcj|jtj||jdSr))rjrrnrorlrs rrzWeakSequence.appends, W[t|<<=====rc*t|jSr))rkrjrs rrlzWeakSequence.__len__rarc8dd|jDDS)Nc3K|]}||V dSr)r r=s rrz(WeakSequence.__iter__..s+  sC  rc3*K|]}|VdSr)r )r*ros rrz(WeakSequence.__iter__..s(;;cCCEE;;;;;;r)rjrs rrpzWeakSequence.__iter__s3  ;;T];;;    rcr |j|}|S#t$rtd|zwxYw)NzIndex %s out of range)rjr IndexError)rindexrs rrzWeakSequence.__getitem__sQ -&C355L > > >4u<== = >s 6N)r )rrrrSrrlrprr rrrgrgsd     >>>"""   rrgceZdZddZdS)OrderedIdentitySetNct|t|_|r|D]}||dSdSr))rrSrrr)rros rrSzOrderedIdentitySet.__init__s]T"""#          rr))rrrrSr rrrzrzs(rrzceZdZdZdZdZdS) PopulateDictzA dict which populates missing values via a creation function. Note the creation function takes a key, unlike collections.defaultdict. c||_dSr)creator)rrs rrSzPopulateDict.__init__s  rc:||x||<}|Sr)rrr0vals r __missing__zPopulateDict.__missing__s!,,s+++S C rNrrrr8rSrr rrr~r~s<rr~ceZdZdZdZdZdS)WeakPopulateDictzaLike PopulateDict, but assumes a self + a method and does not create a reference cycle. c^|j|_|j}tj||_dSr))__func__r__self__rnroweakself)rcreator_methodrs rrSzWeakPopulateDict.__init__s)%. !* H-- rc`|||x||<}|Sr))rrrs rrzWeakPopulateDict.__missing__s+,,t}}<<<S C rNrr rrrrs< ... rrcDttj|Sr))r9operator itemgetter)idxs rrs,S1122rcttjsfd|DSfd|DS)Nc2g|]}|v||Sr r )r*xseenseen_adds rr,zunique_list..s*DDDa!4-- ----rcVg|]%}|v|#|&Sr r )r*rhashfuncrrs rr,zunique_list..sM   x{{$&&xx /D/D& &&&r)rr)seqrrrs `@@rrrso 55DxH  DDDDD3DDDD          rc&eZdZdZddZdZdZdS)UniqueAppenderzAppends items to a collection ensuring uniqueness. Additional appends() of the same object are ignored. Membership is determined by identity (``is a``) not equality (``==``). Nc||_i|_|rt|||_dSt |dr|j|_dSt |dr|j|_dSdS)Nrr)ri_uniquegetattr_data_appenderrrr)rrivias rrSzUniqueAppender.__init__s~   +")$"4"4D    T8 $ $ +"&+D    T5 ! ! +"&(D    + +rcxt|}||jvr!||d|j|<dSdSr&)rrr)rrid_s rrzUniqueAppender.appendsHhh dl " "    % % % $DL    # "rc*t|jSr))rnrirs rrpzUniqueAppender.__iter__!sDIrr))rrrr8rSrrpr rrrr sP ++++%%% rrct|dkr5t|dtjrt |dS|S)Nrr)rkrYtypes GeneratorTyper)rKs rcoerce_generator_argr%s; 3xx1}}CFE,?@@}CF|| rc||St|tjrt|ttzr|gSt|t r|St |Sr))rYrIterabler rr)rrs rto_listr,sgy a1 2 2j <, &77s At  AwwrcZt|d|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. c g|] }|j | Sr )rdr*is rr,z$has_intersection..As"E"E"E!*"E1"E"E"Er)boolr)set_rs rhas_intersectionr9s/ !!"E"Eh"E"E"EFF G GGrc|tSt|tstt|S|Sr))rrYrrs rto_setrDs9yuu a  71::rc|tSt|tstt|S|Sr)) column_setrYrrs r to_column_setrMs<y|| a $ $'!**%%%rc v|}|r|||jdi||S)z5Copy the given dict and update with the given values.r )rr!)rD_newrLs r update_copyrVs@ A   AHNNrNNN Hrc#K|D]B}t|ts't|drt|D]}|V>|VCdS)zGiven an iterator of which further sub-elements may also be iterators, flatten the sub-elements into a single iterator. rpN)rYrsrflatten_iterator)relemys rrr`sx $$$ z)B)B %d++   JJJJ rc`eZdZdZdZddZdZddZd Zd Z d Z d Z e d Z dZdS)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?Ncn||_||_||_d|_t j|_dSr)rrrrr Lockr)rrrrs rrSzLRUCache.__init__ys1  "$ n&& rc0|xjdz c_|jSNr)rrs r _inc_counterzLRUCache._inc_counters  }rct|||}||ur||d<|dS|SNr)rArr)rr0rrs rrz LRUCache.getsExxc7++ w  ''))DG7NNrcvt||}||d<|dSr)rArr)rr0rs rrzLRUCache.__getitem__s5c**##%%QAwrcJdt|DS)Ncg|] }|d S)rr rs rr,z#LRUCache.values..s000!000r)rArors rrozLRUCache.valuess"00dkk$//0000rc(||vr||S|||<|Sr)r r/s rr`zLRUCache.setdefaults# $;;9 DILrct||}|4|||g}t|||n||d<|dSr)rArrrO _manage_size)rr0r1rs rrOzLRUCache.__setitem__snxxc"" < 1 1 3 34D   T3 - - - -DG rc0|j|j|jzzSr))rrrs rsize_thresholdzLRUCache.size_thresholds}t}t~===rcx|jdsdS t|j}t ||j|j|jzzkr|rd}||tt |tj dd}||jdD]} ||d= #t$rYwxYwt ||j|j|jzzk|j dS#|j wxYw)NFrT)r0reverser)racquirerrrkrrsortedrArorrrrelease)rr by_counterrs rrzLRUCache._manage_sizesL{""5))  F "do..Jd))dmdmdn.LLLL*!&JOOD)))#KK%%8+>q+A+A4 't}7!!D! aMM#!!! !d))dmdmdn.LLLL K   ! ! ! ! !DK   ! ! ! !s0B"D C  D CDC+DD9)rrNr))rrrr8rrSrrrror`rOr9rrr rrrrmsLI'''' 111>>X>"""""rrrc D|ft|z}t|}|r|St|tft dt |Ddgz}||_td|D|_|t|<|S)Nc6g|]\}}||t|fSr))_property_getters)r*rfields rr,z+lightweight_named_tuple..s7   C$)#./$$$r)rr cg|]}||Sr)r )r*fs rr,z+lightweight_named_tuple..s???!Ar) r _lw_tuplesrr_r;rA enumerater>r)namefieldshash_tp_clss rlightweight_named_tuplers GeFmm #E ^^E " "F      "+F"3"3    !!  "    F!F??v???@@FNJu Mrc0eZdZdZdZdZdZdZdZdS)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. c0||_||_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)rrrs rrSzScopedRegistry.__init__s%" rc|} |j|S#t$r0|j||cYSwxYwr))rrrr`rrs r__call__zScopedRegistry.__call__sknn D=% % D D D=++C1B1BCC C C C Ds #7AAc8||jvS)z9Return True if an object is present in the current scope.)rrrs rhaszScopedRegistry.hass~~4=00rc>||j|<dS)z$Set the value for the current scope.N)rrrrs rrzScopedRegistry.sets +. dnn&&'''rc^ |j|=dS#t$rYdSwxYw)z Clear the current scope, if any.N)rrrrs rr^zScopedRegistry.clear sC  dnn..///    DD s  ,,N rrrr8rSrrrr^r rrrrsl     DDD111 ... rrc0eZdZdZdZdZdZdZdZdS)ThreadLocalRegistryz\A :class:`.ScopedRegistry` that uses a ``threading.local()`` variable for storage. cD||_tj|_dSr))rr localr)rrs rrSzThreadLocalRegistry.__init__s$!)) rc |jjS#t$r%|x}|j_|cYSwxYwr))rr1r.r)rrs rrzThreadLocalRegistry.__call__sO =& &   (,(9(9 9C$-%JJJ s ,==c,t|jdS)Nr1)rrrs rrzThreadLocalRegistry.has$st}g...rc||j_dSr))rr1rs rrzThreadLocalRegistry.set's! rc8 |j`dS#t$rYdSwxYwr))rr1r.rs rr^zThreadLocalRegistry.clear*s7  ###    DD s  Nrr rrrrsi ***///"""rrc8d}|D]}||ur|dz }|dkrdSdS)zrGiven a sequence and search object, return True if there's more than one, False if zero or one of them. rrTFr )sequencetargetcrs r has_dupesr1s@ A 6>> FA1uutt 5rr))7r8 __future__rrrrncompatrrrrr r frozenset EMPTY_SETrr rr;rhrFrArQrbrrrrrrrgrzr~rr column_dictordered_column_setr_gettersrrrrrrrrrrrrrrrrr rrrs!&%&&&&&&  ######))))))  IKK  " " " " " " " "@@@@@@@@@@#@@@@@@F (9999999999999&999@LLLLLLLL^11111 111,j ^^^^^$^^^Bh!h!h!h!h!h!h!h!VLNLNLNLNLN&LNLNLN^6D     4        t   (   <+ , , L22     V6    HHH       N"N"N"N"N"tN"N"N"bXc]] 455555V555p.<r