o ?Og @sdZdZddlZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlmZddlmZmZeZejD] \ZZeede<q^dZdddd d d Z d d Z!ddZ"ddZ#ddZ$ddZ%e&edrddZ'nddZ'e&edrddZ(nddZ(ddZ)d d!Z*d"d#Z+d$d%Z,d&d'Z-d(d)Z.d*d+Z/d,d-Z0d.d/Z1d0d1Z2d2d3Z3d4d5Z4d6d7Z5d8d9Z6d:d;Z7ddd?Z9d@dAZ:dBdCZ;ddDdEdFZdKdLZ?dMdNZ@dOdPZAdQdRZBdSdTZCdUdVZDddWdXZEiZFiZGddYdZZHGd[d\d\eIZJGd]d^d^ejKZLd_d`ZMdadbZNGdcddddeIZOGdedfdfZPdgdhZQdidjZRdkdlZSdmdnZTddodpZUedqdrZVdsdtZWedudvZXdwdxZYedydzZZd{d|Z[ed}d~Z\ddZ]dddZ^ddZ_ddddiie`dddddddde^f ddZae`ddddddfddZbddZcddZdddZeeddZfddZgeddZhdddZiddZjeddehjkZldddZmdddZnddZodddZpdddZqerZsddZtddZuddZvddZwddZxesfddZydZzdZ{dZ|dZ}ddZ~dd„ZdZdZdZdZddȄZddʄZeejZeejZeejdZeeeejfZdd̈́ZdddτZddфZddӄZddՄZddׄZddلZddd܄ZdddބZ dddZddddddddZGdddZGdddZGdddejZejZejZejZejZejZededededediZGdddZGdddZGdddZdddddddZddZedkredSdS(aFGet useful information from live Python objects. This module encapsulates the interface provided by the internal special attributes (co_*, im_*, tb_*, etc.) in a friendlier fashion. It also provides some help for examining source code and class layout. Here are some of the useful functions provided by this module: ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(), isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(), isroutine() - check object types getmembers() - get members of an object that satisfy a given condition getfile(), getsourcefile(), getsource() - find an object's source code getdoc(), getcomments() - get documentation on an object getmodule() - determine the module that an object came from getclasstree() - arrange classes so as to represent their hierarchy getargvalues(), getcallargs() - get info about function arguments getfullargspec() - same, with support for Python 3 features formatargvalues() - format an argument spec getouterframes(), getinnerframes() - get info about frames currentframe() - get the current stack frame stack(), trace() - get info about frames on the stack or in a traceback signature() - get a Signature object for the callable get_annotations() - safely compute an object's annotations )zKa-Ping Yee z'Yury Selivanov N) attrgetter) namedtuple OrderedDictZCO_iFglobalslocalseval_strc st|trEt|dd}|r!t|dr!|dd}t|tjr d}nd}d}t|dd}|rs z#get_annotations..)rtypegetattrhasattrr typesGetSetDescriptorTypesysmodulesdictvars ModuleTypecallable TypeError ValueErrorr functoolspartialfuncr items) objrrrZobj_dictannZ obj_globals module_namemoduleZ obj_localsunwrapZ return_valuerrrget_annotationsBsl -                r/cC t|tjS)zReturn true if the object is a module. Module objects provide these attributes: __cached__ pathname to byte compiled file __doc__ documentation string __file__ filename (missing for built-in modules))rrr"objectrrrismodule r3cC t|tS)zReturn true if the object is a class. Class objects provide these attributes: __doc__ documentation string __module__ name of module in which this class was defined)rrr1rrrisclass r6cCr0)a_Return true if the object is an instance method. Instance method objects provide these attributes: __doc__ documentation string __name__ name with which this method was defined __func__ function object containing implementation of method __self__ instance to which this method is bound)rr MethodTyper1rrrismethod r9cCs:t|s t|s t|rdSt|}t|dot|d S)aReturn true if the object is a method descriptor. But not if ismethod() or isclass() or isfunction() are true. This is new in Python 2.2, and, for example, is true of int.__add__. An object passing this test has a __get__ attribute but not a __set__ attribute, but beyond that the set of attributes varies. __name__ is usually sensible, and __doc__ often is. Methods implemented via descriptors that also pass one of the other tests return false from the ismethoddescriptor() test, simply because the other tests promise more -- you can, e.g., count on having the __func__ attribute (etc) when an object passes ismethod().F__get____set__r6r9 isfunctionrrr2tprrrismethoddescriptorsrAcCs8t|s t|s t|rdSt|}t|dpt|dS)a}Return true if the object is a data descriptor. Data descriptors have a __set__ or a __delete__ attribute. Examples are properties (defined in Python) and getsets and members (defined in C). Typically, data descriptors will also have __name__ and __doc__ attributes (properties, getsets, and members have both of these attributes), but this is not guaranteed.Fr< __delete__r=r?rrrisdatadescriptorsrCMemberDescriptorTypecCr0)Return true if the object is a member descriptor. Member descriptors are specialized descriptors defined in extension modules.)rrrDr1rrrismemberdescriptor rFcCdS)rEFrr1rrrrFrcCr0)Return true if the object is a getset descriptor. getset descriptors are specialized descriptors defined in extension modules.)rrrr1rrrisgetsetdescriptorrGrKcCrH)rJFrr1rrrrKrIcCr0)a(Return true if the object is a user-defined function. Function objects provide these attributes: __doc__ documentation string __name__ name with which this function was defined __code__ code object containing compiled function bytecode __defaults__ tuple of any default values for arguments __globals__ global namespace in which this function was defined __annotations__ dict of parameter annotations __kwdefaults__ dict of keyword only parameters with defaults)rr FunctionTyper1rrrr>s r>cCsDt|r |j}t|st|}t|st|sdSt|jj|@S)zReturn true if ``f`` is a function (or a method or functools.partial wrapper wrapping a function) whose code object has the given ``flag`` set in its flags.F) r9__func__r&_unwrap_partialr>_signature_is_functionlikebool__code__co_flags)fflagrrr_has_code_flag"s rUcCr5)zReturn true if the object is a user-defined generator function. Generator function objects provide the same attributes as functions. See help(isfunction) for a list of attributes.)rUZ CO_GENERATORr*rrrisgeneratorfunction- rWcCr5)zuReturn true if the object is a coroutine function. Coroutine functions are defined with "async def" syntax. )rUZ CO_COROUTINErVrrriscoroutinefunction4rXrYcCr5)zReturn true if the object is an asynchronous generator function. Asynchronous generator functions are defined with "async def" syntax and have "yield" expressions in their body. )rUZCO_ASYNC_GENERATORrVrrrisasyncgenfunction;r7rZcCr0)z7Return true if the object is an asynchronous generator.)rrAsyncGeneratorTyper1rrr isasyncgenC r\cCr0)aReturn true if the object is a generator. Generator objects provide these attributes: __iter__ defined to support iteration over container close raises a new GeneratorExit exception inside the generator to terminate the iteration gi_code code object gi_frame frame object or possibly None once the generator has been exhausted gi_running set to 1 when generator is executing, 0 otherwise next return the next item from the container send resumes the generator and "sends" a value that becomes the result of the current yield-expression throw used to raise an exception inside the generator)rr GeneratorTyper1rrr isgeneratorGs r_cCr0)z)Return true if the object is a coroutine.)rr CoroutineTyper1rrr iscoroutineXr]racCs6t|tjpt|tjot|jjt@pt|tj j S)z?Return true if object can be passed to an ``await`` expression.) rrr`r^rPgi_coderRZCO_ITERABLE_COROUTINE collectionsabc Awaitabler1rrr isawaitable\s   rfcCr0)abReturn true if the object is a traceback. Traceback objects provide these attributes: tb_frame frame object at this level tb_lasti index of last attempted instruction in bytecode tb_lineno current line number in Python source code tb_next next inner traceback object (called by this level))rr TracebackTyper1rrr istracebackcr:rhcCr0)a`Return true if the object is a frame object. Frame objects provide these attributes: f_back next outer frame object (this frame's caller) f_builtins built-in namespace seen by this frame f_code code object being executed in this frame f_globals global namespace seen by this frame f_lasti index of last attempted instruction in bytecode f_lineno current line number in Python source code f_locals local namespace seen by this frame f_trace tracing function for this frame, or None)rr FrameTyper1rrrisframems rjcCr0)aReturn true if the object is a code object. Code objects provide these attributes: co_argcount number of arguments (not including *, ** args or keyword only arguments) co_code string of raw compiled bytecode co_cellvars tuple of names of cell variables co_consts tuple of constants used in the bytecode co_filename name of file in which this code object was created co_firstlineno number of first line in Python source code co_flags bitmap: 1=optimized | 2=newlocals | 4=*arg | 8=**arg | 16=nested | 32=generator | 64=nofree | 128=coroutine | 256=iterable_coroutine | 512=async_generator co_freevars tuple of names of free variables co_posonlyargcount number of positional only arguments co_kwonlyargcount number of keyword only arguments (not including ** arg) co_lnotab encoded mapping of line numbers to bytecode indices co_name name with which this code object was defined co_names tuple of names other than arguments and function locals co_nlocals number of local variables co_stacksize virtual machine stack space required co_varnames tuple of names of arguments and local variables)rrCodeTyper1rrriscode{s rlcCr0)a,Return true if the object is a built-in function or method. Built-in functions and methods provide these attributes: __doc__ documentation string __name__ original name of this function or method __self__ instance to which a method is bound, or None)rrBuiltinFunctionTyper1rrr isbuiltinr4rncCs t|pt|pt|pt|S)zr9rAr1rrr isroutinesrocCst|tsdS|jt@rdStt|tjsdSt|drdS|j D] \}}t |ddr1dSq$|j D]}t |ddD]}t ||d}t |ddrOdSq=q5dS)z:Return true if the object is an abstract base class (ABC).FT__abstractmethods____isabstractmethod__rN) rr __flags__TPFLAGS_IS_ABSTRACT issubclassrdABCMetarr r)r __bases__)r2namerbaserrr isabstracts(       ryc Cst|r |ft|}nd}g}t}t|}z|jD]}|jD]\}}t|tj r1| |q"qWn t y=Ynw|D]>} z t || } | |vrNt Wnt yk|D]}| |jvrf|j| } nqXYq@Ynw|rr|| ry| | | f| | q@|jddd|S)zReturn all members of an object as (name, value) pairs sorted by name. Optionally, only return members that satisfy a given predicate.rcSs|dS)Nrr)Zpairrrrzgetmembers..r)r6getmrosetdirrvr r)rrDynamicClassAttributeappendAttributeErrorraddsort) r2Z predicatemroresults processednamesrxkvrrrrr getmemberssJ          r Attributezname kind defining_class objectc Cs4t|}tt|}tdd|D}|f|}||}t|}|D]}|jD]\}}t|tjr=|j dur=| |q)q"g} t } |D]} d} d} d}| | vrz| dkr[t dt || } Wnt ys}zWYd}~nGd}~wwt | d| } | |vrd} d}|D]}t || d}|| ur|}q|D]}z||| }Wn tyYqw|| ur|}q|dur|} |D]}| |jvr|j| }| |vr|} nq| durqF| dur| n|}t|ttjfrd}|}n!t|ttjfrd}|}nt|trd }|}n t|rd }nd }| t| || || | qF| S) aNReturn list of attribute-descriptor tuples. For each name in dir(cls), the return list contains a 4-tuple with these elements: 0. The name (a string). 1. The kind of attribute this is, one of these strings: 'class method' created via classmethod() 'static method' created via staticmethod() 'property' created via property() 'method' any other flavor of method or descriptor 'data' not a method 2. The class which defined this attribute (a class). 3. The object as obtained by calling getattr; if this fails, or if the resulting object does not live anywhere in the class' mro (including metaclasses) then the object is looked up in the defining class's dict (found by walking the mro). If one of the items in dir(cls) is stored in the metaclass it will now be discovered and not have None be listed as the class in which it was defined. Any items whose home class cannot be discovered are skipped. css |] }|ttfvr|VqdSN)rr2)rclsrrr sz'classify_class_attrs..Nr z)__dict__ is special, don't want the proxy __objclass__z static methodz class methodpropertymethoddata)r}rtuplerr r)rrrfgetrr~ Exceptionr __getattr__r staticmethodBuiltinMethodType classmethodClassMethodDescriptorTyperrorr)rrZmetamroZ class_basesZ all_basesrrxrrresultrrwZhomeclsZget_objZdict_objexcZlast_clsZsrch_clsZsrch_objr*kindrrrclassify_class_attrss             rcC|jS)zHReturn tuple of base classes (including cls) in method resolution order.)__mro__)rrrrr}^r}stopcsdur dd}nfdd}|}t||i}t}||r?|j}t|}||vs0t||kr7td||||<||s|S)anGet the object wrapped by *func*. Follows the chain of :attr:`__wrapped__` attributes returning the last object in the chain. *stop* is an optional callback accepting an object in the wrapper chain as its sole argument that allows the unwrapping to be terminated early if the callback returns a true value. If the callback never returns a true value, the last object in the chain is returned as usual. For example, :func:`signature` uses this to stop unwrapping if any object in the chain has a ``__signature__`` attribute defined. :exc:`ValueError` is raised if a cycle is encountered. NcSs t|dSNrrrSrrr _is_wrapperu zunwrap.._is_wrappercst|do | Srrrrrrrxsz!wrapper loop when unwrapping {!r})idrgetrecursionlimitrlenr%format)r(rrrSZmemoZrecursion_limitZid_funcrrrr.ds   r.cCs|}t|t|S)zBReturn the indent size, in spaces, at the start of a line of text.) expandtabsrlstrip)lineZexplinerrr indentsizesrcCsNtj|j}|dur dS|jdddD]}t||}qt|s%dS|S)N.)rrr r __qualname__splitrr6)r(rrwrrr _findclasss rc Cst|r'|jD]}|tur$z|j}Wn tyYqw|dur$|SqdSt|rI|jj}|j}t|rEt t ||dd|jurE|}n|j }nt |rb|j}t |}|dus_t |||uradSnmt |r|j}|j}t|r}|jd||jkr}|}nR|j }nNt|tr|j}|j}t |}|dust |||urdSn1t|st|r|j}|j}t |||urdSt|rt |dd}t|tr||vr||SndS|jD]}zt ||j}Wn tyYqw|dur|SqdS)NrMr __slots__)r6rr2__doc__rr9rM__name____self__r __class__r>rrnrrrrrArCrrFr )r*rxdocrwselfrr(slotsrrr_finddocsx       rc Csdz|j}Wn tyYdSw|dur'zt|}Wn ttfy&YdSwt|ts.dSt|S)zGet the documentation string for an object. All tabs are expanded to spaces. To clean up docstrings that are indented to line up with blocks of code, any whitespace than can be uniformly removed from the second line onwards is removed.N)rrrr$rrcleandoc)r2rrrrgetdocs    rcCsz |d}Wn tyYdSwtj}|ddD]}t|}|r2t||}t||}q|r=|d|d<|tjkrVtdt|D] }|||d||<qI|rf|dsf| |rf|dr\|rw|dsw| d|rw|drld |S)zClean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed. Nrr) rr UnicodeErrorrmaxsizerrminrangepopjoin)rlinesZmarginrZcontentindentirrrrs.     (    rcCst|rt|ddr |jStd|t|r=t|dr6tj |j }t|ddr-|jS|j dkr6t dtd|t |rD|j }t|rK|j}t|rR|j}t|rY|j}t|r`|jStdt|j) z@Work out which source or compiled file an object was defined in.__file__Nz{!r} is a built-in moduler __main__source code not availablez{!r} is a built-in classzVmodule, class, method, function, traceback, frame, or code object was expected, got {})r3rrr$rr6rrrr r OSErrorr9rMr>rQrhtb_framerjf_coderl co_filenamerr)r2r-rrrgetfiles6    rcCsTtj|}ddtjD}||D]\}}||r'|d|SqdS)z1Return the module name for a given file, or None.cSsg|] }t| |fqSr)r)rsuffixrrr %sz!getmodulename..N)ospathbasename importlib machinery all_suffixesrendswith)rZfnamesuffixesZneglenrrrr getmodulename!s   rcst|tjjdd}|tjjdd7}tfdd|Dr0tjdtjj dntfddtjj Dr?dStj rGSt |}t |dddurVSt t |dddddurdStjvrkSdS) zReturn the filename that can be used to locate an object's source. Return None if no way can be identified to get the source. Nc3|]}|VqdSrrrsfilenamerrr4z getsourcefile..rc3rrrrrrrr7r __loader____spec__loader)rrrDEBUG_BYTECODE_SUFFIXESOPTIMIZED_BYTECODE_SUFFIXESanyrrsplitextSOURCE_SUFFIXESEXTENSION_SUFFIXESexists getmoduler linecachecache)r2Zall_bytecode_suffixesr-rrr getsourcefile-s*     rcCs,|dur t|p t|}tjtj|S)zReturn an absolute path to the source or compiled file for an object. The idea is for each object to have a unique origin, so this routine normalizes the result as much as possible.N)rrrrnormcaseabspath)r2 _filenamerrr getabsfileFsrc Cszt|r|St|drtj|jS|dur"|tvr"tjt|Szt||}Wn tt fy5YdSw|tvrBtjt|Stj D].\}}t|rwt|drw|j }|t |dkrbqI|t |<t|}|jt|<ttj|<qI|tvrtjt|Stjd}t|dsdSt||jrt||j}||ur|Stjd}t||jrt||j} | |ur|SdSdS)zAReturn the module an object was defined in, or None if not found.r Nrrrbuiltins)r3rrrr r modulesbyfilerr$FileNotFoundErrorcopyr)r_filesbymodnamerrrrealpathr) r2rfilemodnamer-rSmainZ mainobjectZbuiltinZ builtinobjectrrrrRsR         rc@ eZdZdS)ClassFoundExceptionNrr rrrrrrsrc@s(eZdZddZddZeZddZdS) _ClassFindercCsg|_||_dSr)stackqualname)rrrrr__init__ z_ClassFinder.__init__cCs<|j|j|jd|||j|jdS)Nz)rrrw generic_visitrrnoderrrvisit_FunctionDefs    z_ClassFinder.visit_FunctionDefcCsb|j|j|jd|jkr%|jr|jdj}n|j}|d8}t||||j dS)Nrrr) rrrwrrdecorator_listlinenorr r)rr  line_numberrrrvisit_ClassDefs z_ClassFinder.visit_ClassDefN)rr rrr Zvisit_AsyncFunctionDefrrrrrrs  rc Cst|}|r t|nt|}|dr|dstdt||}|r-t||j }nt|}|s8tdt |r@|dfSt |r{|j }d |}t|}t|}z ||Wtdtyz}z|jd} || fWYd}~Sd}~wwt|r|j}t|r|j}t|r|j}t|r|j}t|rt|d std |jd } t d } | dkrz|| } Wn t!ytd w| "| r || fS| d } | dks|| fStd)abReturn the entire source file and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of all the lines in the file and the line number indexes a line in that list. An OSError is raised if the source code cannot be retrieved.<>rzcould not get source coderNzcould not find class definitionco_firstlinenoz"could not find function definitionrz>^(\s*def\s)|(\s*async\s+def\s)|(.*(?rQrhrrjrrlrrrecompile IndexErrormatch) r2rr-rrsourceZtreeZ class_findererlnumZpatrrrr findsourcesj             r$c Cszt|\}}Wn ttfyYdSwt|rd}|r)|ddddkr)d}|t|krI||dvrI|d}|t|krI||dvs7|t|kr||dddkrg}|}|t|kr||dddkr||||d}|t|kr||dddksmd|SdSdS|dkrSt ||}|d}|dkrU|| dddkrWt |||krY|| g}|dkr|d}|| }|dddkrt |||kr|g|dd<|d}|dkrn|| }|dddkrt |||ks|r0|ddkr0g|dd<|r0|ddks|rN|d dkrNg|d d<|rN|d dksrNr) r.r$rhrr3rjrco_namerFr2rr#rrrgetsourcelinesXs  rIcCst|\}}d|S)aReturn the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An OSError is raised if the source code cannot be retrieved.r)rIrrHrrr getsourcems  rJcCsRg}|jtddd|D]}|||jf||vr&|t||||q |S)z-Recursive helper function for getclasstree().r rr|)rrrrvwalktree)classeschildrenparentrcrrrrKwsrKcCsi}g}|D]2}|jr/|jD]}||vrg||<|||vr%||||r-||vr-nqq||vr8||q|D] }||vrF||q;t||dS)aArrange the given list of classes into a hierarchy of nested lists. Where a nested list appears, it contains classes derived from the class whose entry immediately precedes the list. Each entry is a 2-tuple containing a class and a tuple of its base classes. If the 'unique' argument is true, exactly one entry appears in the returned structure for each class in the given list. Otherwise, classes using multiple inheritance and their descendants will appear multiple times.N)rvrrK)rLuniquerMrootsrOrNrrr getclasstrees&      rR Argumentszargs, varargs, varkwc Cst|s td||j}|j}|j}t|d|}t||||}d}||7}d}|jt@r<|j|}|d}d}|jt @rH|j|}t ||||S)aGet information about the arguments accepted by a code object. Three things are returned: (args, varargs, varkw), where 'args' is the list of argument names. Keyword-only arguments are appended. 'varargs' and 'varkw' are the names of the * and ** arguments or None.z{!r} is not a code objectNrr) rlr$r co_varnames co_argcountco_kwonlyargcountlistrR CO_VARARGSCO_VARKEYWORDSrS) cornargsZnkwargsr kwonlyargsstepvarargsvarkwrrrgetargss"    r`ArgSpeczargs varargs keywords defaultscCsDtjdtddt|\}}}}}}}|s|rtdt||||S)aeGet the names and default values of a function's parameters. A tuple of four things is returned: (args, varargs, keywords, defaults). 'args' is a list of the argument names, including keyword-only argument names. 'varargs' and 'keywords' are the names of the * and ** parameters or None. 'defaults' is an n-tuple of the default values of the last n parameters. This function is deprecated, as it does not support annotations or keyword-only parameters and will raise ValueError if either is present on the supplied callable. For a more structured introspection API, use inspect.signature() instead. Alternatively, use getfullargspec() for an API with a similar namedtuple based interface, but full support for annotations and keyword-only parameters. Deprecated since Python 3.5, use `inspect.getfullargspec()`. zhinspect.getargspec() is deprecated since Python 3.0, use inspect.signature() or inspect.getfullargspec()r% stacklevelzgFunction has keyword-only parameters or annotations, use inspect.signature() API which can support them)warningswarnDeprecationWarninggetfullargspecr%ra)r(rr^r_defaultsr\kwonlydefaultsr+rrr getargspecsrj FullArgSpeczGargs, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotationsc Csfz t|ddtdd}Wnty}ztd|d}~wwg}d}d}g}g}i}d} i} |j|jur8|j|d<|jD]a} | j} | j } | t ur[| | | j | jurZ| | j f7} n8| t urq| | | j | jurp| | j f7} n"| turx| }n| tur| | | j | jur| j | | <n| tur| }| j| jur| j|| <q=| sd} | sd} t||||| || |S)a$Get the names and default values of a callable object's parameters. A tuple of seven things is returned: (args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations). 'args' is a list of the parameter names. 'varargs' and 'varkw' are the names of the * and ** parameters or None. 'defaults' is an n-tuple of the default values of the last n parameters. 'kwonlyargs' is a list of keyword-only parameter names. 'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults. 'annotations' is a dictionary mapping parameter names to annotations. Notable differences from inspect.signature(): - the "self" parameter is always reported, even for bound methods - wrapper chains defined by __wrapped__ *not* unwrapped automatically F)follow_wrapper_chainsskip_bound_argsigclsrzunsupported callableNrreturn)_signature_from_callable Signaturerr$return_annotationempty parametersvaluesrrw_POSITIONAL_ONLYrdefault_POSITIONAL_OR_KEYWORD_VAR_POSITIONAL _KEYWORD_ONLY _VAR_KEYWORD annotationrk)r(sigexrr^r_ posonlyargsr\ annotationsrh kwdefaultsparamrrwrrrrgsj               rgArgInfozargs varargs keywords localscCs t|j\}}}t||||jS)a9Get information about arguments passed into a particular frame. A tuple of four things is returned: (args, varargs, varkw, locals). 'args' is a list of the argument names. 'varargs' and 'varkw' are the names of the * and ** arguments or None. 'locals' is the locals dictionary of the given frame.)r`rrf_locals)framerr^r_rrr getargvalues;srcCstt|dddkrdd}td|t|St|tjrt|St|tr6|j d|fvr.|j S|j d|j St|S)Nr typingcSs|}|dS)Nztyping.)group removeprefix)r textrrrreplGs zformatannotation..replz[\w\.]+rr) rrsubreprrr GenericAliasrrr r)r|Z base_modulerrrrformatannotationEs  rcst|ddfdd}|S)Nr cs t|Sr)r)r|r-rr_formatannotationUrz5formatannotationrelativeto.._formatannotation)r)r2rrrrformatannotationrelativetoSs  rrcCd|SN*rrwrrrrz\r{rzcCrN**rrrrrrz]r{cC dt|SN=rrrrrrz^r,cCr)Nz -> r)rrrrrz_r{c s8ddlm} | dtddfdd}g}|r!t|t|}t|D]\}}||}|r=||kr=|| |||}||q%|durQ||||n|rX|d |rv|D]}||}|rp||vrp|| ||7}||q\|dur|| ||d d |d }d vr|| d 7}|S)aFormat an argument spec from the values returned by getfullargspec. The first seven arguments are (args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations). The other five arguments are the corresponding optional formatting functions that are called to turn names and values into strings. The last argument is an optional function to format the sequence of arguments. Deprecated since Python 3.5: use the `signature` function and `Signature` objects. r)rezc`formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directlyr%rbcs(|}|vr|d|7}|S)Nz: r)argrrr formatargrrformatargandannotationtsz-formatargspec..formatargandannotationNr(, )ro)rdrerfr enumeraterr)rr^r_rhr\rirr formatvarargs formatvarkw formatvalueZ formatreturnsrrerspecsZ firstdefaultrrspecZ kwonlyargrrrr formatargspecYs<      rcCrrrrrrrrzr{cCrrrrrrrrzr{cCrrrrrrrrzr,c Cs|||fdd}g} tt|D] } | ||| q|r+| ||||||r:| |||||dd| dS)afFormat an argument spec from the 4 values returned by getargvalues. The first four arguments are (args, varargs, varkw, locals). The next four arguments are the corresponding optional formatting functions that are called to turn names and values into strings. The ninth argument is an optional function to format the sequence of arguments.cSs|||||Srr)rwrrrrrrconvertsz formatargvalues..convertrrr)rrrr) rr^r_rrrrrrrrrrrformatargvaluess  rcsfdd|D}t|}|dkr|d}n|dkr dj|}ndj|dd}|dd=d ||}td |||r=d nd |dkrDd nd|f)Ncsg|] }|vrt|qSrr)rrwrurrrsz&_missing_arguments..rrr%z {} and {}z , {} and {}rz*%s() missing %i required %s argument%s: %s positional keyword-onlyrr)rrrr$)f_nameZargnamesposrurmissingrtailrrr_missing_argumentss    rc st||}tfdd|D}|r|dk} d|f} n|r*d} d|t|f} n t|dk} tt|} d} |rOd} | |dkrCd nd||dkrKd ndf} td || | rWd nd|| |dkre|sed fd f) Ncsg|]}|vr|qSrr)rrrrrrsz_too_many..rz at least %dTz from %d to %drz7 positional argument%s (and %d keyword-only argument%s)rz5%s() takes %s positional argument%s but %d%s %s givenZwasZwere)rrr$) rrZkwonlyr^ZdefcountZgivenruZatleastZ kwonly_givenZpluralr}Z kwonly_sigmsgrrr _too_manys0    rcOst|}|\}}}}}} } |j} i} t|r!|jdur!|jf|}t|} t|}|r/t|nd}t| |}t|D] }||| ||<q:|rQt||d| |<t||}|r]i| |<| D])\}}||vrz|sst d| |f|| ||<qa|| vrt d| |f|| |<qa| |kr|st | ||||| | | |kr|d||}|D] }|| vrt | |d| qt |||dD]\}}|| vr||| |<qd}|D]}|| vr| r|| vr| || |<q|d7}q|rt | |d| | S)zGet the mapping of arguments to values. A dict is returned, with keys the function argument names (including the names of the * and ** arguments, if any), and values the respective bound values from 'positional' and 'named'.Nrz*%s() got an unexpected keyword argument %rz(%s() got multiple values for argument %rTrF)rgrr9rrrrrr~r)r$rrr)r(rZnamedrrr^r_rhr\rir+rZ arg2valueZnum_posZnum_argsZ num_defaultsnrZpossible_kwargskwrZreqrrkwargrrr getcallargssl          r ClosureVarsz"nonlocals globals builtins unboundc Cst|r|j}t|std||j}|jduri}n ddt|j|jD}|j }| dt j }t |r:|j }i}i}t}|jD]/}|dvrKqDz||||<WqDtysz||||<Wntyp||YnwYqDwt||||S)a Get the mapping of free variables to their current values. Returns a named tuple of dicts mapping the current nonlocal, global and builtin references as seen by the body of the function. A final set of unbound names that could not be resolved is also provided. {!r} is not a Python functionNcSsi|]\}}||jqSr) cell_contents)rvarZcellrrrr"sz"getclosurevars.. __builtins__)NoneTrueFalse)r9rMr>r$rrQ __closure__zip co_freevarsr r rr r3r~co_namesKeyErrorrr) r(codeZ nonlocal_varsZ global_nsZ builtin_nsZ global_varsZ builtin_varsZ unbound_namesrwrrrgetclosurevars sB      r Tracebackz+filename lineno function code_context indexrcCst|r |j}|j}n|j}t|std|t|p t|}|dkr^|d|d}zt |\}}Wn t yBd}}Yn wt dt |t ||}||||}|d|}nd}}t|||jj||S)aGet information about a frame or traceback object. A tuple of five things is returned: the filename, the line number of the current line, the function name, a list of lines of context from the source code, and the index of the current line within that list. The optional second argument specifies the number of lines of context to return, which are centered around the current line.z'{!r} is not a frame or traceback objectrrr%N)rh tb_linenorf_linenorjr$rrrr$rmaxrrrrrG)rcontextrrr(rr#indexrrr getframeinfoDs&  rcCr)zCGet the line number from a frame object, allowing for optimization.)rrrrr getlinenodsr FrameInforcCs4g}|r|ft||}|t||j}|s|S)zGet a list of records for a frame and all higher (calling) frames. Each record contains a frame object, filename, line number, function name, a list of lines of context, and index within the context.)rrrf_back)rr framelist frameinforrrgetouterframesksrcCs6g}|r|jft||}|t||j}|s|S)zGet a list of records for a traceback's frame and all lower frames. Each record contains a frame object, filename, line number, function name, a list of lines of context, and index within the context.)rrrrtb_next)tbrrrrrrgetinnerframeswsrcCsttdr tdSdS)z?Return the frame of the caller or None if this is not possible. _getframerN)rrrrrrr currentframesrcCsttd|S)z@Return a list of records for the stack above the caller's frame.r)rrrrrrrrsrcCsttd|S)zCReturn a list of records for the stack below the current exception.r%)rrexc_inforrrrtracesrcCstjd|S)Nr)rr r;)klassrrr_static_getmrorcCs6i}zt|d}Wn tyYnwt||tSNr )r2__getattribute__rr r _sentinel)r*attrZ instance_dictrrr_check_instances rc CsFt|D]}tt|tur z|j|WStyYqwqtSr)r_shadowed_dictrrr r)rrentryrrr _check_classs  rcCs$zt|WdStyYdSwNFT)rr$rVrrr_is_types   rc Csltjd}t|D]*}z ||d}Wn tyYq wt|tjur/|jdkr/|j|us3|Sq t Sr) rr rr;rrrrrr)r dict_attrrZ class_dictrrrrs     rc Cst}t|st|}t|}|tust|tjurt||}n|}t||}|turB|turBtt|dturBtt|dturB|S|turH|S|turN|S||urutt|D]}tt|turtz|j |WSt ysYqXwqX|tur{|St |)aRetrieve attributes without triggering dynamic lookup via the descriptor protocol, __getattr__ or __getattribute__. Note: this function may not be able to retrieve all attributes that getattr can fetch (like dynamically created attributes) and may find attributes that getattr can't (like descriptors that raise AttributeError). It can also return descriptor objects instead of instance members in some cases. See the documentation for details. r;r<) rrrrrrDrrrr rr)r*rrwZinstance_resultrrZ klass_resultrrrrgetattr_statics<    r GEN_CREATED GEN_RUNNING GEN_SUSPENDED GEN_CLOSEDcC,|jrtS|jdur tS|jjdkrtStS)a#Get current state of a generator-iterator. Possible states are: GEN_CREATED: Waiting to start execution. GEN_RUNNING: Currently being executed by the interpreter. GEN_SUSPENDED: Currently suspended at a yield expression. GEN_CLOSED: Execution has completed. Nr) gi_runningrgi_framerf_lastirr) generatorrrrgetgeneratorstate   rcCs6t|s td|t|dd}|dur|jjSiS)z Get the mapping of generator local variables to their current values. A dict is returned, with the keys the local variable names and values the bound values.z{!r} is not a Python generatorrN)r_r$rrrr)rrrrrgetgeneratorlocalss  r CORO_CREATED CORO_RUNNINGCORO_SUSPENDED CORO_CLOSEDcCr)a&Get current state of a coroutine object. Possible states are: CORO_CREATED: Waiting to start execution. CORO_RUNNING: Currently being executed by the interpreter. CORO_SUSPENDED: Currently suspended at an await expression. CORO_CLOSED: Execution has completed. Nr) cr_runningrcr_framerrrr) coroutinerrrgetcoroutinestaterrcCst|dd}|dur |jSiS)z Get the mapping of coroutine local variables to their current values. A dict is returned, with the keys the local variable names and values the bound values.rN)rr)rrrrrgetcoroutinelocals/s r from_bytescCs6zt||}Wn tyYdSwt|ts|SdS)zPrivate helper. Checks if ``cls`` has an attribute named ``method_name`` and returns it only if it is a pure python function. N)rrr_NonUserDefinedCallables)rZ method_nameZmethrrr"_signature_get_user_defined_methodKs  rc Cs|j}t|}|jp d}|jpi}|r||}z |j|i|}Wnty9}z d|} t| |d}~wwd} |D]y\} } z|j | } Wn t yTYn4w| j t ur`| | q@| j tur{| |vrtd} | j| d|| <n| | jq@| j tur| j| d|| <| r| j tur|| jtd}||| <|| q@| j ttfvr|| q@| j tur| | jq@|j|dS) zPrivate helper to calculate how 'wrapped_sig' signature will look like after applying a 'functools.partial' object (or alike) on it. rz+partial object {!r} has incorrect argumentsNFT)rwrrt)rtrr)rkeywords bind_partialr$rr% argumentsrrrvrrxreplacerwrz move_to_endr{ryru) wrapped_sigr'Z extra_argsZ old_params new_paramsZ partial_argsZpartial_keywordsZbar~rZtransform_to_kwonly param_namerZ arg_valueZ new_paramrrr_signature_get_partial[sT                 rcCslt|j}|r|djttfvrtd|dj}|ttfvr(|dd}n|t ur0td|j |dS)zWPrivate helper to transform signatures for unbound functions to bound methods. rzinvalid method signaturerNzinvalid argument typer ) rrtrurr{rzr%rxrvryr)r}paramsrrrr_signature_bound_methods   rcCs&t|pt|pt|tp|ttfvS)zxPrivate helper to test if `obj` is a callable that might support Argument Clinic's __text_signature__ protocol. )rnrArrrr2rVrrr_signature_is_builtins rcCst|rt|r dSt|dd}t|dd}t|dt}t|dt}t|dd}t|tjoMt|toM|dup;t|toM|dupDt|t oMt|t pM|duS)zPrivate helper to test if `obj` is a duck type of FunctionType. A good example of such objects are functions compiled with Cython, which have all attributes that a pure Python function would have, but have their code statically compiled. FrNrQ __defaults____kwdefaults__r ) r#r6r_voidrrrkrrr )r*rwrrhrrrrrrOs       rOcCs<|d}|dkr|d}|d}|d}|d|S)z Private helper to get first parameter name from a __text_signature__ of a builtin method, which should be in the following format: '($param1, ...)'. Assumptions are that the first argument won't have a default value or an annotation. ,rr:rr%)find)rrZcposrrr_signature_get_bound_params     rcCs |s|ddfSd}d}dd|dD}t|j}t|}d}d}g}|j} d} tj} tj} t|} |D]O} | j | j }}|| kr^|dkrS|rLd}nd}| d 7} q6|d kr^d}| d }q6|| kri|d kri| }q6|ryd}|| kru|d ksy| d | ||dkr| dq6d |}|||fS)a Private helper function. Takes a signature in Argument Clinic's extended signature format. Returns a tuple of three things: * that signature re-rendered in standard Python syntax, * the index of the "self" parameter (generally 0), or None if the function does not have a "self" parameter, and * the index of the last "positional only" parameter, or None if the signature has no positional-only parameters. NcSsg|] }|r|dqS)ascii)encode)rlrrrrsz6_signature_strip_non_python_syntax..rFrrTr/$rr r) rrBrCr9rr?OP ERRORTOKENnextrstringr) signatureself_parameterlast_positional_onlyrrZ token_streamZ delayed_commaZskip_next_commarrZcurrent_parameterr$r%trr'clean_signaturerrr"_signature_strip_non_python_syntaxsR     r-Tc sLddl|jt|\}}}d|d}z|}Wn ty&d}Ynwt|js4td|j d} gj d}it dd} | rVt j | d}|rV|jt j  fdd fd d  G fd d d jffd d } t| jj} t| jj} tj| | dd}|durjnjttt|D]\}\}}| ||||krjq| jjr̈j| | jjjt| jj| jj D] \}}| ||q| jj!rj"| | jj!|durt dd}|du}t#|}|r|s |r$dn dj%jd} | d<||j dS)zdPrivate helper to parse content of '__text_signature__' and return a Signature based on it. rNzdef fooz: pass"{!r} builtin has invalid signaturer cs|jdur td|jS)Nz'Annotations are not currently supported)r|r%r)r rrr parse_namejs z&_signature_fromstr..parse_namec slzt|}Wnty!zt|}Wn tytwYnwt|tttttt dfr4 |Str) r NameErrorr%rrintfloatbytesrPrConstant)rr)r module_dictsys_module_dictrr wrap_valueps   z&_signature_fromstr..wrap_valuecs4eZdZfddZfddZfddZdS)z,_signature_fromstr..RewriteSymbolicscsdg}|}t|jr||j|j}t|js t|js!t||jdt |}|S)Nr) rrrrrNamer%rrreversed)rr arrrr8rrvisit_Attribute~s    z<_signature_fromstr..RewriteSymbolics.visit_Attributecst|jjs t|jSr)rctxZLoadr%rr r<rr visit_Names z7_signature_fromstr..RewriteSymbolics.visit_Namecs||j}||j}t|jrt|jstt|jjr*|j|jSt|jj r:|j|jSt|jj rJ|j|jBStr) rleftrightrr5r%opZAddrZSubZBitOr)rr r@rAr/rr visit_BinOps  z8_signature_fromstr..RewriteSymbolics.visit_BinOpN)rr rr=r?rCrr<rrRewriteSymbolics}s rDcsh|}|r'|tur'z |}|}Wnty&tddw||ddS)Nr.rwr|)_emptyrZ literal_evalr%rr)Z name_nodeZ default_noderwrw) ParameterrDrrsrr*rtr0rrps   z_signature_fromstr..p) fillvaluerr rr)&r_parameter_clsr-r SyntaxErrorrZModuler%rbodyrsrrrr r rZNodeTransformerr:rrh itertools zip_longestPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDrrWvarargVAR_POSITIONAL KEYWORD_ONLYrr\ kw_defaultsr VAR_KEYWORDr3rr)rr*rrmr,r)r*Zprogramr-rSr,rHrrhrBrrwrwZ_selfZ self_isboundZ self_ismoduler) rGrDrrsrr6r*rtr0r7r8r_signature_fromstrEsp        !      rWcCsBt|s td|t|dd}|std|t||||S)zHPrivate helper function to get signature for builtin callables. z%{!r} is not a Python builtin function__text_signature__Nz#no signature found for builtin {!r})rr$rrr%rW)rr(rmrrrr_signature_from_builtins rYc CsFd}t|st|r d}ntd|t|dd}|r#t||||S|j}|j} | j} | j } | j } | d| } | j }| | | |}t ||||d}|j }|j}|rXt|}nd}g}| |}| }| d|D]}|rntnt}||t}|||||d|r|d 8}qht| |dD]#\}}|rtnt}||t}|||||||d |r|d 8}q| jt@r| | |}||t}||||td|D]}t}|dur||t}||t}||||t|d q| jt@r| |}| jt@r|d 7}| |}||t}||||td|||d t|d S) zCPrivate helper: constructs Signature for the given python function.FTrrXNrr)r|rr)r|rrwrorr__validate_parameters__)r>rOr$rrrWrKrQrUrTco_posonlyargcountrVr/rrrrvrxr rFrrrRrXryrzrYr{)rr(rmrrrZis_duck_functionrrGZ func_codeZ pos_countZ arg_namesZ posonly_countrZkeyword_only_countZ keyword_onlyrrhrZpos_default_countrtZnon_default_countZ posonly_leftrwrr|offsetrwrrrr_signature_from_functions                     r^)rlrmrrrc Cs|tjt||||||d}t|std|t|tjr*||j }|r(t |S|S|r>t |ddd}t|tjr>||Sz|j }Wn t yLYnw|dur_t|ts]td||Sz|j} Wn t ymYn5wt| tjr|| j} t| | d}t| jd } | jtjur|St|j} | f| } |j| d St|st|rt||||||d St|rt|||d St|tjr||j} t| |Sd}t|trit t|d }|dur||}n5d}t |d}t |d}d|j!vr|}nd|j!vr|}n|dur |}n|dur|}|dur||}|durh|j"ddD]}z|j#}Wn t y:Yq(w|rFt$|||Sq(t|j"vrh|j%t&j%ura|j't&j'ura|(t&St)d|n0t|t*st t|d }|durz||}Wnt)y}z d|}t)||d}~ww|dur|rt |S|St|tj+rd|}t)|t)d|)zQPrivate helper function to get signature for arbitrary callable objects. )rlrmrrrnrz{!r} is not a callable objectcSst|dp t|tjS)N __signature__)rrrr8rrrrrzl s z*_signature_from_callable..rNz1unexpected object {!r} in __signature__ attributerrr )rmrrr)rm__call____new__rrz(no signature found for builtin type {!r}zno signature found for {!r}z,no signature found for builtin function {!r}z+callable {!r} is not supported by signature),r&r'rpr#r$rrrr8rMrr.r_rrq_partialmethod partialmethodr(rrrtrurrGrSrr>rOr^rrYrrr rrXrWrr2ra from_callabler%rrm)r*rlrmrrrrnZ_get_signature_ofr}rcrZfirst_wrapped_paramZ sig_paramsrZcallZfactory_methodnewZinitrxZtext_sigr~rrrrrpG s                                      rpc@eZdZdZdS)rz1A private marker - used in Parameter & Signature.Nrr rrrrrrr rc@rf)rFz6Marker object for Signature.empty and Parameter.empty.NrgrrrrrF rhrFc@s4eZdZdZdZdZdZdZddZe dd Z d S) _ParameterKindrrr%cCrr)_name_r4rrr__str__ sz_ParameterKind.__str__cCst|Sr)_PARAM_NAME_MAPPINGr4rrr description sz_ParameterKind.descriptionN) rr rrPrQrSrTrVrmrrorrrrri srizpositional-onlyzpositional or keywordzvariadic positionalrzvariadic keywordc@seZdZdZdZeZeZe Z e Z e ZeZeedddZddZdd Zed d Zed d ZeddZeddZeeeedddZddZddZddZddZdS)rGaRepresents a parameter in a function signature. Has the following public attributes: * name : str The name of the parameter as a string. * default : object The default value for the parameter if specified. If the parameter has no default value, this attribute is set to `Parameter.empty`. * annotation The annotation for the parameter if specified. If the parameter has no annotation, this attribute is set to `Parameter.empty`. * kind : str Describes how argument values are bound to the parameter. Possible values: `Parameter.POSITIONAL_ONLY`, `Parameter.POSITIONAL_OR_KEYWORD`, `Parameter.VAR_POSITIONAL`, `Parameter.KEYWORD_ONLY`, `Parameter.VAR_KEYWORD`. )_name_kind_default _annotationrEcCszt||_Wntytd|dw|tur/|jttfvr/d}||jj}t|||_||_ |tur=tdt |t sNdt |j }t||ddkrz|ddrz|jtkrnd }||jj}t|t|_d |dd}|std |||_dS) Nzvalue z is not a valid Parameter.kindz({} parameters cannot have default valuesz*name is a required attribute for Parameterzname must be a str, not a {}rrrzLimplicit arguments must be passed as positional or keyword arguments, not {}z implicit{}z"{!r} is not a valid parameter name)rirqr%rFryr{rrorrrsrrrrr$isdigitrxrv isidentifierrp)rrwrrwr|rrrrrM s8    zParameter.__init__cCs t||j|jf|j|jdfS)Nrrrs)rrprqrrrsr4rrr __reduce__u s  zParameter.__reduce__cC|d|_|d|_dS)Nrrrsrvrstaterrr __setstate__{  zParameter.__setstate__cCrr)rpr4rrrrw rzParameter.namecCrr)rrr4rrrrw rzParameter.defaultcCrr)rsr4rrrr| rzParameter.annotationcCrr)rqr4rrrr rzParameter.kind)rwrr|rwcCsL|tur|j}|tur|j}|tur|j}|tur|j}t|||||dS)z+Creates a customized copy of the Parameter.rE)rrprqrsrrr)rrwrr|rwrrrr szParameter.replacecCs|j}|j}|jturd|t|j}|jtur1|jtur(d|t|j}n d|t|j}|tkr;d|}|S|t krCd|}|S)Nz{}: {}z{} = {}z{}={}rr) rrprsrFrrrrrryr{)rr formattedrrrrm s    zParameter.__str__cCd|jj|S)Nz <{} "{}">rrrr4rrr__repr__ rzParameter.__repr__cCst|j|j|j|jfSr)hashrwrr|rwr4rrr__hash__ szParameter.__hash__cCsJ||urdSt|ts tS|j|jko$|j|jko$|j|jko$|j|jkSNT)rrGNotImplementedrprqrrrsrotherrrr__eq__ s     zParameter.__eq__N)rr rrrrvrPrxrQryrSrzrTr{rVrFrsrrwr{rrwrwr|rrrrmrrrrrrrrG- s6(      rGc@sheZdZdZdZddZeddZeddZed d Z d d Z d dZ ddZ ddZ ddZdS)BoundArgumentsaResult of `Signature.bind` call. Holds the mapping of arguments to the function's parameters. Has the following public attributes: * arguments : dict An ordered mutable mapping of parameters' names to arguments' values. Does not contain arguments' default values. * signature : Signature The Signature object that created this instance. * args : tuple Tuple of positional arguments values. * kwargs : dict Dict of keyword arguments values. )r  _signature __weakref__cCs||_||_dSr)r r)rr(r rrrr r zBoundArguments.__init__cCrr)rr4rrrr( rzBoundArguments.signaturec Csg}|jjD]5\}}|jttfvrt |Sz|j|}Wn ty,Yt |Sw|jtkr8| |q| |qt |Sr) rrtr)rr{rzr rryextendrr)rrrrrrrrr s     zBoundArguments.argsc Csi}d}|jjD];\}}|s"|jttfvrd}n||jvr"d}q |s%q z|j|}Wn ty5Yq w|jtkrA||q |||<q |Sr) rrtr)rr{rzr rupdate)rkwargsZkwargs_startedrrrrrrr s(     zBoundArguments.kwargsc Cs|j}g}|jjD]:\}}z ||||fWq tyE|jtur*|j}n|jt ur2d}n |jt ur:i}nYq |||fYq wt ||_dS)zSet default values for missing arguments. For variable-positional arguments (*args) the default is an empty tuple. For variable-keyword arguments (**kwargs) the default is an empty dict. rN) r rrtr)rrrwrFrryr{r )rr Z new_argumentsrwrvalrrrapply_defaults s       zBoundArguments.apply_defaultscCs2||urdSt|ts tS|j|jko|j|jkSr)rrrr(r rrrrr4 s   zBoundArguments.__eq__cCrx)Nrr rr ryrrrr{< r|zBoundArguments.__setstate__cCs|j|jdS)Nrrr4rrr __getstate__@ zBoundArguments.__getstate__cCs@g}|jD] \}}|d||qd|jjd|S)Nz{}={!r}z <{} ({})>r)r r)rrrrr)rrrrrrrrC szBoundArguments.__repr__N)rr rrrrrr(rrrrr{rrrrrrr s    rc@seZdZdZdZeZeZe Z d,e ddddZ e dd Z e d d Ze dddd d ddZeddZeddZeedddZddZddZddZd dddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+ZdS)-rqaA Signature object represents the overall signature of a function. It stores a Parameter object for each parameter accepted by the function, as well as information specific to the function itself. A Signature object has the following public attributes and methods: * parameters : OrderedDict An ordered mapping of parameters' names to the corresponding Parameter objects (keyword-only arguments are in the same order as listed in `code.co_varnames`). * return_annotation : object The annotation for the return type of the function if specified. If the function has no annotation for its return type, this attribute is set to `Signature.empty`. * bind(*args, **kwargs) -> BoundArguments Creates a mapping from positional and keyword arguments to parameters. * bind_partial(*args, **kwargs) -> BoundArguments Creates a partial mapping from positional and keyword arguments to parameters (simulating 'functools.partial' behavior.) )_return_annotation _parametersNTrZc Cs|durt}n_|r^t}t}d}|D]I}|j}|j} ||kr-d} | |j|j} t| ||kr5d}|}|ttfvrK|jt urI|rHd} t| nd}| |vrXd| } t| ||| <qn tdd|D}t ||_ ||_ dS) zConstructs Signature from the given list of Parameter objects and 'return_annotation'. All arguments are optional. NFz7wrong parameter order: {} parameter before {} parameterz-non-default argument follows default argumentTzduplicate parameter name: {!r}css|]}|j|fVqdSrrrrrrrr rz%Signature.__init__..)rrvrrwrror%rxrwrFrMappingProxyTyperr) rrtrrr[rZtop_kindZ kind_defaultsrrrwrrrrrh sD     #  zSignature.__init__cCtjdtddt||S)zConstructs Signature for the given python function. Deprecated since Python 3.5, use `Signature.from_callable()`. z_inspect.Signature.from_function() is deprecated since Python 3.5, use Signature.from_callable()r%rb)rdrerfr^rr(rrr from_function  zSignature.from_functioncCr)zConstructs Signature for the given builtin function. Deprecated since Python 3.5, use `Signature.from_callable()`. z^inspect.Signature.from_builtin() is deprecated since Python 3.5, use Signature.from_callable()r%rb)rdrerfrYrrrr from_builtin rzSignature.from_builtinFfollow_wrappedrrrcCst||||||dS)z3Constructs Signature for the given callable object.)rnrlrrr)rp)rr*rrrrrrrrd szSignature.from_callablecCrr)rr4rrrrt rzSignature.parameterscCrrrr4rrrrr rzSignature.return_annotation)rtrrcCs0|tur |j}|tur|j}t|||dS)zCreates a customized copy of the Signature. Pass 'parameters' and/or 'return_annotation' arguments to override them in the new copy. rJ)rrtrurr)rrtrrrrrr s zSignature.replacecCs8tdd|jD}dd|jD}|||jfS)Ncss|] }|jtkr|VqdSr)rrzrrrrr s  z(Signature._hash_basis..cSsi|] }|jtkr|j|qSr)rrzrwrrrrr s z)Signature._hash_basis..)rrtrurr)rr kwo_paramsrrr _hash_basis s zSignature._hash_basiscCs(|\}}}t|}t|||fSr)r frozensetrur)rrrrrrrrr s zSignature.__hash__cCs*||urdSt|ts tS||kSr)rrqrrrrrrr s  zSignature.__eq__r'c Cs|i}t|j}d}t|} zt|}Wn`tyvzt|} Wn ty-YYnw| jtkr5Yn| j|vrR| jtkrMd} | j | jd} t | d| f}Yns| jt ks\| j t ura| f}Ynd|rh| f}Yn]d} | j | jd} t | dwzt|} Wn tyt ddw| jt tfvrt dd| jtkr|g} | |t| || j<n| j|vr| jtkrt dj | jdd||| j<qd} t||D]P} | jt kr| } q| jtkrq| j} z|| }Wn"ty |s| jtkr| j t urt dj | ddYqw| jtkrt dj | jd||| <q|r8| dur,||| j<n t d j tt|d|||S) z#Private method. Don't use directly.rTzA{arg!r} parameter is positional only, but was passed as a keyword)rNz$missing a required argument: {arg!r}ztoo many positional argumentsz$multiple values for argument {arg!r}z*got an unexpected keyword argument {arg!r})rBrtrur& StopIterationrryrwrvrr$r{rwrFrzrrrNchainrr_bound_arguments_cls)rrrr'r rtZ parameters_exZarg_valsZarg_valrrruZ kwargs_paramrrrr_bind s           (      J         zSignature._bindcOs |||S)zGet a BoundArguments object, that maps the passed `args` and `kwargs` to the function's signature. Raises `TypeError` if the passed arguments can not be bound. rrrrrrrbindm rGzSignature.bindcOs|j||ddS)zGet a BoundArguments object, that partially maps the passed `args` and `kwargs` to the function's signature. Raises `TypeError` if the passed arguments can not be bound. Trrrrrrr t szSignature.bind_partialcCs t|t|jfd|jifSNr)rrrrurr4rrrrw{ szSignature.__reduce__cCs|d|_dSrrryrrrr{ rzSignature.__setstate__cCr~)Nz<{} {}>rr4rrrr rzSignature.__repr__c Csg}d}d}|jD]2}t|}|j}|tkrd}n |r$|dd}|tkr+d}n |tkr8|r8|dd}||q |rE|ddd |}|j t ur^t |j }|d|7}|S)NFTr!rz({})rz -> {}) rtrurrrvrryrzrrrrrFr) rrZrender_pos_only_separatorZrender_kw_only_separatorrr}rZrenderedZannorrrrm s0       zSignature.__str__r)rr rrrrGrKrrrFrsrrrrrdrrtrrrrrrrrrr rwr{rrmrrrrrqJ s@ 6       rqrcCstj|||||dS)z/Get a signature object for the passed callable.r)rqrd)r*rrrrrrrr( sr(c Csddl}ddl}|}|jddd|jdddd d |}|j}|d \}}}z ||}} Wn(ty\} zd |t | j | } t | t jd t dWYd} ~ nd} ~ ww|rp|d} | }| D]} t|| }qh| j t jvrt dt jd t d|jrt d |t d t| t d | j|| urt d t| jt| drt d | jnzt|\}}Wn tyYnwt d |t ddSt t|dS)z6 Logic for inspecting an object given at command line rNr2zCThe object to be analysed. It supports the 'module:qualname' syntax)helpz-dz --details store_truez9Display info about the module rather than its source code)actionrrzFailed to import {} ({}: {}))rr%rz#Can't get info for builtin modules.rz Target: {}z Origin: {}z Cached: {}z Loader: {}__path__zSubmodule search path: {}zLine: {}r)argparserArgumentParser add_argument parse_argsr2 partition import_modulerrrrprintrstderrexitrrbuiltin_module_namesZdetailsr __cached__rrrrr$rJ)rrparserrtargetZmod_nameZ has_attrsZattrsr*r-rrpartspart__rrrr_main sd       rrr)F)r)r)T)TNNF)r __author__rdrdisZcollections.abcrcenumimportlib.machineryrrNrrrrr9r?rrdr&roperatorrrrrZmod_dictZCOMPILER_FLAG_NAMESr)rrrsr/r3r6r9rArCrrFrKr>rUrWrYrZr\r_rarfrhrjrlrnroryrrrr}r.rrrrrrrrrrrrrrZ NodeVisitorrr$r*r+r-rFrIrJrKrRrSr`rarjrkrgrrrrrrrrrrrrrrr_fieldsrrrrrrr2rrrrrrrrrrrrrrrrrrrrr`Z_WrapperDescriptorallZ_MethodWrapperr2r Z_ClassMethodWrapperrmrrrrrrOrr-rWrYr^rprrFIntEnumrirPrvrQrxrSryrTrzrVr{rnrGrrqr(rrrrrrs  t            ,t$ >   /D-6    ]  ;  < 5         0   L  H  ` B l :