B 4]@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZddl mZd d ZGd d d eZd dZddZddZddZddZddZddZGdddeZddZddd Zd!d"Zdd$d%Zdd'd(Zdd)d*Z d+d,Z!d-d.Z"dd0d1Z#Gd2d3d3eZ$d4d5Z%d6d7Z&dd9d:Z'd;d<Z(dd=d>Z)Gd?d@d@eZ*dAdBZ+GdCdDdDeZ,GdEdFdFeZ-ddGdHZ.GdIdJdJeZ/dKdLZ0dMdNZ1dOdPZ2ddQdRZ3dSdTZ4dUdVZ5ddWdXZ6dYdZZ7d[d\Z8Gd]d^d^e9Z:Gd_d`d`eZ;GdadbdbeZdee>_?GdfdedeeZ@daAdgdhZBdidjZCddldmZDGdndodoejEZFdpdqZGdrdsZHdtduZIeJdvZKeJdwZLeLeKfdxdyZMeNdZOdzd{ZPGd|d}d}eNZQd~dZRddZSddZTddZUddZVddZWdS)zRoutines to help with the creation, loading and introspection of modules, classes, hierarchies, attributes, functions, and methods. )update_wrapperN) _collections)compat)exccCs*tjr|d}t}|||S)Nzutf-8)rpy3kencodehashlibZmd5updateZ hexdigest)xmrN/opt/alt/python37/lib64/python3.7/site-packages/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 ||_dS)N)r)selfrrrr__init__8szsafe_reraise.__init__cCst|_dS)N)sysexc_infor)rrrr __enter__;szsafe_reraise.__enter__cCsz|dkr0|j\}}}d|_|jsvt|||nFtjsb|jrb|jdrbtd|jd|jdfd|_t|||dS)NrzfAn exception has occurred during handling of a previous exception. The previous exception is: %s %s r)rrrZreraiserwarn)rtype_value tracebackexc_type exc_valueZexc_tbrrr__exit__>s zsafe_reraise.__exit__N)F)__name__ __module__ __qualname____doc__ __slots__rrrrrrrr$s  rcCsdddtd|jDS)N css|]}|VqdS)N)lower).0nrrr Tsz(clsname_as_plain_name..z ([A-Z][a-z]+))joinrefindallr )clsrrrclsname_as_plain_nameRsr.cCsBg}x4|j|j|jfD] }t|dr,|}||qWt|S)zrdecode a slice object as sent to __getitem__. takes into account the 2.5 __index__() method, basically. __index__)startstopstephasattrr/appendtuple)ZslcZretr rrr decode_sliceXs  r6c 'spt|}xb|D]Ztftfddtd}x2|D]}||kr:|||VPq:WtdqWdS)Ncs t|S)N)str)i)baserrkz!_unique_symbols..iz&exhausted namespace for symbol base %s)set itertoolschainrZitertools_imaprangeadd NameError)ZusedbasesZpoolsymr)r9r_unique_symbolsfs   rDccs.x(|r(||d@}||V||N}qWdS)z6Call the given function given each nonzero bit from n.rNr)fnr(brrrmap_bitsvs rGcsfdd}t|S)z'A signature-matching decorator factory.cst|st|stdt|}t|d|dd|jf}t|dd\}}t ||d}| t |dd |j|d <d |}t ||||i|j}t |d |j|_||_t||S) Nznot a decoratable functionrrtargetrE)rIrEF)groupednamezDdef %(name)s(%(args)s): return %(target)s(%(fn)s, %(apply_kw)s) im_func)inspect isfunctionismethod Exceptionrinspect_getfullargspecr5r rDdictr format_argspec_plus_exec_code_in_envgetattr __defaults__ __wrapped__r)rEspecnamesZ targ_namefn_namemetadatacode decorated)rIrrdecorates    zdecorator..decorate)r)rIr^r)rIr decorators r_cCst||||S)N)exec)r\envrZrrrrTs rTc Cst|tr$|j}|}d|j|f}n|}}d|}|dd}t|}|dd=t|dd}||d<d |}|td } t || | |} |j | _ d | dd d| _ tj st|d r||j_ n||_ | 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:`~%s` for a full usage and argument description.zJThis function is mirrored; see :func:`~%s` for a description of arguments..rF)rJrKz5def %(name)s(%(args)s): return cls(%(apply_kw)s) )r-symbolZ sqlalchemyr__func__) isinstancetyperr splitrrQrSrdr`r#rsplitr!py2kr3re) rIlocationrEZ callable_docZ location_namerXr[r\rar]rrrpublic_factorys0       rmc@s.eZdZd ddZddZddZdd ZdS) PluginLoaderNcCs||_i|_||_dS)N)groupimplsauto_fn)rrorqrrrrszPluginLoader.__init__cCs|jdS)N)rpclear)rrrrrrszPluginLoader.clearcCs||jkr|j|S|jr:||}|r:||j|<|Sy ddl}Wntk rZYn,Xx(||j|D]}|j|j|<|SWtd|j|fdS)NrzCan't load plugin: %s:%s) rprq pkg_resources ImportErrorZiter_entry_pointsroloadrZNoSuchModuleError)rrKloaderrsimplrrrrus        zPluginLoader.loadcsfdd}||j|<dS)Ncs:t}x$dddD]}t||}qWt|S)Nrbr)rimport_rhrU)modtoken) modulepathobjnamerrrus z#PluginLoader.register..load)rp)rrKr{r|rur)r{r|rregisterszPluginLoader.register)N)r r!r"rrrrur}rrrrrns rncCsjy tj}Wn.tk r8t|}|dt|dfSX|j}|j}t|j d|t|j |@fSdS)Nrr) rMZCO_VARKEYWORDSAttributeErrorrrQbool__code__ co_argcountlist co_varnamesco_flags)rEZco_varkeywordsrXconargsrrr_inspect_func_argss  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)'} rrz%s[0]NrrHrcSsd|S)N=r)r rrrr:r;z%format_argspec_plus..)Z formatvalue)rself_arg apply_posapply_kwrc)rcallablerQinspect_formatargspeclenrR) rErJrXrrrZ num_defaultsZ name_argsZdefaulted_valsrrrrrS}sJ      rScCsV|tjkr|rdpd}n.y t||dStk rD|rd}YnXtd|||dS)a format_argspec_plus with considerations for typical __init__ methods Wraps format_argspec_plus with error handling strategies for typical __init__ cases:: object.__init__ -> (self) other unreflectable (usually C) -> (self, *args, **kwargs) z(self)r)rJz(self, *args, **kwargs)zself, *args, **kwargs)rrrr)objectrrSrrR)methodrJrrrrformat_argspec_inits   rcCsJy t|Stk rD|tjkr2dgdddfSdgdddfSYnXdS)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)rrQrrr)rrrrgetargspec_inits   rcCs t|tjr|js|jS|SdS)zSAdjust the incoming callable such that a 'self' argument is not required. N)rfr MethodTyperre)Z func_or_clsrrrunbound_method_to_callablesrrc sV|dkrg}n t|}tg}t}d}xt|D]\}}yt|j} Wntk rhw:Yq:X| j rzt | j p|d} |dkr| j r| j }| r| | j d| q| | j ddn$|fdd| j d| D| r:|ddt| j | d| j Dq:Wg} | fdd|D|dk rdt|rd| d dt|Dxr|D]f\} } | |krqny6t| }|k r|| kr| d | |fWntk rYnXqnW|r@x`|D]X\} } y6t| }|k r || kr | d | |fWntk r8YnXqWd jjd | fS) z}Produce a __repr__() based on direct association of the __init__() specification vs. same-named attributes present. Nrrcsg|] }|fqSrr)r'arg)missingrr %sz generic_repr..cSsg|]\}}||fqSrr)r'rdefaultrrrr+sc3s|]}tt|dVqdS)N)reprrU)r'r)objrrr)3szgeneric_repr..cSsg|] }t|qSr)r)r'valrrrr6sz%s=%rz%s(%s)z, )rto_listr OrderedDict enumeraterrQrrrrrextendrr zipr3rUitemsr4rP __class__r r*)rZ additional_kwZ to_inspectZ omit_kwargZpos_argsZkw_argsZvargsr8ZinsprXZ default_lenoutputrZdefvalrr)rrr generic_reprs`        rc@s6eZdZdZdZddZddZd dd Zd d Zd S)portable_instancemethodz_Turn an instancemethod into a (parent, name) pair to produce a serializable callable. )rIrKr __weakref__cCs|j|j|jdS)N)rIrKr)rIrKr)rrrr __getstate__Vsz$portable_instancemethod.__getstate__cCs&|d|_|d|_|dd|_dS)NrIrKrr)rIrKrr)rstaterrr __setstate__]s  z$portable_instancemethod.__setstate__rcCs|j|_|j|_||_dS)N)rrIr rKr)rZmethrrrrrbsz portable_instancemethod.__init__cOs ||jt|j|j||S)N)r rrUrIrK)rrkwrrrrgs z portable_instancemethod.__call__N)r) r r!r"r#r$rrrrrrrrrNs  rcs tjrt|tjrtS|ht|j}x|r|}tjrbt|tjrLq*fdd|jD}nfdd|jD}x |D]}| | |q|Wtj r|j dks*t |dsq*n|j dks*t |dsq*x2fdd|DD]}| | |qWq*WtS) 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|VqdS)N)rfr ClassType)r'_)hierrrr)sz"class_hierarchy..c3s|]}|kr|VqdS)Nr)r'r)rrrr)sbuiltins__subclasses__Z __builtin__csg|]}|kr|qSrr)r'r)rrrrsz#class_hierarchy..)rrjrfrrr__mro__poprr4r@rr!r3r)r-ZprocessrrBrFsr)rrclass_hierarchyls4          rccsFt|}x8|D]0}x*|jD] }||jkr||j|fVPqWqWdS)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)dirrr)r-keyskeyrrrriterate_attributess    r self.proxyc s0|r |}n$dkrdfddt|D}x|D]}y&t||}t|dsPw4t|d|}Wntk rtw4YnXy2t|} t| d} t| ddd} Wntk rd } d } YnXd t} |dk r||ipi} t | | y|j | |_ Wntk rYnXt || |q4WdS) z9Automates delegation of __specials__ for a proxying type.N)r$__del____getattribute__Z __metaclass__rrcs6g|].}|dr|drt|s|kr|qS)__) startswithendswithr3)r'r )into_clsskiprrrs    z0monkeypatch_proxied_specials..rrLrrz(self, *args, **kw)z (*args, **kw)z?def %(method)s%(fn_args)s: return %(name)s.%(method)s%(d_args)s) rrUr3r~rrQrrlocalsZexec_rVsetattr)rZfrom_clsrZonlyrKZ from_instanceZdundersrrErXZfn_argsZd_argspyrar)rrrmonkeypatch_proxied_specialss<        rcCst|d|t|d|kS)z;Return True if the two methods are the same implementation.re)rU)Zmeth1Zmeth2rrrmethods_equivalents rc Csx|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} x`t |D]T\} } | |krtd | t| s0td | | ft|| t| | | qW|| |r^|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)r)r'r rrrrsz as_interface..zany ofzall ofz%r does not implement %s: %sz, c@seZdZdZdS)z(as_interface..AnonymousInterfacezA callable-holding shell.N)r r!r"r#rrrrAnonymousInterface4srZ Anonymousz%r: unknown in this interfacez%r=%r is not callablez,dictionary does not contain required keys %sN)rrfrgr<roperatorgegt intersectionrRr*rr dictlike_iteritemsrrr staticmethodr@) rr-methodsZrequiredZ interfaceZ implementedZcompliesZ qualifierrfoundrrwrrr as_interfacesH!        rc@s6eZdZdZd ddZddZddZed d ZdS) memoized_propertyz2A read-only @property that is only evaluated once.NcCs||_|p|j|_|j|_dS)N)fgetr#r )rrrlrrrrOs zmemoized_property.__init__cCs&|dkr |S|||j|j<}|S)N)rrr )rrr-resultrrr__get__Tszmemoized_property.__get__cCst||jdS)N)rresetr )rrrrr_resetZszmemoized_property._resetcCs|j|ddS)N)rr)r-rrKrrrr]szmemoized_property.reset)N) r r!r"r#rrr classmethodrrrrrrLs  rcsfdd}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)NcsS)Nr)ar)rrrmemonsz6memoized_instancemethod..oneshot..memo)r r#r)rrrr)rE)rroneshotks   z(memoized_instancemethod..oneshot)r)rErr)rErmemoized_instancemethodbs rc@s2eZdZdZd ddZddZddZd d Zd S) !group_expirable_memoized_propertyz?A family of @memoized_properties that can be expired in tandem.rcCsg|_|r|j|dS)N) attributesr)rrrrrr|sz*group_expirable_memoized_property.__init__cCs&|j}x|jD]}||dqWdS)z.Expire all memoized properties for *instance*.N)rrr)rinstanceZstashZ attributerrrexpire_instances z1group_expirable_memoized_property.expire_instancecCs|j|jt|S)N)rr4r r)rrErrrrsz*group_expirable_memoized_property.__call__cCs|j|jt|S)N)rr4r r)rrErrrrsz(group_expirable_memoized_property.methodN)r)r r!r"r#rrrrrrrrrys  rc@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|dS)N)r~)rrrrr_fallback_getattrszMemoizedSlots._fallback_getattrcsdrtnptdrBtd}t||Stdrztdfdd}j|_|SSdS)NZ _memoizedz_memoized_attr_%sz_memoized_method_%scs6||fdd}j|_j|_t|S)NcsS)Nr)rr)rrrrsz8MemoizedSlots.__getattr__..oneshot..memo)r r#r)rrr)rErr)rrrs    z*MemoizedSlots.__getattr__..oneshot)rr~r3rUrr#r)rrrrr)rErrr __getattr__s    zMemoizedSlots.__getattr__N)r r!r"r#r$rrrrrrrsrcsfdd}|S)Ncsnd}td|ddtt|dg}t||d}t||j|rjt |drj|j |j|S)Nrbrrc__all__) rhrrxr*globalsrrUrr r3rr4)rtokensry) add_to_all modulenamerrr^s $z dependency_for..decorater)rrr^r)rrrdependency_fors rc@sFeZdZdZddZddZeddZeZ iZ Gdd d e Z d S) dependenciesaApply imported dependencies as arguments to a function. E.g.:: @util.dependencies( "sqlalchemy.sql.widget", "sqlalchemy.engine.default" ); def some_func(self, widget, default, arg1, arg2, **kw): # ... Rationale is so that the impact of a dependency cycle can be associated directly with the few functions that cause the cycle, and not pollute the module-level namespace. c GsHg|_x<|D]4}|d}|jtd|dd|dq WdS)Nrbrrc) import_depsrhr4r _importlaterr*)rZdepsZdeprrrrrs   zdependencies.__init__c Cs|j}t|}t|d}|ddk}x0tt|D] }d||d||rPdnd<q6Wt|dd}x|D]}||rzdnd=qlW||ddd<t|dd} d| d|d d } t| t} t |d |j | _ t | |S) Nr)rr-zimport_deps[%r]rF)rJz!lambda %(args)s: fn(%(apply_kw)s)rr)rrrL) rrrQrr?rrSevalrrUrVr) rrErrXZ spec_zeroZhasselfr8Z inner_specZimpnameZ outer_specr\r]rrrrs"        zdependencies.__call__cCs,x&ttjD]}|j|r |q WdS)N)rr _unresolved _full_pathr_resolve)r-pathr rrr resolve_alls zdependencies.resolve_allc@sNeZdZeZiZddZddZeddZ e ddZ d d Z d d Z d S)zdependencies._importlatercCs<|d|}|tjkr tj|St|tj|<}|SdS)Nrb)r_by_keyr__new__)r-raddtlrZimprrrr s    z!dependencies._importlater.__new__cCs||_||_tj|dS)N)_il_path _il_addtlrrr@)rrr rrrrsz"dependencies._importlater.__init__cCs|jd|jS)Nrb)r r )rrrrrsz$dependencies._importlater._full_pathcCs,|tjkrtd|j|jft|j|jS)Nz.bool_or_valuer)rrr)rr bool_or_strHs rcCs|dkr |St|S)zCoerce to integer.N)int)rrrrasintWsrcCs^||krZt|tr t|||sZ||dk rZ|tkrJ|rJt||||<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)rfrgrr)rrrZ flexi_boolrrrcoerce_kw_type_s   rcs0t|}|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|fVqdS)N)r)r'k)rrrr)ysz#constructor_copy..)rr difference)rr-rrrYr)rrconstructor_copypsr"cs&tjtdfdd}|S)z%Return a threadsafe counter function.rcs ztSXdS)N)acquirenextreleaser)counterlockrr_nextszcounter.._next)r threadingLockr=count)r(r)r&r'rr&~s  r&cCst|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__Nr4r@r<)r3r, issubclassr<rfrgrrR)ZspecimenrZisarrrduck_type_collections&         r.cCs^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'rrrrr)sz"assert_arg_type..z6Argument '%s' is expected to be of type '%s', got '%s')rfr5rZ ArgumentErrorr*rg)rZargtyperKrrrassert_arg_types  $r/cstjrtdrFtSn(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$xD]}||fVq WdS)N)r2)r)dictlikegetterrriteratorsz$dictlike_iteritems..iteratorrc3s|]}||fVqdS)Nr)r'r)r4rrr)sz%dictlike_iteritems..) rrr3rrr0iterrUrr)r3r5r)r3r4rrs        rcs(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|_dS)N)superr7rr#)rrrr)rrrrszclassproperty.__init__cCs ||S)N)r)Zdescrr-rrrrszclassproperty.__get__)r r!r"r#rr __classcell__rr)rrr7s  r7c@seZdZddZddZdS)hybridpropertycCs ||_dS)N)r)rrrrrrszhybridproperty.__init__cCs.|dkr ||}|jj|_|S||SdS)N)rr#)rrownerZclsvalrrrrs   zhybridproperty.__get__N)r r!r"rrrrrrr:sr:c@s eZdZdZddZddZdS) hybridmethodz/Decorate a function as cls- or instance- level.cCs ||_dS)N)r)rrrrrrszhybridmethod.__init__cCs*|dkr|j||jS|j||SdS)N)rrr)rrr;rrrrszhybridmethod.__get__N)r r!r"r#rrrrrrr<sr<c@s.eZdZd ddZddZddZdd ZdS) _symbolNcCs@t|tjst|dkr t|}tt|}||_|r<||_ |S)zConstruct a new named symbol.N) rfrrAssertionErrorhashrrr=rKr#)rrKrl canonicalvrrrr s z_symbol.__new__cCst|jdt|ffS)Nr )rdrKr)rrrr __reduce__sz_symbol.__reduce__cCst|S)N)r)rrrr__str__sz_symbol.__str__cCs d|jS)Nz symbol(%r))rK)rrrr__repr__sz_symbol.__repr__)NN)r r!r"rrBrCrDrrrrr= s r=rdc@s(eZdZdZiZejZdddZ dS)rdaA 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. NcCsJ|jz.|j|}|dkr6t||||j|<}|StjXdS)N)_lockr#symbolsrr=rdr%)r-rKrlr@rCrrrr<s  zsymbol.__new__)NN) r r!r"r#rFrr)r*rErrrrrrd#s 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_orderJs rHcOs<y |||Stk r6tdtddYnXdS)zXexecutes the given function, catches all exceptions and converts to a warning. z%s('%s') ignoredrrN)rPrrr)rrrrrrwarn_exceptionWs rIcCs>y$t||krd|d|S|SWntk r8|SXdS)Nz%s...r)rr)rZlen_rrrellipses_stringbs  rKcs0eZdZdZfddZddZddZZS)_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)r8rLrr?_hash)r-rnumrZ interpolatedr)rrrrws  z_hash_limit_string.__new__cCs|jS)N)rM)rrrr__hash__sz_hash_limit_string.__hash__cCst|t|kS)N)r?)rotherrrr__eq__sz_hash_limit_string.__eq__)r r!r"r#rrOrQr9rr)rrrLls  rLcCstj|tjdddS)zdIssue a warning. If msg is a string, :class:`.exc.SAWarning` is used as the category. r) stacklevelN)warningsrr SAWarning)msgrrrrsrcCs&|rt|d|}tj|tjdddS)z\Issue a warning with a parameterized string, limiting the number of registrations. r)rRN)rLrSrrrT)rUrrrr warn_limiteds rWcs|gfdd}|S)zNDecorate the given function to be a no-op after it is called exactly once.csr}|||SdS)N)r)rrZonce_fn)oncerrgoszonly_once..gor)rErYr)rXr only_onces rZz%sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.pyzunit(?:2|test2?/)cCshd}t|d}x"||kr2|||r2|d7}qWx"||krV|||rV|d8}q6W|||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_suffixr0endrrrchop_tracebacks    r^cCs$d|}t}t|||dS)Nz&def set(obj, value): obj.%s = valuer<)rcopyr`)Zattrnamer\rarrr attrsetters  r`cs(eZdZdZfddZddZZS)EnsureKWArgTypezYApply translation of functions to accept \**kw arguments if they don't already. c sv|j}|r^xR|D]J}t||}|r||}t|}|js||||<} t||| qWtt | |||dS)N) Z ensure_kwargr+matchrrQr _wrap_w_kwrr8rar) r-ZclsnamerBZclsdictZfn_regrr rErXwrapped)rrrrs   zEnsureKWArgType.__init__csfdd}t|S)Ncs|S)Nr)rr)rErrwrapsz(EnsureKWArgType._wrap_w_kw..wrap)r)rrErer)rErrcs zEnsureKWArgType._wrap_w_kw)r r!r"r#rrcr9rr)rrras racCsjt|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)r3rrr r!rr#)wrapperrEZ_frrr wrap_callables     rgcCsd|kr|dSd}gg}d}t|}x||kr||}|dkr|dkr~||dkr~||ddkr~|dd|d7}q|dN}n*|dkr|dkr|gn|d||d7}q*Wdd|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'] "rbrrrccSsg|]}d|qS))r*)r'rzrrrr'sz'quoted_token_parser..)rhrr4)rrridxZlvcharrrrquoted_token_parsers$  $    rlcstfdd}|S)Ncs:|jdk r|jpd}|r0t|fddD}||_|S)Nricsi|] }|qSrr)r'param)rrr 0sz8add_parameter_text..decorate..)r#inject_param_text)rErl)paramsrrrr^-s z$add_parameter_text..decorate)rr)rprr^r)rprradd_parameter_text*s rqcCsN|dd}t|dkr|S|\}}|ds@|dt|St|SdS)N rr%)rhrrtextwrapdedent)rZ split_text firstlineZ remainingrrr_dedent_docstring7s   rvcCst|pd}|d}t|d}|dr:|ddddt|D}|dd|t|t|d}|d||||d}d|S)NrirrrcSsg|]\}}|s|qSr)r)r'rNlinerrrrJsz)inject_docstring_text..r) rvrhrsrtinsertrminrr*)doctextZ injecttextposlinesZ injectlinesZblanksZ inject_posrrrinject_docstring_textCs    r}c Cs:|}g}d}x|r.|d}|dkrtd|}|r|d}||krdt|dd}|rtd|d} | rdt| d}|||}n|dr|d|||dd}nT| s|||||dd}n(| d r"||||dq||qWd |S) Nrz(\s+):param (?:\\\*\*?)?(.+?):rr%rz(\s+)\Sz:param rrz::) splitlinesrr+rbrorlstriprr4rstriprr*) rzZ inject_paramsZdoclinesr|Z to_injectrwr rmindentZm2rrrroSsB             ro)N)FF)T)T)rNr)NNrN)NNN)F)T)N)rJ)Xr# functoolsrr rMr=rr+rrsrrSrirrrrrrr.r6rDrGr_rTrmrnrrrrrSrrrrrrrrrrrrrrrrrrrrr"r&r.r/rrr7r:r<rr=r rdrGrHrIrKZ text_typerLrrWrZcompileZ_SQLA_REZ _UNITTEST_REr^rgZNoneTyper`rargrlrqrvr}rorrrr s    . 0* + 6 S  H3 9 V( u   !  $      ,