[@sdZddfZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlmZddlmZmZyddlmZWnNek r8dd f\ZZd d f\ZZd d df\ZZZYn5Xe Z!x(ej"D]\Z#Z$e#e!de$Z%ddZ&ddZ'ddZ(ddZ)ddZ*e+e drddZ,n ddZ,e+e drd d!Z-n d"d!Z-d#d$Z.d%d&Z/d'd(Z0d)d*Z1d+d,Z2d-d.Z3d/d0Z4d1d2Z5d3d4Z6dd5d6Z7ed7d8Z8d9d:Z9d;d<Z:d=dd>d?Z;d@dAZ<dBdCZ=dDdEZ>dFdGZ?edHdIZ@dJdKZAdLdMZBdNdOZCddPdQZDiZEiZFddRdSZGdTdUZHdVdWZIGdXdYdYeJZKGdZd[d[ZLd\d]ZMd^d_ZNd`daZOdbdcZPdddedfZQedgdhZRdidjZSdkdlZTedmdnZUdodpZVedqdrZWdsdtZXedudvZYdwdxZZddydzZ[d{d|Z\dddfiie]d}d~dd~dd~dd~e[dd Z^e]dd~dd~dd~ddZ_ddZ`ddZaddZbeddZcddZdeddZedddZfddZgdddZhdddZiddZjdddZkdddZlemZnddZoddZpddZqddZrddZsenddZtdZudZvdZwdZxddZyddZze{e{j|Z}e{e~j|Ze{ejdZe}eee jfZddZfddZddZddZddZddZddZdddZdddZddddZddZGdddZGdddZGdddeZedddZedddZed ddZedddZed ddZGdddZGdddZGdddZddZedkrendS)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-3000 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 OrderedDict)COMPILER_FLAG_NAMES @ZCO_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/usr/lib/python3.4/inspect.pyismoduleDsrcCs 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)rrrrisclassMsrcCst|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)rrrrismethodUsrcCsQt|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)rtprrrismethoddescriptor_s$ 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)rrrrrisdatadescriptorss$ rMemberDescriptorTypecCst|tjS)zReturn true if the object is a member descriptor. Member descriptors are specialized descriptors defined in extension modules.)rrr )rrrrismemberdescriptorsr!cCsdS)zReturn true if the object is a member descriptor. Member descriptors are specialized descriptors defined in extension modules.Fr)rrrrr!sGetSetDescriptorTypecCst|tjS)zReturn true if the object is a getset descriptor. getset descriptors are specialized descriptors defined in extension modules.)rrr")rrrrisgetsetdescriptorsr#cCsdS)zReturn true if the object is a getset descriptor. getset descriptors are specialized descriptors defined in extension modules.Fr)rrrrr#scCst|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)rrrrrs rcCs,tt|st|o(|jjt@S)zReturn true if the object is a user-defined generator function. Generator function objects provides same attributes as functions. See help(isfunction) for attributes listing.)boolrr__code__co_flags CO_GENERATOR)rrrrisgeneratorfunctionsr)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)rrrr isgeneratorsr+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)rrrr 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)rrrrisframes r/cCst|tjS)auReturn true if the object is a code object. Code objects provide these attributes: co_argcount number of arguments (not including * or ** args) co_code string of raw compiled bytecode 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 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)rrrriscodesr1cCst|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)rrrr isbuiltinsr3cCs.t|p-t|p-t|p-t|S)z1szgetmembers..)rgetmrosetdir __bases____dict__itemsrrDynamicClassAttributeappendAttributeErrorgetattraddsort) rZ predicatemroresults processednamesbasekvr8valuerrr getmemberss:          rN Attributezname kind defining_class objectcCst|}tt|}tdd|D}|f|}||}t|}xP|D]H}x?|jjD].\}}t|tjrw|j |qwqwWqaWg} t } xU|D]M} d} d} d}| | kry.| dkrt dnt || } Wn%t k r<}zWYdd}~XqXt | d| } | |krd} d}x5|D]-}t || d}|| krn|}qnqnWxQ|D]I}y|j || }Wntk rwYnX|| kr|}qqW|dk r |} q qnxC|D];}| |jkr|j| }| |krL|} nPqqW| dkrfqn| po|}t|trd}|}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).0clsrrr Ss 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_objobjkindrrrclassify_class_attrs6s                             racCs|jS)zHReturn tuple of base classes (including cls) in method resolution order.)__mro__)rQrrrr:sr:stopcsdkrdd}nfdd}|}t|h}xV||r|j}t|}||krtdj|n|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)frrr _is_wrapperszunwrap.._is_wrappercst|do| S)Nrd)r)re)rcrrrfsz!wrapper loop when unwrapping {!r})idrd ValueErrorformatrD)funcrcrfrememoZid_funcr)rcrunwraps    rlcCs&|j}t|t|jS)zBReturn the indent size, in spaces, at the start of a line of text.) expandtabslenlstrip)lineZexplinerrr indentsizes rqc CsCy |j}Wntk r%dSYnXt|ts9dSt|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)__doc__rBrstrcleandoc)rdocrrrgetdocs   rvc CsOy|jjd}Wntk r1dSYnXtj}xR|ddD]@}t|j}|rLt||}t||}qLqLW|r|dj|d.) warningswarnDeprecationWarningcatch_warnings simplefilterPendingDeprecationWarningimpospathbasenameZ get_suffixesrEr)rrfilenamesuffixesneglenrrrrrr getmoduleinfos    rcCsptjj|}ddtjjD}|jx1|D])\}}|j|r?|d|Sq?WdS)z1Return the module name for a given file, or None.cSs#g|]}t| |fqSr)rn)rPrrrrrR/s z!getmodulename..N)rrr importlib machinery all_suffixesrEendswith)rZfnamerrrrrr getmodulename+s  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)rrr >sz getsourcefile..rc3s|]}j|VqdS)N)r)rPr)rrrrAs __loader__)rrrDEBUG_BYTECODE_SUFFIXESOPTIMIZED_BYTECODE_SUFFIXESanyrrsplitextSOURCE_SUFFIXESEXTENSION_SUFFIXESexistsrC getmodule linecachecache)rZall_bytecode_suffixesr)rr getsourcefile7s !rcCsC|dkr't|p!t|}ntjjtjj|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 _filenamerrr getabsfileMs rc Cs t|r|St|dr2tjj|jS|dk r^|tkr^tjjt|Syt||}Wntk rdSYnX|tkrtjjt|Sxt tjj D]\}}t|rt|dr|j }|t j|dkrqn|t |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)|(.*(?rrrrecompiler~rnmatchrAgrouprErrrr&r-rr/rr1rr) rrrrr]ZpatZ candidatesrrlnumrrr findsources^       #            rc Csyt|\}}Wnttfk r4dSYnXt|rEd}|rp|ddddkrpd}nx6|t|kr||jdkr|d}qsW|t|kr||dddkrg}|}xQ|t|kr4||dddkr4|j||j|d}qWdj|Sn|dkrt ||}|d}|dkr||j dddkrt |||kr||jj g}|dkrk|d}||jj }xv|dddkrgt |||krg|g|dd<|d}|dkrNPn||jj }qWnx0|r|djdkrg|ddsrcCsvg}|jdtddxP|D]H}|j||jf||kr&|jt||||q&q&W|S)z-Recursive helper function for getclasstree().r8rr)rErrAr=walktree)classeschildrenparentrGrrrrrHs  $rFcCsi}g}x|D]}|jrx|jD]Y}||krKg||._formatannotation)rC)rr*r)rrformatannotationrelativetosr+cCsd|S)N*r)r]rrrr9#sr9cCsd|S)Nz**r)r]rrrr9$scCsdt|S)N=)r()rMrrrr9%scCsd|S)Nz -> r)textrrrr9&sc sfdd} g}|r=t|t|}nx`t|D]R\}}| |}|r||kr|| |||}n|j|qJW|dk r|j|| |n|r|jdn|r:xS|D]H}| |}|r&||kr&|| ||7}n|j|qWn|dk rb|j| | |nddj|d}dkr|| d7}n|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.cs7|}|kr3|d|7}n|S)Nz: r)argr\)r r) formatargrrformatargandannotation0s  z-formatargspec..formatargandannotationNr,(z, )r)rn enumeraterAr)rrrr rr r r0 formatvarargs formatvarkw formatvalueZ formatreturnsr)r1specsZ firstdefaultrr/specZ kwonlyargr\r)r r)r0r formatargspec s2      r:cCsd|S)Nr,r)r]rrrr9QscCsd|S)Nz**r)r]rrrr9RscCsdt|S)Nr-)r()rMrrrr9Ssc Cs|||dd}g} x1tt|D]} | j||| q.W|ry| j|||||n|r| j|||||nddj| 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]localsr0r7rrrconvertZsz formatargvalues..convertr2z, r3)r~rnrAr) rrrr;r0r5r6r7r<r8rrrrformatargvaluesOs $$r=csfdd|D}t|}|dkr>|d}nW|dkr\dj|}n9dj|dd}|dd=dj||}td |||rd nd |dkrd nd |fdS)Ncs(g|]}|krt|qSr)r()rPr])rrrrRgs z&_missing_arguments..rrrz {} and {}z , {} and {}z, z*%s() missing %i required %s argument%s: %s positionalz keyword-onlyrrr?)rnrirr)f_nameZargnamesposrrImissingrtailr)rr_missing_argumentsfs     rDc s1t||}tfdd|D}|rQ|dk} d|f} nI|rvd} d|t|f} n$t|dk} tt|} d} |rd} | |dkrd nd||dkrd ndf} ntd || | rd nd|| |dkr | r d nd fdS) Ncs"g|]}|kr|qSrr)rPr/)rrrrRxs 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)rnrsr) r@rZkwonlyrZdefcountZgivenrZatleastZ kwonly_givenZpluralrZ kwonly_sigmsgr)rr _too_manyvs$ rFcOs|d}|dd}t|}|\}}}}} } } |j} i} t|r~|jdk r~|jf|}nt|}t|}|rt|nd}t||}x&t|D]}||| ||r9rrrr rr r r@Z arg2valueZnum_posZnum_argsZ num_defaultsnrZpossible_kwargskwrMZreqr/rBkwargrrr getcallargssd            '   rK ClosureVarsz"nonlocals globals builtins unboundc Cs^t|r|j}nt|s<tdj|n|j}|jdkr]i}n"ddt|j|jD}|j }|j dt j }t |r|j }ni}i}t}x~|jD]s}|d krqny||||s z"getclosurevars.. __builtins__NoneTrueFalse)zNonezTruezFalse)rrrrrir& __closure__zip co_freevars __globals__rrr>rr;co_namesKeyErrorrDrL) rjcodeZ nonlocal_varsZ global_nsZ builtin_nsZ global_varsZ builtin_varsZ unbound_namesr]rrrgetclosurevarss8              rZ Tracebackz+filename lineno function code_context indexcCs5t|r!|j}|j}n |j}t|sNtdj|nt|pct|}|dkr|d|d}yt |\}}Wnt k rd}}YqXt |d}t 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/rrirrrrmaxr}rnr[rco_name)r%contextlinenorrrrindexrrr getframeinfos&       " rccCs|jS)zCGet the line number from a frame object, allowing for optimization.)r])r%rrr getlineno#srdcCs=g}x0|r8|j|ft|||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.)rArcf_back)r%r` framelistrrrgetouterframes(s   rgcCs@g}x3|r;|j|jft|||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.)rArrctb_next)tbr`rfrrrgetinnerframes3s    rjcCs ttdrtjdSdS)z?Return the frame of the caller or None if this is not possible. _getframerN)rr{rkrrrr currentframe>srlcCsttjd|S)z@Return a list of records for the stack above the caller's frame.r)rgr{rk)r`rrrstackBsrmcCsttjd|S)zCReturn a list of records for the stack below the current exception.r)rjr{exc_info)r`rrrtraceFsrocCstjdj|S)Nrb)rr>r)klassrrr_static_getmroOsrqc CsDi}ytj|d}Wntk r0YnXtj||tS)Nr>)r__getattribute__rBdictr _sentinel)r_attrZ instance_dictrrr_check_instanceRs  rvc CsZxSt|D]E}tt|tkr y|j|SWqRtk rNYqRXq q WtS)N)rq_shadowed_dictrrtr>rX)rpruentryrrr _check_class[s  ryc Cs+yt|Wntk r&dSYnXdS)NFT)rqr)r_rrr_is_typeds   rzc Cstjd}xwt|D]i}y|j|d}Wntk rKYqXt|tjko||jdko||j|ks|SqWt S)Nr>) rr>rqrrXrr"rrSrt)rp dict_attrrxZ class_dictrrrrwks  rwc Csut}t|s`t|}t|}|tksKt|tjkrft||}qfn|}t||}|tk r|tk rtt|dtk rtt|dtk r|Sn|tk r|S|tk r|S||krUx\tt|D]E}tt|tkr y|j |SWqNt k rJYqNXq q Wn|tk re|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) rtrzrrwrr rvryrqr>rXrB)r_rurZinstance_resultrpr{Z klass_resultrxrrrgetattr_staticys6          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. Nrrx) gi_runningr~gi_framerf_lastir}r) generatorrrrgetgeneratorstates rcCsTt|s$tdj|nt|dd}|dk rL|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+rrirCrr$)rr%rrrgetgeneratorlocalss    r from_bytesc CsCyt||}Wntk r+dSYnXt|ts?|SdS)N)rCrBr_NonUserDefinedCallables)rQZ method_namemethrrr"_signature_get_user_defined_methods   rcCsE|j}t|j}|jp'f}|jp6i}|rL||}ny|j||}WnCtk r}z#dj|} t| |WYdd}~XnXd} x~|jD]p\} } y|j | } Wnt k rYnX| j t kr|j | qn| j tkr_| |krId} | jd| || .rwFrrTr/$r3z,  r)ryrrrrArOP ERRORTOKENnextrENCODINGrstringr) signatureself_parameterlast_positional_onlyrrZ token_streamZ delayed_commaZskip_next_commar.rDZcurrent_parameterrrtrrclean_signaturerrr"_signature_strip_non_python_syntaxsZ                  rTcsM|jt|\}}}d|d}ytj|}Wntk rYd}YnXt|tjstdj|n|j d} gj t d}it |dd} | rt jj| d}|r|jqnt jddfdd G fd d d tjfd d } t| jj} t| jj} tj| | dd}|dk rjn jxQttt|D]7\}\}}| ||||krjqqW| jjrCj| | jjnjx6t| jj| jj D]\}}| ||qhW| jj!rj"| | jj!n|dk r:st#t |dd}|dk }t$|}|r|s|rj%dq:dj&dj} | d.parse_namecsyt|}WnCtk rXyt|}Wntk rStYnXYnXt|trutj|St|ttfrtj |St|t rtj |S|dkrtj |StdS)NTF)TFN) eval NameError RuntimeErrorrrsrZStrintfloatZNumbytesZBytesZ NameConstant)rrM) module_dictsys_module_dictrr wrap_values        z&_signature_fromstr..wrap_valuecs4eZdZfddZfddZdS)z,_signature_fromstr..RewriteSymbolicscsg}|}x/t|tjr=|j|j|j}qWt|tjs\tn|j|jdj t |}|S)Nr') rrrOrArurMNamerrgrreversed)rrarHrM)rrrvisit_Attribute s  z<_signature_fromstr..RewriteSymbolics.visit_Attributecs.t|jtjs!tn|jS)N)rZctxrZLoadrhrg)rr)rrr visit_Names z7_signature_fromstr..RewriteSymbolics.visit_NameN)rrrrrr)rrrRewriteSymbolicss  rcs|}|krdS|r|tk ry%j|}tj|}Wntk rm}YnX|kr~dS|k r|n|}nj|d|ddS)Nrr)_emptyZvisitrZ literal_evalrhrA)Z name_nodeZ default_noderr]o) Parameterrrinvalidr`rrrrps     z_signature_fromstr..p fillvaluerGr`r)'_parameter_clsrrparse SyntaxErrorrZModulerhriZbodyrrrCr{rrr>ZNodeTransformerrrr  itertools zip_longestPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDr4rZvarargVAR_POSITIONAL KEYWORD_ONLYrTrZ kw_defaultsrJ VAR_KEYWORDrrrr)rQr_rrrrrZprogramrreZ module_namerrr rrr]r_selfZ self_isboundZ self_ismoduler) rrrrr`rrrrrr_signature_fromstrsl        '   +     (       rcCsgt|s$tdj|nt|dd}|sTtdj|nt||||S)Nz%{!r} is not a Python builtin function__text_signature__z#no signature found for builtin {!r})rrrirCrhr)rQrjrrrrr_signature_from_builtinYs  rc!Cs3t|s$tdj|nt|tjrbt|j||}|r[t|S|Sn|rt |ddd}ny |j }Wnt k rYn8X|dk rt|t stdj|n|Sy |j }Wnt k rYnXt|tjr|t|j||}t||d}t|jjd}|ft|jj}|jd|St|st|rt j|St|rtt |d|St|tjrt|j||}t||Sd}t|tr5tt|d }|dk r?t|||}n`t|d } | dk rot| ||}n0t|d } | dk rt| ||}n|dkrxS|jddD]>} y | j} Wnt k rYqX| rt t || SqWt|jkr2|j!t"j!kr/t#t"Sq2qnt|t$stt|d }|dk ryt|||}Wqt%k r} z#d j|}t%|| WYdd} ~ XqXqn|dk r|rt|S|Snt|tj&rdj|}t%|nt%dj|dS)Nz{!r} is not a callable objectrccSs t|dS)N __signature__)r)rerrrr9ysz%_signature_internal..z1unexpected object {!r} in __signature__ attributerrr__call____new__rrzno signature found for {!r}z,no signature found for builtin function {!r}z+callable {!r} is not supported by signature)Nrx)'rrrirrrrrrrlrrB Signature_partialmethod functools partialmethodrjrrWrrrrr from_functionrrrrrrbrrrrrrrhr2)r_rrrrrZfirst_wrapped_paramrcallnewZinitrJZtext_sigrrErrrrgs                            (  rcCs t|S)z/Get a signature object for the passed callable.)r)r_rrrrsrc@seZdZdZdS)rz0A private marker - used in Parameter & SignatureN)rrrrrrrrrr s rc@seZdZdS)rN)rrrrrrrrs rc@s4eZdZddZddZddZdS)_ParameterKindcGstj||}||_|S)N)rr_name)rr]rr_rrrrs z_ParameterKind.__new__cCs|jS)N)r)rrrr__str__sz_ParameterKind.__str__cCsdj|jS)Nz<_ParameterKind: {!r}>)rir)rrrr__repr__sz_ParameterKind.__repr__N)rrrrrrrrrrrs   rr]rrrrrc @seZdZdZdZeZeZe Z e Z e ZeZdededd Zed d Zed d ZeddZeddZdededededdZddZddZddZddZdS) 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`. r_kind_default _annotationrrcCs|tttttfkr*tdn||_|tk rr|ttfkrrdj|}t|qrn||_ ||_ |tkrtdnt |t st dj|n|jstdj|n||_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)rrrrrrhrrrirrrrsr isidentifierr)rr]r`rrrErrrrFs"       zParameter.__init__cCs|jS)N)r)rrrrr]_szParameter.namecCs|jS)N)r)rrrrrcszParameter.defaultcCs|jS)N)r)rrrrrgszParameter.annotationcCs|jS)N)r)rrrrr`kszParameter.kindr]r`cCs|tkr|j}n|tkr0|j}n|tkrH|j}n|tkr`|j}nt|||d|d|S)z+Creates a customized copy of the Parameter.rr)rrrrrr)rr]r`rrrrrros        zParameter.replacecCs|j}|j}|jtk r?dj|t|j}n|jtk rldj|t|j}n|tkrd|}n|t krd|}n|S)Nz{}:{}z{}={}r,z**) r`rrrrir)rr(rr)rr` formattedrrrrs       zParameter.__str__cCs"dj|jjt||jS)Nz<{} at {:#x} {!r}>)ri __class__rrgr])rrrrrszParameter.__repr__cCsXt|jtoW|j|jkoW|j|jkoW|j|jkoW|j|jkS)N) issubclassrrrrrr)rotherrrr__eq__s zParameter.__eq__cCs|j| S)N)r)rrrrr__ne__szParameter.__ne__N)z_namez_kindz_defaultz _annotation)rrrrr __slots__rrrrrrrrrrrrrrTr]rrr`rrrrrrrrrrr&s&    rc@speZdZdZddZeddZeddZedd Zd d Z d d Z dS)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. cCs||_||_dS)N)r _signature)rrrrrrrs zBoundArguments.__init__cCs|jS)N)r)rrrrrszBoundArguments.signaturec Csg}x|jjjD]x\}}|jttfkr>Pny|j|}Wntk rdPYqX|jtkr|j |q|j |qWt |S)N) rrr?r`rrrrXrextendrArW)rrrr"r/rrrrs zBoundArguments.argsc Csi}d}x|jjjD]\}}|sm|jttfkrOd}qm||jkrmd}qqmn|syqny|j|}Wntk rYqX|jtkr|j|q||| 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__validate_parameters__Tc Csg|dkrt}n0|r/t}t}d}xt|D]\}}|j} |j} | |krd} | j|| } t| n| |krd}| }n| ttfkr|jt kr|rd} t| qqd}n| |krdj| } t| n||| .)rrr4r`r]rirhrrrrMappingProxyTyperr) rrrrrZtop_kindZ kind_defaultsidxr"r`r]rErrrr s<            zSignature.__init__c Csd}t|s?t|r'd}q?tdj|n|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|dtnxl| D]d}t}| dk r | j|t}n| j|t}|j||d|dtd|qW|jt@r||}|jt@ry|d 7}n||}| j|t}|j||d|dtn||d | jd td |S) z2Constructs Signature for the given python functionFTz{!r} is not a Python functionNrrr`rrrrr)rrrrirr&rrrWrrrrrnrrrArr4r'rrrrr)rQrjZis_duck_functionrZ func_codeZ pos_countZ arg_namesr>Zkeyword_only_countZ keyword_onlyr r r!Zpos_default_countrZnon_default_countr]roffsetrrbrrrrK sj            #           zSignature.from_functioncCs t||S)N)r)rQrjrrr from_builtin szSignature.from_builtincCs|jS)N)r)rrrrr szSignature.parameterscCs|jS)N)r)rrrrr szSignature.return_annotationrcCsL|tkr|jj}n|tkr6|j}nt||d|S)zCreates a customized copy of the Signature. Pass 'parameters' and/or 'return_annotation' arguments to override them in the new copy. r)rrrrr)rrrrrrr s    zSignature.replacec Cs2tt|t sF|j|jksFt|jt|jkrJdSddt|jjD}xt|jjD]\}\}}|j t kry|j|}Wnt k rdSYq*X||kr*dSqy||}Wnt k rdSYqX||ks&||j|krdSqWdS)NFcSsi|]\}}||qSrr)rPrr"rrrrN s z$Signature.__eq__..T) rrrrrnrr4keysr?r`rrX)rrZother_positionsrrr"Z other_paramZ other_idxrrrr s, (      zSignature.__eq__cCs|j| S)N)r)rrrrrr szSignature.__ne__rFcCsbt}t|jj}f}t|}xyt|}Wn tk rPyt|} Wntk rxPYnX| jtkrPn| j|kr| jt krd} | j d| j} t | dn| f}Pnh| jt ks| j tk r| f}Pn=|r"| f}Pn*d} | j d| j} t | dYq3Xyt|} Wn!tk rt ddYq3X| jt tfkrt dn| jtkr|g} | j|t| || j {}) rrrsr`rrArrrirrrr)) rr\Zrender_pos_only_separatorZrender_kw_only_separatorr"rr`ZrenderedZannorrrre s0          zSignature.__str__)z_return_annotationz _parameters)rrrrrrrrrrrrrr[rrrTrrrrrrrrrrrrrrrs$  2Q    rcCsgddl}ddl}|j}|jddd|jdddd dd |j}|j}|jd \}}}y|j|}} Wn`tk r} z@d j |t | j | } t | d t jtdWYdd} ~ XnX|r8|jd} | }x | D]} t|| }qWn| j t jkrjt dd t jtdn|jrSt dj |t dj t| t dj | j|| krt dj t| jt| drFt dj | jqFn>yt|\}}Wntk r2YnXt dj |t dnt t|dS)z6 Logic for inspecting an object given at command line rNrhelpzCThe 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 {} ({}: {})rrr'z#Can't get info for builtin modules.rz Target: {}z Origin: {}z Cached: {}z Loader: {}__path__zSubmodule search path: {}zLine: {}rw)argparserArgumentParser add_argument parse_argsr partition import_modulerXrirrprintr{stderrexitryrCbuiltin_module_namesZdetailsr __cached__r(rrr rr)r rparserrtargetZmod_nameZ has_attrsZattrsr_rr^rEpartspart__rarrr_main sV              rr)rr __author__rimportlib.machineryrrrrrr{rrrrrroperatorr collectionsrrZdisrZ _flag_names ImportErrorZ CO_OPTIMIZEDZ CO_NEWLOCALSrrZ CO_NESTEDr(Z CO_NOFREEglobalsZmod_dictr?rKrLr6rrrrrrr!r#rr)r+r-r/r1r3r4r7rNrOrar:rlrqrvrtrrrrrrrrrrrrXrrrrrrrrrrrr rr r#r&r)r+rsr:r=rDrFrKrLrZr[rcrdrgrjrlrmrorrtrqrvryrzrwr|r}r~rrrrrrZ_WrapperDescriptorallZ_MethodWrapperrr>Z_ClassMethodWrapperr2rrrrrrrrrrrrrrrrrrrrrrrrrrrrrs8                           , t !       . I -'     X        )     > 5!       0    K    F  }W :