Viewing File: /opt/alt/python35/lib/python3.5/site-packages/funcsigs/__pycache__/__init__.cpython-35.opt-1.pyc



.Wv@sdZddlmZmZmZddlZddlZddlZddlZyddl	m
Z
Wn"ek
rddlm
Z
YnXddl
mZdddd	gZeejZeejZeeejfZdd
dZdd
Zdd	ZGdddeZGdddeZGdddeZedddZedddZ edddZ!edddZ"edddZ#GdddeZ$Gd ddeZ%Gd!ddeZ&dS)"zFunction signature objects for callables

Back port of Python 3.3's function signature tools from the inspect module,
modified to be compatible with Python 2.6, 2.7 and 3.3+.
)absolute_importdivisionprint_functionN)OrderedDict)__version__BoundArguments	Parameter	Signature	signaturecCsJt|tr@|jdd|fkr.|jS|jd|jSt|S)Nbuiltins__builtin__.)
isinstancetype
__module____name__repr)
annotationZbase_moduler/__init__.pyformatannotations
rcGsvyF|tkrdSt||}x |D]}t|||}q)WWntk
r^dSYnXt|tsr|SdS)N)rgetattrAttributeErrorr_NonUserDefinedCallables)clsZmethod_namenestedmethnamerrr_get_user_defined_method's

	rc$Cst|s!tdj|t|tjrt|j}|jdkrU|St	|j
j}|s|djt
tfkrtd|dj}|ttfkr|dd}n|tk	rtd|jd|Sy
|j}Wntk
rYnX|dk	r"|Sy
|j}Wntk
rCYnXt|St|tjrmtj|St|tjrt|j}t|j
j}|jpf}|j pi}y|j!||}Wn@tk
r}	z dj|}
t|
WYdd}	~	XnXx~|j"jD]m\}}||}
||krk|
jd	|d
d||<q*|
jt
tfkr*|
j#r*|j$|q*W|jd|jSd}t|t%rJt&t%|d}|dk	rt|}qt&|d
}|dk	r t|}qt&|d}|dk	rt|}n?t|t'st&t%|dd}|dk	rt|}|dk	r|jdt	|j
jddSt|tj(rdj|}
t|
tdj|dS)z/Get a signature object for the passed callable.z{0!r} is not a callable objectNrzinvalid method signaturezinvalid argument type
parametersz,partial object {0!r} has incorrect argumentsdefault_partial_kwargT__call____new____init__Zim_funcz-no signature found for builtin function {0!r}z,callable {0!r} is not supported by signature))callable	TypeErrorformatrtypes
MethodTyper
__func____self__tupler valueskind_VAR_KEYWORD
_KEYWORD_ONLY
ValueError_POSITIONAL_OR_KEYWORD_POSITIONAL_ONLY_VAR_POSITIONALreplaceZ
__signature__r__wrapped__FunctionTyper	
from_function	functoolspartialfuncritemsargskeywordsbind_partial	argumentsr"poprrrBuiltinFunctionType)objsigparamsr/wrappedZ
new_paramsZpartial_argsZpartial_keywordsZbaexmsgZarg_nameZ	arg_valueparamcallnewZinitrrrr
7s 








)c@seZdZdZdS)_voidz0A private marker - used in Parameter & SignatureN)rr__qualname____doc__rrrrrMsrMc@seZdZdS)_emptyN)rrrNrrrrrPsrPc@s4eZdZddZddZddZdS)_ParameterKindcOs#tj||}|d|_|S)Nr)intr$_name)selfr>kwargsrDrrrr$s
z_ParameterKind.__new__cCs|jS)N)rS)rTrrr__str__sz_ParameterKind.__str__cCsdj|jS)Nz<_ParameterKind: {0!r}>)r(rS)rTrrr__repr__sz_ParameterKind.__repr__N)rrrNr$rVrWrrrrrQsrQrPOSITIONAL_ONLYrPOSITIONAL_OR_KEYWORDVAR_POSITIONALKEYWORD_ONLYVAR_KEYWORDc@seZdZdZdZeZeZe	Z
eZe
ZeZeeddd	Zed
dZedd
ZeddZeddZeeeeeddZddZddZddZddZddZdS) 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 not set.
    * annotation
        The annotation for the parameter if specified.  If the
        parameter has no annotation, this attribute is not set.
    * 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`.
    rS_kind_default_annotationr"FcCs
|tttttfkr'td||_|tk	ri|ttfkridj|}t|||_	||_
|dkr|tkrtd||_nUt|}|tkrt
jd|t
jrdj|}t|||_||_dS)Nz,invalid value for 'Parameter.kind' attributez){0} parameters cannot have default valuesz<None is not a valid name for a non-positional-only parameterz
[a-z_]\w*$z#{0!r} is not a valid parameter name)r4r3r5r1r0r2r`rPr(rarbrSstrrematchIr")rTrr/r!rr"rIrrrr%s(				%	zParameter.__init__cCs|jS)N)rS)rTrrrrszParameter.namecCs|jS)N)ra)rTrrrr!szParameter.defaultcCs|jS)N)rb)rTrrrrszParameter.annotationcCs|jS)N)r`)rTrrrr/!szParameter.kindc	Cs|tkr|j}|tkr*|j}|tkr?|j}|tkrT|j}|tkri|j}t|||d|d|d|S)z+Creates a customized copy of the Parameter.r!rr")rMrSr`rbrar"r)rTrr/rr!r"rrrr6%s					zParameter.replacecCs|j}|j}|tkr?|dkr0d}dj|}|jtk	ridj|t|j}|jtk	rdj|t|j}|t	krd|}n|t
krd|}|S)Nz<{0}>z{0}:{1}z{0}={1}*z**)r/rSr4r(rbrPrrarr5r0)rTr/	formattedrrrrV;s 			

zParameter.__str__cCs"dj|jjt||jS)Nz<{0} at {1:#x} {2!r}>)r(	__class__ridr)rTrrrrWSszParameter.__repr__cCs%dj|jj}t|dS)Nzunhashable type: '{0}')r(rjrr')rTrIrrr__hash__WszParameter.__hash__cCsXt|jtoW|j|jkoW|j|jkoW|j|jkoW|j|jkS)N)
issubclassrjrrSr`rarb)rTotherrrr__eq__[s
zParameter.__eq__cCs|j|S)N)ro)rTrnrrr__ne__bszParameter.__ne__N)z_namez_kindz_defaultz_annotationz_partial_kwarg)rrrNrO	__slots__r4rXr3rYr5r[r1r]r0r_rPemptyr%propertyrr!rr/rMr6rVrWrlrorprrrrrs*	c@s|eZdZdZddZeddZeddZedd	Zd
dZ	dd
Z
ddZdS)raResult 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)rA
_signature)rTr
rArrrr%ws	zBoundArguments.__init__cCs|jS)N)rt)rTrrrr
{szBoundArguments.signaturecCsg}x|jjjD]~\}}|jttfksC|jrDPy|j|}Wntk
rjPYqX|jt	kr|j
|q|j|qWt|S)N)
rtr r=r/r0r1r"rAKeyErrorr5extendappendr-)rTr>
param_namerJargrrrr>s	
zBoundArguments.argscCsi}d}x|jjjD]\}}|sp|jttfksO|jrXd}n||jkrpd}q|syqy|j|}Wntk
rYqX|jtkr|j	|q|||<qW|S)NFT)
rtr r=r/r0r1r"rAruupdate)rTrUZkwargs_startedrxrJryrrrrUs(		
zBoundArguments.kwargscCs%dj|jj}t|dS)Nzunhashable type: '{0}')r(rjrr')rTrIrrrrlszBoundArguments.__hash__cCs4t|jto3|j|jko3|j|jkS)N)rmrjrr
rA)rTrnrrrroszBoundArguments.__eq__cCs|j|S)N)ro)rTrnrrrrpszBoundArguments.__ne__N)rrrNrOr%rsr
r>rUrlrorprrrrrfsc@seZdZdZdZeZeZe	Z
de	dddZedd	Z
ed
dZedd
ZeeddZddZddZddZdddZddZddZddZdS) 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 not set.
    * 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_parametersNTcCs%|dkrt}n|rt}t}xt|D]\}}|j}||krd}	|	j||j}	t|	n|}|j}
|
dkrt|}
|jd|
}|
|krdj|
}	t|	|||
<q:Wntdd|D}||_	||_
dS)zConstructs Signature from the given list of Parameter
        objects and 'return_annotation'.  All arguments are optional.
        Nz%wrong parameter order: {0} before {1}rzduplicate parameter name: {0!r}css|]}|j|fVqdS)N)r).0rJrrr	<genexpr>sz%Signature.__init__.<locals>.<genexpr>)rr4	enumerater/r(r2rrcr6r|r{)rTr return_annotation__validate_parameters__rFZtop_kindidxrJr/rIrrrrr%s0			
	zSignature.__init__cCst|tjs'tdj||j}|j}|j}|j}t	|d|}t
|dd}||||}t
|di}	|j}
t
|dd}|
rt|
}nd}g}
||}xI|d|D]7}|	j
|t}|
j||d|dtqWx_t||dD]G\}}|	j
|t}|
j||d|dtd	|
|qBW|jd
@r|||}|	j
|t}|
j||d|dtxi|D]a}t}|dk	r
|j
|t}|	j
|t}|
j||d|dtd	|qW|jd@r||}|jd
@rs|d7}||}|	j
|t}|
j||d|dt||
d
|	j
dtddS)z2Constructs Signature for the given python functionz{0!r} is not a Python functionNco_kwonlyargcountr__annotations____kwdefaults__rr/r!r^rrreturnrF)rr)r8r'r(_parameter_cls__code__co_argcountco_varnamesr-r__defaults__lengetrPrwr3rco_flagsr5r1r0)rr<rZ	func_codeZ	pos_countZ	arg_namesZ
positionalZkeyword_only_countZkeyword_onlyZannotationsZdefaultsZ
kwdefaultsZpos_default_countr Znon_default_countrroffsetr!indexrrrr9sd					
#








	zSignature.from_functioncCs@ytj|jSWn%tk
r;t|jjSYnXdS)N)r)MappingProxyTyper|rrr=)rTrrrr Ts
zSignature.parameterscCs|jS)N)r{)rTrrrr[szSignature.return_annotationcCsF|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)rMr r.r{r)rTr rrrrr6_s	zSignature.replacecCs%dj|jj}t|dS)Nzunhashable type: '{0}')r(rjrr')rTrIrrrrlnszSignature.__hash__cCs8tt|tsF|j|jksFt|jt|jkrJdStddt|jjD}xt|jj	D]\}\}}|j
tkry|j|}Wntk
rdSYq0X||kr0dSqy||}Wntk
rdSYqX||ks,||j|krdSqWdS)NFcss!|]\}}||fVqdS)Nr)r}rrJrrrr~xsz#Signature.__eq__.<locals>.<genexpr>T)
rmrr	rrr dictrkeysr=r/r1ru)rTrnZother_positionsrrxrJZother_paramZ	other_idxrrrrors,(
	
	zSignature.__eq__cCs|j|S)N)ro)rTrnrrrrpszSignature.__ne__FcCsut}t|jj}f}t|}|rxx?|jjD].\}}	|	jrF||krF|	j||<qFWxyt|}
Wntk
ryt|}	Wntk
rPYnX|	j	t
krPn|	j|kr&|	j	tkrd}|j
d|	j}t||	f}Pne|	j	tksD|	jtk	rQ|	f}Pn:|rd|	f}Pn'd}|j
d|	j}t|Yq{Xyt|}	Wntk
rtdYq{X|	j	ttfkrtd|	j	t
kr|
g}|j|t|||	j<P|	j|krEtdj
d|	j|
||	j<q{Wd}
xtj||D]}	|	j	tkrtdj
d|	j|	j	tkr|	}
qo|	j}y|j|}
WnOtk
r$|r |	j	t
kr |	jtkr tdj
d|YqoX|
||<qoW|re|
dk	rU|||
j<ntd||j||S)z$Private method.  Don't use directly.zA{arg!r} parameter is positional only, but was passed as a keywordryz'{arg!r} parameter lacking default valueztoo many positional argumentsz$multiple values for argument {arg!r}Nztoo many keyword arguments %r)riterr r.r=r"r!next
StopIterationr/r5rr4r(r'r0rPr1rvr-	itertoolschainrBru_bound_arguments_cls)rTr>rUr;rAr Z
parameters_exZarg_valsrxrJZarg_valrIr.Zkwargs_paramrrr_binds	

			
	
	
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)r>rUrrrbindszSignature.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.
        r;T)r)rTr>rUrrrr@szSignature.bind_partialc	Csg}d}xt|jjD]h\}}t|}|j}|tkrXd}n%|tkr}|r}|jdd}|j|q"Wdjdj	|}|j
tk	rt|j
}|dj|7}|S)NTFrhz({0})z, z -> {0})
rr r.rcr/r5r1rwr(joinrrPr)	rTresultZrender_kw_only_separatorrrJrir/ZrenderedZannorrrrV!s "		
zSignature.__str__)z_return_annotationz_parameters)rrrNrOrqrrrrrPrrr%classmethodr9rsr rrMr6rlrorprrr@rVrrrrr	s$%I)'rOZ
__future__rrrrr:rdr)collectionsrImportErrorZordereddictZfuncsigs.versionr__all__rr#Z_WrapperDescriptorallZ_MethodWrapperrCrrrr
objectrMrPrRrQr4r3r5r1r0rrr	rrrr<module>s<

a
Back to Directory File Manager