U a?@sddZddlZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddl mZddl mZd d ZGd d d eZd dZddZddZddZddZddZddZddZddZdd Zdd!d"ZGd#d$d$eZd%d&Z dd'd(Z!d)d*Z"dd,d-Z#dd/d0Z$dd1d2Z%dd4d5Z&d6d7Z'd8d9Z(dd:d;Z)Gdd?Z+d@dAZ,ddCdDZ-dEdFZ.ddGdHZ/GdIdJdJeZ0dKdLZ1GdMdNdNeZ2GdOdPdPeZ3dQdRZ4dSdTZ5dUdVZ6ddWdXZ7dYdZZ8d[d\Z9d]d^Z:dd_d`Z;dadbZZ?GdgdhdheZ@GdidjdjeZAGdkdldleBZCdmeC_DGdndmdmeZEdaFdodpZGdqdrZHddtduZIGdvdwdwejJZKddxdyZLdzd{ZMdd|d}ZNd~dZOePdZQePdZReReQfddZSeTdZUddZVGdddeTZWddZXddZYddZZddZ[ddZ\ePdZ]ddZ^ddZ_ddZ`dS)zRoutines to help with the creation, loading and introspection of modules, classes, hierarchies, attributes, functions, and methods. Nupdate_wrapper) _collections)compat)exccCs*tjr|d}t}|||S)Nzutf-8)rpy3kencodehashlibmd5update hexdigest)xmr\C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\util\langhelpers.pymd5_hexs   rc@s.eZdZdZdZd ddZddZdd Zd S) safe_reraiseaKReraise an exception after invoking some handler code. Stores the existing exception info before invoking so that it is maintained across a potential coroutine context switch. e.g.:: try: sess.commit() except: with safe_reraise(): sess.rollback() ) warn_only _exc_infoFcCs ||_dSN)r)selfrrrr__init__:szsafe_reraise.__init__cCst|_dSr)sysexc_inforrrrr __enter__=szsafe_reraise.__enter__cCsz|dkr0|j\}}}d|_|jsvtj||dnFtjsb|jrb|jdrbtd|jd|jdfd|_tj||ddS)N)with_tracebackrzfAn exception has occurred during handling of a previous exception. The previous exception is: %s %s r)rrrZraise_r warn)rtype_value tracebackexc_type exc_valueexc_tbrrr__exit__@s  zsafe_reraise.__exit__N)F)__name__ __module__ __qualname____doc__ __slots__rrr&rrrrr&s  rccsHt}|g}|rD|}||kr$q n |||||Vq dSr)setpopaddextend__subclasses__)clsseenstackrrrwalk_subclassesWs r4cCs<t|tjr|Sz t|WStk r6d|YSXdS)Nzunprintable element %r) isinstancer string_typesstr Exception)elementrrrstring_or_unprintablees   r:cCsdddtd|jDS)N css|]}|VqdSr)lower).0nrrr psz(clsname_as_plain_name..z ([A-Z][a-z]+))joinrefindallr')r1rrrclsname_as_plain_nameos  rCcCs.t|ts|j}n|}|j}t||}||kS)z1Return True if the two class methods don't match.)r5type __class__r'getattr)Zinstance_or_clsZagainst_methodZ current_cls method_nameZcurrent_methodrrrmethod_is_overriddenus   rHcCs>g}|j|j|jfD] }t|dr*|}||qt|S)zrdecode a slice object as sent to __getitem__. takes into account the 2.5 __index__() method, basically. __index__)startstopstephasattrrIappendtuple)Zslcretrrrr decode_slices   rQc 'sjt|}|D]Xtftfddtd}|D] }||kr6|||Vq q6tdq dS)Ncs t|Sr)r7)ibaserrz!_unique_symbols..iz&exhausted namespace for symbol base %s)r, itertoolschainrZitertools_imapranger. NameError)usedbasespoolsymrrSr_unique_symbolss r_ccs*|r&||d@}||V||N}qdS)z6Call the given function given each nonzero bit from n.rNr)fnr>brrrmap_bitss rbcsfdd}t|S)z'A signature-matching decorator factory.c st|st|stdt|}i}t||}t|d|dd|jf}t |dd\}}t ||d}| t |dd |j|d <d |}| |||d |j it|||j}t|d |j|_||_t||S)Nznot a decoratable functionrrtargetr`)rdr`FgroupednamezDdef %(name)s(%(args)s): return %(target)s(%(fn)s, %(apply_kw)s) r'__func__)inspect isfunctionismethodr8rinspect_getfullargspec!_update_argspec_defaults_into_envrOr'r_dictr format_argspec_plusr(_exec_code_in_envrF __defaults__ __wrapped__r) r`specenvnamesZ targ_namefn_namemetadatacode decoratedrdrrdecorates&     zdecorator..decorater)rdr{rrzr decorators r|cCs||jrtg}d}|jD]@}t|jdkrJd|}|||<|||d7}q||qt|}t||d<tj|S|SdS)zCgiven a FullArgSpec, convert defaults to be symbol names in an env.r)builtins __builtin__zx%drrcN)defaultsrDr(rNlistrOr FullArgSpec)rsrtZ new_defaultsrRargrgelemrrrrms      rmcCst||||Sr)exec)rxrtrvrrrrps rpcCst|tr0|j}|}d|r|nd|j|f}n|}}d|}|dd}t|}|dd=t|dd}||d <d |} |t|j d } t | | | |} t |d r|j \} } | j }|d krd|j |jf}t|d| ||fd}|| _ n|j | _ d|ddd| _ | j tjkr*td| j ftjs>t |drb||j_ t |jd s~| |f|j_ n||_ t |d s~| |f|_ | S)zProduce a wrapping function for the given cls or classmethod. Rationale here is so that the __init__ method of the class can serve as documentation for the function. zConstruct a new :class:`%s` object. This constructor is mirrored as a public API function; see :func:`sqlalchemy%s` for a full usage and argument description.z.%szSThis function is mirrored; see :func:`sqlalchemy%s` for a description of arguments..rFrergz5def %(name)s(%(args)s): return cls(%(apply_kw)s) )r1symbolr' _linked_toNz%s.%sz.. container:: inherited_member This documentation is inherited from :func:`sqlalchemy%s`; this constructor, :func:`sqlalchemy%s`, creates a :class:`sqlalchemy%s` object. See that class for additional details describing this subclass.r sqlalchemyz0public_factory location %s is not in sys.modulesrh)r5rDrr'splitrrlrorr(rrMrr*inject_docstring_textrsplitrmodules ImportErrorpy2krh)rdlocationZclass_locationr`Z callable_docZ location_namersrwrxrtryZ linked_toZlinked_to_locationZ linked_to_docrrrpublic_factoryst           rc@s.eZdZd ddZddZddZdd ZdS) PluginLoaderNcCs||_i|_||_dSr)groupimplsauto_fn)rrrrrrr@szPluginLoader.__init__cCs|jdSr)rclearrrrrrEszPluginLoader.clearcCs||jkr|j|S|jr:||}|r:||j|<|St|jD]&}|j|krF|j|j|<|SqFtd|j|fdS)NzCan't load plugin: %s:%s) rrrZimportlib_metadata_getrrgloadrZNoSuchModuleError)rrgloaderimplrrrrHs       zPluginLoader.loadcsfdd}||j|<dS)Ncs6t}dddD]}t||}qt|S)Nrr)rimport_rrF)modtoken modulepathobjnamerrr\s  z#PluginLoader.register..load)r)rrgrrrrrrregister[szPluginLoader.register)N)r'r(r)rrrrrrrrr?s rcCsnz tj}Wn2tk r<t|}|dt|dfYSX|j}|j}t|j d|t|j |@fSdS)Nrr) riCO_VARKEYWORDSAttributeErrorrrlbool__code__ co_argcountr co_varnamesco_flags)r`Zco_varkeywordsrsconargsrrr_inspect_func_argses   rcCs|dk}|rt}|jdd}|o>> format_argspec_plus(lambda self, a, b, c=3, **d: 123) {'args': '(self, a, b, c=3, **d)', 'self_arg': 'self', 'apply_kw': '(self, a, b, c=c, **d)', 'apply_pos': '(self, a, b, c, **d)'} rrrNz%s[0]rcrcSsd|SN=rrrrrrU3rVz%format_argspec_plus..) formatvaluecSsd|SrrrrrrrU<rV)rself_arg apply_posapply_kwapply_pos_proxiedapply_kw_proxiedr)rcallablerlinspect_formatargspeclenrn) r`rfrsrrrr num_defaultsZ name_argsZdefaulted_valsrrrrrros"             rocCst|tjkr$|rdnd}|rdnd}n (self) other unreflectable (usually C) -> (self, *args, **kwargs) z(self)rz()rez(self, *args, **kwargs)zself, *args, **kwargsz(*args, **kwargs)z*args, **kwargs)rrrrrr)objectrrorrn)methodrfrZproxiedrrrformat_argspec_initUs&  rrcsfdd}|S)zA class decorator that will copy attributes to a proxy class. The class to be instrumented must define a single accessor "_proxied". csd fdd }fdd}D].}t||rDtd||ft||||q&D].}t||rxtd||ft||||qZD]2}t||rtd||ft||||ddq|S) NFc st|}t|}d|ji}t||}t|dd}|j|d|d|d|dd}|rld |}|d <nd |}t|||j}t|d |j|_t |j d fd|_ |rt |}|S)Nr'Frerrrr)rgrrrrzLdef %(name)s(%(args)s): return target_cls.%(name)s(%(apply_kw_proxied)s) target_clszWdef %(name)s(%(args)s): return %(self_arg)s._proxied.%(name)s(%(apply_kw_proxied)s)rhS.. container:: class_bases Proxied for the %s class on behalf of the %s class.r) rFrrlr(rmror'rprqrr* classmethod) rgclslevelr`rsrtZcaller_argspecrwrxZproxy_fnproxy_cls_sphinx_namertarget_cls_sphinx_namerr instrumentsB      z:create_proxy_methods..decorate..instrumentcsRj|d}|dk r.t|jdfd}nd}dd|i}t|d|id}|S)Nrrzdef set_(self, attr): self._proxied.%(name)s = attr def get(self): return self._proxied.%(name)s get.__doc__ = doc getset = property(get, set_)rgrgetset)rrrr*rp)rgattrrrxrrrrmakeprops"  z8create_proxy_methods..decorate..makepropz class %s already has a method %sTr)F)rMrsetattr)r1rrmethprop attributes classmethodsmethodsrrrrrr{s*-      z&create_proxy_methods..decorater)rrrrrrr{rrrcreate_proxy_methodsvscrcCsTz t|WStk rN|tjkr8dgdddfYSdgdddfYSYnXdS)zinspect.getargspec with considerations for typical __init__ methods Wraps inspect.getargspec with error handling for typical __init__ cases:: object.__init__ -> (self) other unreflectable (usually C) -> (self, *args, **kwargs) rNrkwargs)rrlrrr)rrrrgetargspec_inits   rcCs t|tjr|js|jS|SdS)zSAdjust the incoming callable such that a 'self' argument is not required. N)r5r MethodTyperrh)Z func_or_clsrrrunbound_method_to_callablesrc sL|dkrg}n t|}tg}t}d}t|D]\}}zt|j} Wntk rhYq8Yq8X| j rzt | j p|d} |dkr| j r| j }| r| | j d| q| | j ddn$|fdd| j d| D| r8|ddt| j | d| j Dq8g} | fdd|D|dk rbt|rb| d dt|D|D]f\} } | |krqjz6t| }|k r|| kr| d | |fWntk rYnXqj|r6|D]X\} } z6t| }|k r|| kr| d | |fWntk r0YnXqd jjd | fS) z}Produce a __repr__() based on direct association of the __init__() specification vs. same-named attributes present. Nrrcsg|] }|fqSrrr=r)missingrr 'sz generic_repr..cSsg|]\}}||fqSrr)r=rdefaultrrrr,sc3s|]}tt|dVqdSr)reprrFrobjrrr?5szgeneric_repr..cSsg|] }t|qSrr)r=valrrrr8sz%s=%rz%s(%s), )rto_listr OrderedDict enumeraterrlrrrrrr/rr ziprMrFitemsrNr8rEr'r@)rZ additional_kwZ to_inspectZ omit_kwargZpos_argsZkw_argsZvargsrRZinsprsZ default_lenoutputrZdefvalrr)rrr generic_reprsj        rc@s6eZdZdZdZddZddZd dd Zd d Zd S)portable_instancemethodz_Turn an instancemethod into a (parent, name) pair to produce a serializable callable. )rdrgr __weakref__cCs|j|j|jdS)Nrdrgrrrrrr __getstate__Xsz$portable_instancemethod.__getstate__cCs&|d|_|d|_|dd|_dS)Nrdrgrr)rdrgrr)rstaterrr __setstate___s  z$portable_instancemethod.__setstate__rcCs|j|_|j|_||_dSr)rrdr'rgr)rrrrrrrdsz portable_instancemethod.__init__cOs ||jt|j|j||Sr)r rrFrdrg)rrkwrrrris z portable_instancemethod.__call__N)r) r'r(r)r*r+rrrrrrrrrPs  rcstjrt|tjrtS|ht|j}|r|}tjr^t|tjrHq(fdd|jD}nfdd|jD}|D]}| | |qvtj r|j dks(t |dsq(n|j dks(t |dsq(fdd|DD]}| | |qq(tS) aReturn an unordered sequence of all classes related to cls. Traverses diamond hierarchies. Fibs slightly: subclasses of builtin types are not returned. Thus class_hierarchy(class A(object)) returns (A, object), not A plus every class systemwide that derives from object. Old-style classes are discarded and hierarchies rooted on them will not be descended. c3s&|]}|krt|tjs|VqdSr)r5r ClassTyper=_Zhierrrr?s z"class_hierarchy..c3s|]}|kr|VqdSrrr r rrr?sr}r0r~csg|]}|kr|qSrrr r rrrsz#class_hierarchy..)rrr5rrr__mro__r-rrNr.r r(rMr0)r1processrr\rasrr rclass_hierarchyns:         rccs@t|}|D].}|jD]"}||jkr||j|fVq qq dS)ziterate all the keys and attributes associated with a class, without using getattr(). Does not use getattr() so that class-sensitive descriptors (i.e. property.__get__()) are not called. N)dirr r)r1keyskeyrrrriterate_attributess   r self.proxyc s0|r |}n$dkrdfddt|D}|D]}z(t||}t|dsPWq2t|d|}Wntk rvYq2YnXz2t|} t| d} t| ddd} Wntk rd } d } YnXd t} |dk r||ipi} t | | z|j | |_ Wntk rYnXt || |q2dS) z9Automates delegation of __specials__ for a proxying type.N)r+__del____getattribute__ __metaclass__rrcs6g|].}|dr|drt|s|kr|qS)__) startswithendswithrMr=rinto_clsskiprrrs    z0monkeypatch_proxied_specials..rrhrrz(self, *args, **kw)z (*args, **kw)z?def %(method)s%(fn_args)s: return %(name)s.%(method)s%(d_args)s) rrFrMrrrlrrlocalsexec_rqr)rZfrom_clsronlyrgZ from_instanceZdundersrr`rsZfn_argsZd_argspyrtrrrmonkeypatch_proxied_specialssB         r#cCst|d|t|d|kS)z;Return True if the two methods are the same implementation.rh)rF)Zmeth1Zmeth2rrrmethods_equivalents  r$c Cst|s|stdt|tr(t||r(|St|p>ddt|D}tt|}tj}t|trd|}n|svt}tj}nt|}||||r|St|t s|tjkrdpd}td||d |fGdd d t }|rd |j |_ t} t |D]T\} } | |krtd | t| s.td | | ft|| t| | | q|| |rZ|Std d || dS)aEnsure basic interface compliance for an instance or dict of callables. Checks that ``obj`` implements public methods of ``cls`` or has members listed in ``methods``. If ``required`` is not supplied, implementing at least one interface method is sufficient. Methods present on ``obj`` that are not in the interface are ignored. If ``obj`` is a dict and ``dict`` does not meet the interface requirements, the keys of the dictionary are inspected. Keys present in ``obj`` that are not in the interface will raise TypeErrors. Raises TypeError if ``obj`` does not meet the interface criteria. In all passing cases, an object with callable members is returned. In the simple case, ``obj`` is returned as-is; if dict processing kicks in then an anonymous class is returned. obj A type, instance, or dictionary of callables. cls Optional, a type. All public methods of cls are considered the interface. An ``obj`` instance of cls will always pass, ignoring ``required``.. methods Optional, a sequence of method names to consider as the interface. required Optional, a sequence of mandatory implementations. If omitted, an ``obj`` that provides at least one interface method is considered sufficient. As a convenience, required may be a type, in which case all public methods of the type are required. z2a class or collection of method names are requiredcSsg|]}|ds|qS)r )rrrrrrs z as_interface..zany ofzall ofz%r does not implement %s: %src@seZdZdZdS)z(as_interface..AnonymousInterfacezA callable-holding shell.N)r'r(r)r*rrrrAnonymousInterface6sr%Z Anonymousz%r: unknown in this interfacez%r=%r is not callablez,dictionary does not contain required keys %sN)rr5rDr,roperatorgegt intersectionrnr@rr'dictlike_iteritemsrrr staticmethodr.) rr1rrequiredZ interfaceZ implementedZcompliesZ qualifierr%foundrrrrr as_interfacesP!          r.c@s6eZdZdZd ddZddZddZed d ZdS) memoized_property2A read-only @property that is only evaluated once.NcCs||_|p|j|_|j|_dSrfgetr*r'rr2rrrrrQs zmemoized_property.__init__cCs&|dkr |S|||j|j<}|Sr)r2rr'rrr1resultrrr__get__Vszmemoized_property.__get__cCst||jdSr)r/resetr')rrrrr_reset\szmemoized_property._resetcCs|j|ddSr)rr-)r1rrgrrrr7_szmemoized_property.reset)N) r'r(r)r*rr6r8rr7rrrrr/Ns  r/csfdd}t|S)zDecorate a method memoize its return value. Best applied to no-arg methods: memoization is not sensitive to argument values, and will always return the same value even when called with different arguments. cs<|f||fdd}j|_j|_||jj<S)NcsSrrarr5rrmemopsz6memoized_instancemethod..oneshot..memo)r'r*rrrrr<r`r;roneshotms   z(memoized_instancemethod..oneshotr)r`r?rr>rmemoized_instancemethodds r@c@sNeZdZdZdZeZddZddZddZ Gd d d e Z e d d Z d S) HasMemoizedzyA class that maintains the names of memoized elements in a collection for easy cache clearing, generative, etc. rcCs|jD]}|j|dqdSr)_memoized_keysrr-rrrrr_reset_memoizationss zHasMemoized._reset_memoizationscCs|jD]}||jkstqdSr)rBrAssertionErrorrCrrr_assert_no_memoizationss z#HasMemoized._assert_no_memoizationscCs||j|<|j|hO_dSr)rrB)rrr!rrr_set_memoized_attributes z#HasMemoized._set_memoized_attributec@s"eZdZdZdddZddZdS)zHasMemoized.memoized_attributer0NcCs||_|p|j|_|j|_dSrr1r3rrrrs z'HasMemoized.memoized_attribute.__init__cCs8|dkr |S|||j|j<}|j|jhO_|Sr)r2rr'rBr4rrrr6s z&HasMemoized.memoized_attribute.__get__)N)r'r(r)r*rr6rrrrmemoized_attributes rHcsfdd}t|S)z+Decorate a method memoize its return value.csN|f||fdd}j|_j|_||jj<|jjhO_S)NcsSrrr9r;rrr<szBHasMemoized.memoized_instancemethod..oneshot..memo)r'r*rrBr=r>r;rr?s  z4HasMemoized.memoized_instancemethod..oneshotr)r1r`r?rr>rr@s z#HasMemoized.memoized_instancemethodN)r'r(r)r*r+ frozensetrBrDrFrGrrHrr@rrrrrA{srAc@s$eZdZdZdZddZddZdS) MemoizedSlotszApply memoized items to an object using a __getattr__ scheme. This allows the functionality of memoized_property and memoized_instancemethod to be available to a class using __slots__. rcCs t|dSr)r)rrrrr_fallback_getattrszMemoizedSlots._fallback_getattrcsdrtnptdrBtd}t||Stdrztdfdd}j|_|SSdS)NZ _memoizedz_memoized_attr_%sz_memoized_method_%scs6||fdd}j|_j|_t|S)NcsSrrr9r;rrr<sz8MemoizedSlots.__getattr__..oneshot..memo)r'r*r)rrr<r`rrr;rr?s    z*MemoizedSlots.__getattr__..oneshot)rrrMrFrr*rK)rrr!r?rrLr __getattr__s    zMemoizedSlots.__getattr__N)r'r(r)r*r+rKrMrrrrrJsrJcCsDt|tjr<|}|dkr$dS|dkr0dStd|t|S)N)trueyesonyt1T)falsenooffr>f0FzString is not true/false: %r)r5rr6stripr< ValueErrorrrrrrasbools   r[csfdd}|S)zqReturn a callable that will evaluate a string as boolean, or one of a set of "alternate" string values. cs|kr |St|SdSr)r[rtextrr bool_or_valuesz"bool_or_str..bool_or_valuer)r]r^rr\r bool_or_strs r_cCs|dkr |St|S)zCoerce to integer.N)int)r!rrrasintsracCsj|dkr |}||krft|tr,t|||sf||dk rf|tkrV|rVt||||<n|||||<dS)zIf 'key' is present in dict 'kw', coerce its value to type 'type\_' if necessary. If 'flexi_bool' is True, the string '0' is considered false when coercing to boolean. N)r5rDrr[)rrr Z flexi_booldestrrrcoerce_kw_types   rccs$t|}|ftfdd|DS)zbProduce a tuple structure that is cacheable using the __dict__ of obj to retrieve values c3s&|]}|jkr|j|fVqdSrrr=krrrr?s z"constructor_key..)rrO)rr1rurrrconstructor_keysrgcs0t|}|fdd||D|||S)zInstantiate cls using the __dict__ of obj as constructor arguments. Uses inspect to match the named arguments of ``cls``. c3s&|]}|jkr|j|fVqdSrrdrerrrr?&s z#constructor_copy..)rr difference)rr1rrrurrrconstructor_copys rics&tjtdfdd}|S)z%Return a threadsafe counter function.rc s$tW5QRSQRXdSr)nextrcounterlockrr_next3szcounter.._next)r threadingLockrWcount)rnrrkrrl,s  rlcCst|dr*|jdk r$t|jtr$tS|jSt|tr8tp:t}||trJtS||trXtS||trftSt|drttSt|drtSt|drtS|SdS)zGiven an instance or class, guess if it is or is acting as one of the basic collection types: list, set and dict. If the __emulates__ property is present, return that preferentially. __emulates__NrNr.r,)rMrr issubclassr,r5rDrrn)ZspecimenrZisarrrduck_type_collection:s*        rtcCs^t||r|St|trBtd|ddd|Dt|fntd||t|fdS)Nz8Argument '%s' is expected to be one of type %s, got '%s'z or css|]}d|VqdS)z'%s'Nr)r=r:rrrr?bsz"assert_arg_type..z6Argument '%s' is expected to be of type '%s', got '%s')r5rOr ArgumentErrorr@rD)rZargtypergrrrassert_arg_type[s   rvcstjrtdrFtSn(tdr0StdrFtStdtdddkrntdtdrfdd }|Std rtfd d  DStddS) z?Return a (key, value) iterator for almost any dict-like object.r iteritems __getitem__rNzObject '%r' is not dict-likeiterkeysc3s D]}||fVqdSr)ry)rdictlikegetterrriterator}s z$dictlike_iteritems..iteratorrc3s|]}||fVqdSrr)r=r)r|rrr?sz%dictlike_iteritems..) rr rMrrrwiterrFrr)r{r}rrzrr*ks        r*cs(eZdZdZfddZddZZS) classpropertyaAA decorator that behaves like @property except that operates on classes rather than instances. The decorator is currently special when using the declarative module, but note that the :class:`~.sqlalchemy.ext.declarative.declared_attr` decorator should be used for this purpose with declarative. cs$tt|j|f|||j|_dSr)superrrr*)rr2rrrErrrszclassproperty.__init__cCs ||Sr)r2)descrr1rrrr6szclassproperty.__get__)r'r(r)r*rr6 __classcell__rrrrrs rc@s$eZdZddZddZddZdS)hybridpropertycCs||_||_dSrrrrrrrrrszhybridproperty.__init__cCs$|dkr||}|S||SdSr)rr)rinstanceownerZclsvalrrrr6s zhybridproperty.__get__cCs ||_|Srrrrrr classlevelszhybridproperty.classlevelN)r'r(r)rr6rrrrrrsrc@s(eZdZdZddZddZddZdS) hybridmethodz/Decorate a function as cls- or instance- level.cCs||_||_dSrrrrrrrszhybridmethod.__init__cCs*|dkr|j||jS|j||SdSr)rr6rEr)rrrrrrr6szhybridmethod.__get__cCs ||_|Srrrrrrrszhybridmethod.classlevelN)r'r(r)r*rr6rrrrrrsrc@s.eZdZd ddZddZddZdd ZdS) _symbolNcCs@t|tjst|dkr t|}tt|}||_|r<||_ |S)zConstruct a new named symbol.N) r5rr6rEhashr`__new__rrgr*)rrgr canonicalvrrrrs z_symbol.__new__cCst|jdt|ffS)Nr)rrgr`rrrr __reduce__sz_symbol.__reduce__cCst|Srrrrrr__str__sz_symbol.__str__cCs d|jS)Nz symbol(%r))rgrrrr__repr__sz_symbol.__repr__)NN)r'r(r)rrrrrrrrrs rrc@s6eZdZdZiZejZdddZ e d ddZ dS) raA constant symbol. >>> symbol('foo') is symbol('foo') True >>> symbol('foo') A slight refinement of the MAGICCOOKIE=object() pattern. The primary advantage of symbol() is its repr(). They are also singletons. Repeated calls of symbol('name') will all return the same instance. The optional ``doc`` argument assigns to ``__doc__``. This is strictly so that Sphinx autoattr picks up the docstring we want (it doesn't appear to pick up the in-module docstring if the datamember is in a different module - autoattribute also blows up completely). If Sphinx fixes/improves this then we would no longer need ``doc`` here. Nc CsL|j<|j|}|dkr2t||||j|<}|W5QRSQRXdSr)_locksymbolsrr)r1rgrrr^rrrrs  zsymbol.__new__FcCsj|D]>\}}||kr |S|r6||jkr6|S||kr|Sq|dkrTdStd||fdS)aGiven a user parameter, parse the parameter into a chosen symbol. The user argument can be a string name that matches the name of a symbol, or the symbol object itself, or any number of alternate choices such as True/False/ None etc. :param arg: the user argument. :param choices: dictionary of symbol object to list of possible entries. :param name: name of the argument. Used in an :class:`.ArgumentError` that is raised if the parameter doesn't match any available argument. :param resolve_symbol_names: include the name of each symbol as a valid entry. NzInvalid value for '%s': %r)rrgrru)r1rchoicesrgZresolve_symbol_namesr^choicerrrparse_user_arguments zsymbol.parse_user_argument)NN)F) r'r(r)r*rrrorprrrrrrrrrs  cCst|_td7adS)zAssign a '_creation_order' sequence to the given instance. This allows multiple instances to be sorted in order of creation (typically within a single thread; the counter is not particularly threadsafe). rN)_creation_order)rrrrset_creation_orders rcOs>z |||WStk r8tdtddYnXdS)zXexecutes the given function, catches all exceptions and converts to a warning. z%s('%s') ignoredrrN)r8rrr)rrrrrrwarn_exception+s rcCsFz(t||kr d|d|WS|WSWntk r@|YSXdS)Nz%s...r)rr)r!Zlen_rrrellipses_string6s   rcs0eZdZdZfddZddZddZZS)_hash_limit_stringa/A string subclass that can only be hashed on a maximum amount of unique values. This is used for warnings so that we can send out parameterized warnings without the __warningregistry__ of the module, or the non-overridable "once" registry within warnings.py, overloading memory, cs@||d|}tt|||}td|t||f|_|S)Nz6 (this warning may be suppressed after %d occurrences)z%s_%d)rrrr_hash)r1r!numrZ interpolatedrrrrrKs z_hash_limit_string.__new__cCs|jSr)rrrrr__hash__Ssz_hash_limit_string.__hash__cCst|t|kSr)r)rotherrrr__eq__Vsz_hash_limit_string.__eq__)r'r(r)r*rrrrrrrrr@s rcCs(|rttj||dn t|tjdS)zdIssue a warning. If msg is a string, :class:`.exc.SAWarning` is used as the category. )rxN)_warnings_warnr SAWarning)msgrxrrrrZsrcCs |rt|d|}t|tjdS)z\Issue a warning with a parameterized string, limiting the number of registrations. N)rrrr)rrrrr warn_limitedgs rcCszt|}Wn&tk r&d}Yn>d}Yn0X|dk rdtd|jddrd|j}|d7}q6|dk rtj |||ddntj ||dddS)Nrz^(?:sqlalchemy\.|alembic\.)r'rr) stacklevel) r _getframerZrAmatch f_globalsrf_backwarningsr)messagecategoryrframerrrrqs    rcsgfdd}|S)zNDecorate the given function to be a no-op after it is called exactly once.cs@}r<}z |||WSr4d|YnXdS)Nr)r-insert)rrZ strong_fnZonce_fnr`onceretry_on_exceptionrrgos  zonly_once..gor)r`rrrrr only_onces rz%sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.pyzunit(?:2|test2?/)cCs`d}t|d}||kr0|||r0|d7}q||krP|||rP|d8}q0|||dS)atChop extraneous lines off beginning and end of a traceback. :param tb: a list of traceback lines as returned by ``traceback.format_stack()`` :param exclude_prefix: a regular expression object matching lines to skip at beginning of ``tb`` :param exclude_suffix: a regular expression object matching lines to skip at end of ``tb`` rr)rsearch)tbZexclude_prefixZexclude_suffixrJendrrrchop_tracebacks    rcCs$d|}t}t|||dS)Nz&def set(obj, value): obj.%s = valuer,)rcopyr)attrnamerxrtrrr attrsetters  rcs(eZdZdZfddZddZZS)EnsureKWArgTypezYApply translation of functions to accept \**kw arguments if they don't already. c sr|j}|rZ|D]J}t||}|r||}t|}|js||||<} t||| qtt | |||dSr) Z ensure_kwargrArrrlr _wrap_w_kwrrrr) r1Zclsnamer\ZclsdictZfn_regrrr`rswrappedrrrrs  zEnsureKWArgType.__init__csfdd}t|S)Ncs|Srr)rrr>rrwrapsz(EnsureKWArgType._wrap_w_kw..wrapr)rr`rrr>rrs zEnsureKWArgType._wrap_w_kw)r'r(r)r*rrrrrrrrs rcCsjt|drt||S|}|jj|_t|dr4|j|_t|jdrT|jjrT|jj|_n|jrb|j|_|SdS)zAugment functools.update_wrapper() to work with objects with a ``__call__()`` method. :param fn: object with __call__ method r'r(r*N)rMrrEr'r(rr*)wrapperr`Z_frrr wrap_callables     rcCsd|kr|dSd}gg}d}t|}||kr||}|dkr|dkr|||dkr|||ddkr||dd|d7}q|dN}n*|dkr|dkr|gn|d||d7}q(dd|DS)aParse a dotted identifier with accommodation for quoted names. Includes support for SQL-style double quotes as a literal character. E.g.:: >>> quoted_token_parser("name") ["name"] >>> quoted_token_parser("schema.name") ["schema", "name"] >>> quoted_token_parser('"Schema"."Name"') ['Schema', 'Name'] >>> quoted_token_parser('"Schema"."Name""Foo"') ['Schema', 'Name""Foo'] "rrrrcSsg|]}d|qS)r)r@)r=rrrrr#sz'quoted_token_parser..)rrrN)r!rr5idxlvcharrrrquoted_token_parsers$ $    rcstfdd}|S)Ncs:|jdk r|jpd}|r0t|fddD}||_|S)Nrcsi|] }|qSrr)r=paramr\rr ,sz8add_parameter_text..decorate..)r*inject_param_text)r`rparamsr]rrr{)s z$add_parameter_text..decorate)rr)rr]r{rrradd_parameter_text&s rcCsN|dd}t|dkr|S|\}}|ds@|dt|St|SdS)N rr;)rrrtextwrapdedent)r]Z split_text firstline remainingrrr_dedent_docstring3s   rcCst|pd}|d}t|dkr,|dt|d}|drP|ddddt|D}|dd|t|t|d}|d||||d}d |S)NrrrrcSsg|]\}}|s|qSr)rY)r=rlinerrrrHsz)inject_docstring_text..) rrrrNrrrrminr@)doctextZ injecttextposlinesZ injectlinesZblanksZ inject_posrrrr?s      rz(\s+):param (.+?):c Cs t|}g}d}|r|}t|}|dkr|r|dd}||krdt|dd}|rt d|d} | rdt| d}|||}nV|r| d|dgd}n<| s| ||dgd}n| dr| ||gq| |qd|S) Nr*r;rz(\s+)\Srrz::) collectionsdeque splitlinespopleft _param_regrrlstriprrAr/rstriprrNr@) rZ inject_paramsZdoclinesrZ to_injectrrrindentm2rrrrTs6   rcCst|dkrdSt|dk}|r,|ddn|dd|dd}dd|D}|r`d|Sd d|dd|dfSdS) zTrims a list of strings from the middle and return a string of up to four elements. Strings greater than 11 characters will be truncatedrNrrcrcSs,g|]$}t|dkr$d|ddn|qS) z%s..N)r)r=rgrrrrsz$repr_tuple_names..rz %s, ..., %s)rr@)ruflagresrrrrepr_tuple_namess  ( rcCsFz*ddlm}ddlm}ddlm}WdStk r@YdSXdS)Nr)cimmutabledict) cprocessors) cresultproxyTF)rrrrr)rrrrrrhas_compiled_exts   r)N)N)FF)T)T)rrr)rNr)NNrN)NNN)TN)N)r)N)Nr)ar*r functoolsrr rirWr&rArrrrrrrrrrrr4r:rCrHrQr_rbr|rmrprrrrrrrorrrrrrrrr#r$r.r/r@rArJr[r_rarcrgrirlrtrvr*propertyrrrr`rr'rrrrr text_typerrrrrcompileZ_SQLA_REZ _UNITTEST_RErrDZNoneTyperrrrrrrrrrrrrrrs    1  # W& + 6 p % t H3 ? V8)    !D      ,   +