Yf@sdZddfZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlmZddlmZmZeZx+ejjD]\ZZeedeZd d Zd d Z ddZ!ddZ"ddZ#e$edrddZ%n ddZ%e$edrddZ&n ddZ&ddZ'ddZ(d d!Z)d"d#Z*d$d%Z+d&d'Z,d(d)Z-d*d+Z.d,d-Z/d.d/Z0d0d1Z1d2d3Z2dd4d5Z3ed6d7Z4d8d9Z5d:d;Z6d<dd=d>Z7d?d@Z8dAdBZ9dCdDZ:dEdFZ;dGdHZ<dIdJZ=edKdLZ>dMdNZ?dOdPZ@dQdRZAddSdTZBiZCiZDddUdVZEdWdXZFdYdZZGGd[d\d\eHZIGd]d^d^ZJd_d`ZKdadbZLdcddZMdedfZNdgdhdiZOedjdkZPdldmZQdndoZRedpdqZSdrdsZTedtduZUdvdwZVedxdyZWdzd{ZXdd|d}ZYd~dZZdddfiie[ddddddddeYdd Z\e[ddddddddZ]ddZ^ddZ_ddZ`eddZaddZbeddZcdddZdddZeeddfecjfZgdddZhdddZiddZjdddZkdddZlemZnddZoddZpddZqddZrddZsenddZtdZudZvdZwdZxddZyddZzdZ{dZ|dZ}dZ~ddZddZeejZeejZeejdZeeeejfZddZfddZddZddZddZddZddZdddZdddZddZddddddZGdddZGdddZGdddejZejZejZejZejZejZGdddZGdddZGdddZddddZddZedkredS)a%Get 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 getargspec(), getargvalues(), getcallargs() - get info about function arguments getfullargspec() - same, with support for Python 3 features formatargspec(), 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 zKa-Ping Yee z'Yury Selivanov N) attrgetter) namedtuple OrderedDictZCO_cCst|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)) isinstancetypes ModuleType)objectr ,/opt/alt/python35/lib64/python3.5/inspect.pyismodule?sr cCs 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)rtype)r r r r isclassHsrcCst|tjS)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 MethodType)r r r r ismethodPsrcCsQt|s$t|s$t|r(dSt|}t|doPt|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__)rr isfunctionrhasattr)r tpr r r ismethoddescriptorZs$ rcCsPt|s$t|s$t|r(dSt|}t|doOt|dS)aReturn true if the object is a data descriptor. Data descriptors have both a __get__ and a __set__ 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.Frr)rrrrr)r rr r r isdatadescriptorns$ rMemberDescriptorTypecCst|tjS)zReturn true if the object is a member descriptor. Member descriptors are specialized descriptors defined in extension modules.)rrr)r r r r ismemberdescriptor~srcCsdS)zReturn true if the object is a member descriptor. Member descriptors are specialized descriptors defined in extension modules.Fr )r r r r rsGetSetDescriptorTypecCst|tjS)zReturn true if the object is a getset descriptor. getset descriptors are specialized descriptors defined in extension modules.)rrr)r r r r isgetsetdescriptorsrcCsdS)zReturn true if the object is a getset descriptor. getset descriptors are specialized descriptors defined in extension modules.Fr )r r r r rscCst|tjS)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 FunctionType)r r r r rs rcCs,tt|st|o(|jjt@S)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.)boolrr__code__co_flagsZ CO_GENERATOR)r r r r isgeneratorfunctionsr!cCs,tt|st|o(|jjt@S)zReturn true if the object is a coroutine function. Coroutine functions are defined with "async def" syntax, or generators decorated with "types.coroutine". )rrrrr Z CO_COROUTINE)r r r r iscoroutinefunctionsr"cCst|tjS)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 GeneratorType)r r r r isgeneratorsr$cCst|tjS)z)Return true if the object is a coroutine.)rr CoroutineType)r r r r iscoroutinesr&cCsMt|tjpLt|tjr:t|jjt@pLt|tj j S)z?Return true if object can be passed to an ``await`` expression.) rrr%r#rgi_coder ZCO_ITERABLE_COROUTINE collectionsabc Awaitable)r r r r isawaitablesr+cCst|tjS)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 TracebackType)r r r r istracebacksr-cCst|tjS)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 FrameType)r r r r isframes r/cCst|tjS)a/Return 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 co_freevars tuple of names of free variables 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 of local variables co_nlocals number of local variables co_stacksize virtual machine stack space required co_varnames tuple of names of arguments and local variables)rrCodeType)r r r r iscodesr1cCst|tjS)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)rrBuiltinFunctionType)r r r r isbuiltinsr3cCs.t|p-t|p-t|p-t|S)zEszgetmembers..)rgetmrosetdir __bases____dict__itemsrrDynamicClassAttributeappendAttributeErrorgetattraddsort) r Z predicatemroresults processednamesbasekvr8valuer r r getmemberss:          rN Attributezname kind defining_class objectcCst|}tt|}tdd|D}|f|}||}t|}xM|D]E}x<|jjD]+\}}t|tjrw|j |qwWqaWg} t } xF|D]>} d} d} d}| | kry+| dkrt dt || } Wn%t k r6}zWYdd}~XnXt | d| } | |krd} d}x2|D]*}t || d}|| krh|}qhWxN|D]F}y|j || }Wntk rwYnX|| kr|}qW|dk r|} x=|D]5}| |jkr|j| }| |kr4|} PqW| dkrHq| dk rZ| n|}t|tr~d}|}nWt|trd}|}n9t|trd }|}nt|rd }nd }| j t| || || j| qW| 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(g|]}|ttfkr|qSr )rr ).0clsr r r gs z(classify_class_attrs..Nr>z)__dict__ is special, don't want the proxy __objclass__z static methodz class methodpropertymethoddata)r:rtupler<r>r?rrr@rAr; ExceptionrC __getattr__rB staticmethod classmethodrTr4rOrD)rQrFZmetamroZ class_basesZ all_basesrIrJrKrLresultrHnameZhomeclsZget_objZdict_objexcZlast_clsZsrch_clsZsrch_objobjkindr r r classify_class_attrsJs                            racCs|jS)zHReturn tuple of base classes (including cls) in method resolution order.)__mro__)rQr r r r:sr:stopcsdkrdd}nfdd}|}t|h}xS||r|j}t|}||krtdj||j|qEW|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|dS)N __wrapped__)r)fr r r _is_wrapperszunwrap.._is_wrappercst|do| S)Nrd)r)re)rcr r rfsz!wrapper loop when unwrapping {!r})idrd ValueErrorformatrD)funcrcrfrememoZid_funcr )rcr unwraps    rlcCs&|j}t|t|jS)zBReturn the indent size, in spaces, at the start of a line of text.) expandtabslenlstrip)lineZexpliner r r indentsizes rqcCsotjj|j}|dkr%dSx3|jjdddD]}t||}qBWt|skdS|S)N.r)sysmodulesget __module__ __qualname__splitrCr)rjrQr]r r r _findclasss # rzc Csbt|rexR|jD]G}|tk ry |j}Wntk rLwYnX|dk r|SqWdSt|r|jj}|j}t|rt t ||dd|jkr|}q |j }nAt |r|j}t |}|dks t |||k r dSnt |rm|j}|j}t|ra|jd||jkra|}q |j }nt|tr|j}|j}t |}|dkst |||k r dSnJt|st|r|j}|j}t |||k r dSndSxO|jD]D}yt ||j}Wntk rIwYnX|dk r|SqWdS)N__func__rr)rrbr __doc__rBrr{__name____self__rC __class__rrzr3rxrrTfgetrrrS)r_rJdocr]selfrQrjr r r _finddocsb         $     !         !    rcCs~y |j}Wntk r%dSYnX|dkrayt|}Wnttfk r`dSYnXt|tstdSt|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)r|rBr TypeErrorrstrcleandoc)r rr r r getdoc/s     rc CsFy|jjd}Wntk r1dSYnXtj}xO|ddD]=}t|j}|rLt||}t||}qLW|r|dj|d<|tjkrx5tdt|D]}|||d||.) warningswarnDeprecationWarningcatch_warnings simplefilterPendingDeprecationWarningimpospathbasenameZ get_suffixesrEr)rrfilenamesuffixesneglenrrrr r r getmoduleinfozs    rcCsptjj|}ddtjjD}|jx1|D])\}}|j|r?|d|Sq?WdS)z1Return the module name for a given file, or None.cSs#g|]}t| |fqSr )rn)rPrr r r rRs z!getmodulename..N)rrr importlib machinery all_suffixesrEendswith)rZfnamerrrr r r getmodulenames  rcst|tjjdd}|tjjdd7}tfdd|Drtjjdtjj dn)tfddtjj DrdStjj rSt t |dddk rStjkrSdS)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. Nc3s|]}j|VqdS)N)r)rPs)rr r sz getsourcefile..rc3s|]}j|VqdS)N)r)rPr)rr r rs __loader__)rrrDEBUG_BYTECODE_SUFFIXESOPTIMIZED_BYTECODE_SUFFIXESanyrrsplitextSOURCE_SUFFIXESEXTENSION_SUFFIXESexistsrC getmodule linecachecache)r Zall_bytecode_suffixesr )rr getsourcefiles !rcCs@|dkr$t|p!t|}tjjtjj|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)r _filenamer r r getabsfiles rc Cst|r|St|dr2tjj|jS|dk r^|tkr^tjjt|Syt||}Wntk rdSYnX|tkrtjjt|Sxt tjj D]\}}t|rt|dr|j }|t j|dkr q|t |||fS|j|jd |fqW|r|j||dd fStd t|r|j}t|r|j}t|r|j}t|r|j}t|r^t|d std |jd } t jd }x.| dkrS|j|| rFP| d } q&W|| fStddS)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.<>zsource code not availablezcould not get source coderz^(\s*)class\s*z\bcrzcould not find class definitionco_firstlinenoz"could not find function definitionz>^(\s*def\s)|(\s*async\s+def\s)|(.*(?r rr}recompilerrnmatchrAgrouprErr{rrr-rr/rr1rr) r rrrr]ZpatZ candidatesrrlnumr r r findsources^                        rc Csyt|\}}Wnttfk r4dSYnXt|rBd}|rm|ddddkrmd}x6|t|kr||jdkr|d}qpW|t|kr||dddkrg}|}xQ|t|kr1||dddkr1|j||j|d}qWdj|Sn|dkrt ||}|d}|dkr||j dddkrt |||kr||jj g}|dkrb|d}||jj }xp|dddkrat |||kra|g|dd<|d}|dkrHP||jj }qWx0|r|djdkrg|dd._formatannotation)rC)r r9r )rr formatannotationrelativetosr:cCsd|S)N*r )r]r r r r9sr9cCsd|S)Nz**r )r]r r r r9scCsdt|S)N=)r6)rMr r r r9scCsd|S)Nz -> r )textr r r r9sc sfdd} g}|r:t|t|}x]t|D]O\}}| |}|r||kr|| |||}|j|qGW|dk r|j|| |n|r|jd|r+xM|D]E}| |}|r||kr|| ||7}|j|qW|dk rP|j| | |ddj|d}dkr|| d7}|S) aFormat an argument spec from the values returned by getargspec or 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.cs4|}|kr0|d|7}|S)Nz: r )argr\)r/r8 formatargr r formatargandannotations  z-formatargspec..formatargandannotationNr;rz, rr)rn enumeraterAr)rr r rr rr/r? formatvarargs formatvarkw formatvalueZ formatreturnsr8r@specsZ firstdefaultrr>specZ kwonlyargr\r )r/r8r?r formatargspecs2       rGcCsd|S)Nr;r )r]r r r r9scCsd|S)Nz**r )r]r r r r9scCsdt|S)Nr<)r6)rMr r r r9sc Cs|||dd}g} x1tt|D]} | j||| q.W|rv| j||||||r| j|||||ddj| 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|||||S)Nr )r]localsr?rDr r r convertsz formatargvalues..convertrz, r)rrnrAr) rr r rHr?rBrCrDrIrErr r r formatargvaluess !!rJcsfdd|D}t|}|dkr>|d}nW|dkr\dj|}n9dj|dd}|dd=dj||}td |||rd nd |dkrd nd |fdS)Ncs(g|]}|krt|qSr )r6)rPr])r%r r rRs z&_missing_arguments..rrrz {} and {}z , {} and {}z, z*%s() missing %i required %s argument%s: %s positionalz keyword-onlyrrrL)rnrirr)f_nameZargnamesposr%rImissingrtailr )r%r _missing_argumentss     rQc s.t||}tfdd|D}|rQ|dk} d|f} nI|rvd} d|t|f} n$t|dk} tt|} d} |rd} | |dkrd nd||dkrd ndf} td || | rd nd|| |dkr| rd nd fdS) Ncs"g|]}|kr|qSr r )rPr>)r%r r rRs z_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)rnrr) rMrZkwonlyr ZdefcountZgivenr%ZatleastZ kwonly_givenZpluralr-Z kwonly_sigmsgr )r%r _too_manys$ rScOs|d}|dd}t|}|\}}}}} } } |j} i} t|r{|jdk r{|jf|}t|}t|}|rt|nd}t||}x&t|D]}||| ||rOkwargr r r getcallargssd            '   rW ClosureVarsz"nonlocals globals builtins unboundc CsRt|r|j}t|s6tdj||j}|jdkrWi}n"ddt|j|jD}|j }|j dt j }t |r|j }i}i}t}x{|jD]p}|d krqy||||Ws z"getclosurevars.. __builtins__NoneTrueFalse)r]r^r_)rr{rrrir __closure__zip co_freevars __globals__rvrr>r r;co_namesKeyErrorrDrX) rjcodeZ nonlocal_varsZ global_nsZ builtin_nsZ global_varsZ builtin_varsZ unbound_namesr]r r r getclosurevarsBs8              rg Tracebackz+filename lineno function code_context indexcCs#t|r!|j}|j}n |j}t|sKtdj|t|p`t|}|dkr|d|d}yt |\}}Wnt k rd}}YqXt dt |t ||}||||}|d|}n d}}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 objectrrrN)r- tb_linenorf_linenor/rrirrrrmaxrrnrhrco_name)r4contextlinenorrrrindexr r r getframeinfoys$       " rpcCs|jS)zCGet the line number from a frame object, allowing for optimization.)rj)r4r r r getlinenosrq FrameInfor4cCsIg}x<|rD|ft||}|jt||j}q W|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.)rprArrf_back)r4rm framelist frameinfor r r getouterframess   rvcCsLg}x?|rG|jft||}|jt||j}q W|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.)rrprArrtb_next)tbrmrtrur r r getinnerframess   rycCs ttdrtjdSdS)z?Return the frame of the caller or None if this is not possible. _getframerN)rrtrzr r r r currentframesr{cCsttjd|S)z@Return a list of records for the stack above the caller's frame.r)rvrtrz)rmr r r stacksr|cCsttjd|S)zCReturn a list of records for the stack below the current exception.r)ryrtexc_info)rmr r r tracesr~cCstjdj|S)Nrb)rr>r)klassr r r _static_getmrosrc CsDi}ytj|d}Wntk r0YnXtj||tS)Nr>)r __getattribute__rBdictrv _sentinel)r_attrZ instance_dictr r r _check_instances  rc CsWxPt|D]B}tt|tkr y|j|SWq tk rNYq Xq WtS)N)r_shadowed_dictrrr>re)rrentryr r r _check_classs  rc Cs+yt|Wntk r&dSYnXdS)NFT)rr)r_r r r _is_types   rc Cstjd}xwt|D]i}y|j|d}Wntk rKYqXt|tjko||jdko||j|ks|SqWt S)Nr>) rr>rrrerrr}rSr)r dict_attrrZ class_dictr r r rs  rc Csit}t|s]t|}t|}|tksKt|tjkrct||}n|}t||}|tk r|tk rtt|dtk rtt|dtk r|S|tk r|S|tk r|S||krIxVtt|D]B}tt|tkry|j |SWqt k rDYqXqW|tk rY|St |dS)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. rrN) rrrrrrrrrr>rerB)r_rr(Zinstance_resultrrZ klass_resultrr r r getattr_statics6           r GEN_CREATED GEN_RUNNING GEN_SUSPENDED GEN_CLOSEDcCs:|jr tS|jdkr tS|jjdkr6tStS)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. Nrrs) gi_runningrgi_framerf_lastirr) generatorr r r getgeneratorstate(s rcCsQt|s!tdj|t|dd}|dk rI|jjSiSdS)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$rrirCrr3)rr4r r r getgeneratorlocals:s    r CORO_CREATED CORO_RUNNINGCORO_SUSPENDED CORO_CLOSEDcCs:|jr tS|jdkr tS|jjdkr6tStS)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. Nrrs) cr_runningrcr_framerrrr) coroutiner r r getcoroutinestateRs rcCs-t|dd}|dk r%|jSiSdS)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)rCr3)rr4r r r getcoroutinelocalsds r from_bytesc CsCyt||}Wntk r+dSYnXt|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)rCrBr_NonUserDefinedCallables)rQZ method_namemethr r r "_signature_get_user_defined_methods   rcCs3|j}t|j}|jp'f}|jp6i}|rI||}y|j||}WnCtk r}z#dj|} t| |WYdd}~XnXd} xo|jD]a\} } y|j | } Wnt k rYnX| j t kr |j | q| j tkrV| |krCd} | jd| || .rFrrTr/$rz,  r)ryrrrrArOP ERRORTOKENnextrENCODINGrstringr) signatureself_parameterlast_positional_onlyrrZ token_streamZ delayed_commaZskip_next_commar=rDZcurrent_parameterrrtrrclean_signaturer r r "_signature_strip_non_python_syntax2sZ                  rTcs8|jt|\}}}d|d}ytj|}Wntk rYd}YnXt|tjstdj||j d} gj t d}it |dd} | rt jj| d}|r|jt jddfd d G fd d d tjfd d} t| jj} t| jj} tj| | dd}|dk rjn jxNttt|D]4\}\}}| ||||krjqW| jjr4j| | jjjx6t| jj| jj D]\}}| ||qYW| jj!rj"| | jj!|dk r%st#t |dd}|dk }t$|}|r|s|rj%dn#dj&dj} | d<|d|j S)zdPrivate helper to parse content of '__text_signature__' and return a Signature based on it. zdef fooz: passNz"{!r} builtin has invalid signaturerrwcSs:t|tjst|jdkr3td|jS)Nz'Annotations are not currently supported)rastr>rr,rh)noder r r parse_names z&_signature_fromstr..parse_namecsyt|}WnCtk rXyt|}Wntk rStYnXYnXt|trutj|St|ttfrtj |St|t rtj |S|dkrtj |StdS)NTF)TFN) eval NameError RuntimeErrorrrrZStrintfloatZNumbytesZBytesZ NameConstant)rrM) module_dictsys_module_dictr r wrap_values        z&_signature_fromstr..wrap_valuecs4eZdZfddZfddZdS)z,_signature_fromstr..RewriteSymbolicscsg}|}x/t|tjr=|j|j|j}qWt|tjsYt|j|jdj t |}|S)Nrr) rrrOrArrMNamerrgrreversed)rrarTrM)rr r visit_Attributes  z<_signature_fromstr..RewriteSymbolics.visit_Attributecs+t|jtjst|jS)N)rZctxrZLoadrhrg)rr)rr r visit_Names z7_signature_fromstr..RewriteSymbolics.visit_NameN)r}rwrxrrr )rr r RewriteSymbolicss  rcs|}|krdS|r|tk ry%j|}tj|}Wntk rm}YnX|kr~dS|k r|n|}j|d|ddS)Nr(r,)_emptyZvisitrZ literal_evalrhrA)Z name_nodeZ default_noder(r]o) Parameterrr#invalidr`r$rr r ps     z_signature_fromstr..p fillvaluer~r`r")'_parameter_clsrrparse SyntaxErrorrZModulerhriZbodyr#r rCrtrurvr>ZNodeTransformerrrr itertools zip_longestPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDrArZvarargVAR_POSITIONAL KEYWORD_ONLYrar Z kw_defaultsrV VAR_KEYWORDrr rr7)rQr_rrrrrZprogramrreZ module_namerrrrrr]r(_selfZ self_isboundZ self_ismoduler ) rrr#rr`rr$rrrr _signature_fromstrzsl         '   +      (       rcCsat|s!tdj|t|dd}|sNtdj|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})rrrirCrhr)rQrjrrr r r _signature_from_builtins   rc Csd}t|s<t|r'd}ntdj||j}|j}|j}|j}t|d|}|j }||||} |j } |j } |j } | rt | } nd} g}|| }xI|d|D]7}| j|t}|j||d|dtqWx_t||dD]G\}}| j|t}|j||d|dtd| |q<W|jt@r|||}| j|t}|j||d|dtxi| D]a}t}| dk r| j|t}| j|t}|j||d|dtd|qW|jt@r||}|jt@rm|d 7}||}| j|t}|j||d|dt||d | jd td |S) zCPrivate helper: constructs Signature for the given python function.FTz{!r} is not a Python functionNrr,r`r(rr"r__validate_parameters__)rrrrirrr rrWrrrrrnrvrrAr'rAr rr)r*rr+)rQrjZis_duck_functionrZ func_codeZ pos_countZ arg_namesrKZkeyword_only_countZ keyword_onlyr/rr0Zpos_default_countr$Znon_default_countr]r,offsetr(ror r r _signature_from_functionsj            #           rrrc!Cst|s!tdj|t|tjrht|jd|d|d|}|rdt|S|S|rt |ddd}t|tjrt|d|d|d|Sy |j }Wnt k rYn5X|dk r t|t std j||Sy |j }Wnt k r+YnXt|tjrt|jd|d|d|}t||d}t|jjd }|jtjkr|St|jj}||d k st|f|} |jd | St|st|r t||St|r,t||d|St|tjrlt|jd|d|d|}t||Sd}t|t rt!t |d } | dk rt| d|d|d|}nut!|d } | dk rt| d|d|d|}n9t!|d} | dk r8t| d|d|d|}|dkrxS|j"ddD]>} y | j#}Wnt k rYqXX|rXt$|||SqXWt |j"kr|j%t&j%kr|j't&j'krt(t&St)dj|nt|t*st!t |d } | dk ry"t| d|d|d|}WnCt)k r}z#dj|}t)||WYdd}~XnX|dk r|rt|S|St|tj+rdj|}t)|t)dj|dS)zQPrivate helper function to get signature for arbitrary callable objects. z{!r} is not a callable objectrrrrccSs t|dS)N __signature__)r)rer r r r9sz*_signature_from_callable..Nz1unexpected object {!r} in __signature__ attributerr$__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)Nrs),rrrirrrr r{rrlrrBr!_partialmethod functools partialmethodrjrrWr$r%r`rrrr7rrrrrrrrrbrrrr rrrhrr2)r_rrrr-rrZfirst_wrapped_paramZ sig_paramsrZcallnewZinitrJZtext_sigr.rRr r r r hs                               "   r c@seZdZdZdS)rz1A private marker - used in Parameter & Signature.N)r}rwrxr|r r r r r0 s rc@seZdZdZdS)rz6Marker object for Signature.empty and Parameter.empty.N)r}rwrxr|r r r r r4 s rc@s:eZdZdZdZdZdZdZddZdS) _ParameterKindrrrcCs|jS)N)Z_name_)rr r r __str__? sz_ParameterKind.__str__N) r}rwrxrrrrrrr r r r r8 s rc @s eZdZdZd#ZeZeZe Z e Z e ZeZdededd Zd d Zd d ZeddZeddZeddZeddZdededededdZddZddZddZd d!Zd"S)$raRepresents 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 _annotationr(r,cCs|tttttfkr'td||_|tk ri|ttfkridj|}t|||_ ||_ |tkrtdt |t st dj||jstdj|||_dS)Nz,invalid value for 'Parameter.kind' attributez({} parameters cannot have default valuesz*name is a required attribute for Parameterzname must be a str, not a {!r}z"{!r} is not a valid parameter name)r&r'r)r*r+rhrrrirrrrr isidentifierr)rr]r`r(r,rRr r r rj s"          zParameter.__init__cCs1t||j|jfd|jd|jifS)Nrr)rrrrr)rr r r __reduce__ s  zParameter.__reduce__cCs|d|_|d|_dS)Nrr)rr)rstater r r __setstate__ s zParameter.__setstate__cCs|jS)N)r)rr r r r] szParameter.namecCs|jS)N)r)rr r r r( szParameter.defaultcCs|jS)N)r)rr r r r, szParameter.annotationcCs|jS)N)r)rr r r r` szParameter.kindr]r`cCss|tkr|j}|tkr*|j}|tkr?|j}|tkrT|j}t|||d|d|S)z+Creates a customized copy of the Parameter.r(r,)rrrrrr)rr]r`r,r(r r r r7 s        zParameter.replacecCs|j}|j}|jtk r<dj|t|j}|jtk rfdj|t|j}|tkrd|}n|t krd|}|S)Nz{}:{}z{}={}r;z**) r`rrrrir8rr6r)r+)rr` formattedr r r r s       zParameter.__str__cCsdj|jj|S)Nz <{} "{}">)rirr})rr r r __repr__ szParameter.__repr__cCs"t|j|j|j|jfS)N)hashr]r`r,r()rr r r __hash__ szParameter.__hash__cCsi||krdSt|ts#tS|j|jkoh|j|jkoh|j|jkoh|j|jkS)NT)rrNotImplementedrrrr)rotherr r r __eq__ s zParameter.__eq__N)rrrr)r}rwrxr| __slots__r&rr'rr)rr*rr+rrr#rrrrTr]r(r,r`rr7rrr r r r r r rJ s*      rc@seZdZdZdZddZeddZed d Zed d Z d dZ ddZ ddZ ddZ ddZdS)BoundArgumentsaResult of `Signature.bind` call. Holds the mapping of arguments to the function's parameters. Has the following public attributes: * arguments : OrderedDict 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||_||_dS)N)rr)rrrr r r r s zBoundArguments.__init__cCs|jS)N)r)rr r r r szBoundArguments.signaturec Csg}x|jjjD]u\}}|jttfkr;Py|j|}Wntk raPYqX|jtkr|j |q|j |qWt |S)N) rr$r?r`r+r*rrer)extendrArW)rrrr1r>r r r r s zBoundArguments.argsc Csi}d}x|jjjD]\}}|sg|jttfkrOd}n||jkrgd}q|spqy|j|}Wntk rYqX|jtkr|j|q|||r r r r s&  zBoundArguments.kwargsc Cs|j}g}x|jjjD]\}}y|j|||fWq"tk r|jtk rt|j}n3|jt krf}n|jt kri}nw"|j||fYq"Xq"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. N) rrr$r?rArer(rr`r)r+r)rrZ new_argumentsr]r1valr r r apply_defaults# s     zBoundArguments.apply_defaultscCsE||krdSt|ts#tS|j|jkoD|j|jkS)NT)rrr rr)rr r r r r ? s  zBoundArguments.__eq__cCs|d|_|d|_dS)Nrr)rr)rrr r r rG s zBoundArguments.__setstate__cCsd|jd|jiS)Nrr)rr)rr r r __getstate__K szBoundArguments.__getstate__cCs^g}x6|jjD]%\}}|jdj||qWdj|jjdj|S)Nz{}={!r}z <{} ({})>z, )rr?rArirr}r)rrr>rMr r r rN szBoundArguments.__repr__N)rrr)r}rwrxr|rrrTrrrrr rrrr r r r r s      rc@s?eZdZdZd.ZeZeZe Z dde dddd Z e d d Z e d d Ze ddddZeddZeddZdededdZddZddZddZddd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZdS)/r!aA 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 _parametersNr"rTc Cs[|dkrt}n$|r#t}t}d}xt|D]\}}|j} |j} | |krd} | j|| } t| n| |krd}| }| ttfkr|jt kr|rd} t| nd}| |krdj| } t| ||| .)rr&rAr`r]rirhr'r(rrMappingProxyTyperr) rr$r"rrZtop_kindZ kind_defaultsidxr1r`r]rRr r r rs s<           zSignature.__init__cCs#tjdtddt||S)z3Constructs Signature for the given python function.zNinspect.Signature.from_function() is deprecated, use Signature.from_callable()rr)rrrr)rQrjr r r from_function s  zSignature.from_functioncCs#tjdtddt||S)z4Constructs Signature for the given builtin function.zMinspect.Signature.from_builtin() is deprecated, use Signature.from_callable()rr)rrrr)rQrjr r r from_builtin s  zSignature.from_builtinfollow_wrappedcCst|d|d|S)z3Constructs Signature for the given callable object.rr)r )rQr_rr r r from_callable szSignature.from_callablecCs|jS)N)r)rr r r r$ szSignature.parameterscCs|jS)N)r)rr r r r" szSignature.return_annotationr$cCsF|tkr|jj}|tkr0|j}t||d|S)zCreates a customized copy of the Signature. Pass 'parameters' and/or 'return_annotation' arguments to override them in the new copy. r")rr$r%rr)rr$r"r r r r7 s    zSignature.replacecCsNtdd|jjD}dd|jjD}|||jfS)Ncss$|]}|jtkr|VqdS)N)r`r*)rPr1r r r r sz(Signature._hash_basis..cSs+i|]!}|jtkr||jqSr )r`r*r])rPr1r r r r[ s z)Signature._hash_basis..)rWr$r%r")rr kwo_paramsr r r _hash_basis s"zSignature._hash_basiscCs:|j\}}}t|j}t|||fS)N)r! frozensetr%r )rrr r"r r r r  szSignature.__hash__cCs9||krdSt|ts#tS|j|jkS)NT)rr!r r!)rr r r r r  s  zSignature.__eq__rFcCset}t|jj}f}t|}xyt|}Wntk rMyt|} Wntk rxPYnX| jtkrPn| j|kr| jt krd} | j d| j} t | d| f}Pnh| jt ks| j tk r | f}Pn=|r| f}Pn*d} | j d| j} t | dYq3Xyt|} Wn!tk rt ddYq3X| jt tfkrt dd| jtkr|g} | j|t| || jNz$missing a required argument: {arg!r}ztoo many positional argumentsz$multiple values for argument {arg!r}z*got an unexpected keyword argument {arg!r})rrr$r%r StopIterationr`r)r]r&rirr+r(rr*rrWrchainrre_bound_arguments_cls)rrrrrr$Z parameters_exZarg_valsZarg_valr1rRr%Z kwargs_paramrr r r _bind s                  zSignature._bindcOs|dj|dd|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. rrN)r&)rrr r r bindm szSignature.bindcOs$|dj|dd|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. rrNrT)r&)rrr r r rt szSignature.bind_partialcCs.t|t|jjfd|jifS)Nr)rrWrr%r)rr r r r{ s zSignature.__reduce__cCs|d|_dS)Nr)r)rrr r r r szSignature.__setstate__cCsdj|jj|S)Nz<{} {}>)rirr})rr r r r szSignature.__repr__c Csg}d}d}x|jjD]}t|}|j}|tkrRd}n|rk|jdd}|tkrd}n%|tkr|r|jdd}|j|q"W|r|jddjdj |}|j t k rt |j }|dj|7}|S)NFTrr;z({})z, z -> {}) r$r%rr`r&rAr)r*rirr"rr8) rr\Zrender_pos_only_separatorZrender_kw_only_separatorr1rr`ZrenderedZannor r r r s0         zSignature.__str__)rr)r}rwrxr|rrrrr%rr#rr[rrrrTr$r"rr7r!r r r&r'rrrrrr r r r r!U s0  2         r!rcCstj|d|S)z/Get a signature object for the passed callable.r)r!r)r_rr r r r srcCs^ddl}ddl}|j}|jddd|jdddd dd |j}|j}|jd \}}}y|j|}} Wn`tk r} z@d j |t | j | } t | d t jtdWYdd} ~ XnX|r5|jd} | }x| D]} t|| }qW| j t jkrdt dd t jtd|jrJt dj |t dj t| t dj | j|| krt dj t| jt| dr=t dj | jn>yt|\}}Wntk r)YnXt dj |t dnt t|dS)z6 Logic for inspecting an object given at command line rNr helpzCThe object to be analysed. It supports the 'module:qualname' syntaxz-dz --detailsaction store_truez9Display info about the module rather than its source coderzFailed to import {} ({}: {})rrrrz#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_argsr partition import_modulerXrirr}printrtstderrexitryrCbuiltin_module_namesZdetailsr __cached__r6rrr+rr)r,rparserrtargetZmod_nameZ has_attrsZattrsr_rr^rRpartspart__rnr r r _main sV              r<r)r| __author__rZdiscollections.abcr(Zenumimportlib.machineryrrrrrrtrrrrrroperatorrrrglobalsZmod_dictZCOMPILER_FLAG_NAMESr?rKrLr6r rrrrrrrrr!r"r$r&r+r-r/r1r3r4r7rNrOrar:rlrqrzrrrrrrrrrrrrrrrXrrrrrrrrr rrrrrr2r5r8r:rrGrJrQrSrWrXrgrhrprq_fieldsrrrvryr{r|r~r rrrrrrrrrrrrrrrrrrrrrZ_WrapperDescriptorallZ_MethodWrapperrr>Z_ClassMethodWrapperr2rrrrrrrrrrrr rrZIntEnumrrr&rr'rr)rr*rr+rrr!rr<r}r r r r sP                                , t !  ;      . I -7      [        )     > 5       0      L    H Q     ` :