Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/funcsigs/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/funcsigs/__pycache__/__init__.cpython-35.pyc



�.W�v�@s�dZddlmZmZmZddlZddlZddlZddlZyddl	m
Z
Wn"ek
r�ddlm
Z
YnXddl
mZdddd	gZeej�Zeej�ZeeejfZdd
d�Zdd
�Zdd	�ZGdd�de�ZGdd�de�ZGdd�de�Zeddd�Zeddd�Z eddd�Z!eddd�Z"eddd�Z#Gdd�de�Z$Gd d�de�Z%Gd!d�de�Z&dS)"z�Function 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_import�division�print_functionN)�OrderedDict)�__version__�BoundArguments�	Parameter�	Signature�	signaturecCsJt|t�r@|jdd|fkr.|jS|jd|jSt|�S)N�builtinsZ__builtin__�.)�
isinstance�type�
__module__�__name__�repr)�
annotation�base_module�r�B/opt/alt/python35/lib/python3.5/site-packages/funcsigs/__init__.py�formatannotations
rcGsvyF|tkrdSt||�}x |D]}t|||�}q)WWntk
r^dSYnXt|t�sr|SdS)N)r�getattr�AttributeErrorr
�_NonUserDefinedCallables)�cls�method_name�nested�meth�namerrr�_get_user_defined_method's

	rc$Cst|�s!tdj|���t|tj�r�t|j�}|jdkrU|St	|j
j��}|s�|djt
tfkr�td��|dj}|ttfkr�|dd�}n|tk	r�td��|jd|�Sy
|j}Wntk
rYnX|dk	r"|Sy
|j}Wntk
rCYnXt|�St|tj�rmtj|�St|tj�r�t|j�}t|j
j��}|jp�f}|j p�i}y|j!||�}Wn@tk
r}	z dj|�}
t|
��WYdd}	~	XnXx~|j"j�D]m\}}||}
||krk|
jd	|d
d�||<q*|
jt
tfkr*|
j#r*|j$|�q*W|jd|j��Sd}t|t%�rJt&t%|�d�}|dk	r�t|�}q�t&|d
�}|dk	r t|�}q�t&|d�}|dk	r�t|�}n?t|t'�s�t&t%|�dd�}|dk	r�t|�}|dk	r�|jdt	|j
j��dd��St|tj(�r�dj|�}
t|
��tdj|���dS)z/Get a signature object for the passed callable.z{0!r} is not a callable objectNrzinvalid method signature�zinvalid argument type�
parametersz,partial object {0!r} has incorrect arguments�default�_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�	TypeError�formatr
�types�
MethodTyper
�__func__�__self__�tupler!�values�kind�_VAR_KEYWORD�
_KEYWORD_ONLY�
ValueError�_POSITIONAL_OR_KEYWORD�_POSITIONAL_ONLY�_VAR_POSITIONAL�replace�
__signature__r�__wrapped__�FunctionTyper	�
from_function�	functools�partial�funcr�items�args�keywords�bind_partial�	argumentsr#�poprrr�BuiltinFunctionType)�obj�sig�paramsr0�wrapped�
new_params�partial_args�partial_keywords�ba�ex�msgZarg_name�	arg_value�param�call�new�initrrrr
7s� 








)c@seZdZdZdS)�_voidz0A private marker - used in Parameter & SignatureN)rr�__qualname__�__doc__rrrrrU�srUc@seZdZdS)�_emptyN)rrrVrrrrrX�srXc@s4eZdZdd�Zdd�Zdd�ZdS)�_ParameterKindcOs#tj||�}|d|_|S)Nr)�intr%�_name)�selfr@�kwargsrFrrrr%�s
z_ParameterKind.__new__cCs|jS)N)r[)r\rrr�__str__�sz_ParameterKind.__str__cCsdj|j�S)Nz<_ParameterKind: {0!r}>)r)r[)r\rrr�__repr__�sz_ParameterKind.__repr__N)rrrVr%r^r_rrrrrY�srYr�POSITIONAL_ONLYr �POSITIONAL_OR_KEYWORD��VAR_POSITIONAL��KEYWORD_ONLY��VAR_KEYWORDc@s�eZdZdZdZeZeZe	Z
eZe
ZeZeeddd	�Zed
d��Zedd
��Zedd��Zedd��Zeeeeedd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS) ra�Represents 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`.
    r[�_kind�_default�_annotationr#FcCs
|tttttfkr'td��||_|tk	ri|ttfkridj|�}t|��||_	||_
|dkr�|tkr�td��||_nUt|�}|tkr�t
jd|t
j�r�dj|�}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)r5r4r6r2r1r3rhrXr)rirjr[�str�re�match�Ir#)r\rr0r"rr#rOrrrr&�s(				%	zParameter.__init__cCs|jS)N)r[)r\rrrrszParameter.namecCs|jS)N)ri)r\rrrr"szParameter.defaultcCs|jS)N)rj)r\rrrrszParameter.annotationcCs|jS)N)rh)r\rrrr0!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#)rUr[rhrjrir#r)r\rr0rr"r#rrrr7%s					zParameter.replacecCs�|j}|j}|tkr?|dkr0d}dj|�}|jtk	ridj|t|j��}|jtk	r�dj|t|j��}|t	kr�d|}n|t
kr�d|}|S)N�z<{0}>z{0}:{1}z{0}={1}�*z**)r0r[r5r)rjrXrrirr6r1)r\r0�	formattedrrrr^;s 			

zParameter.__str__cCs"dj|jjt|�|j�S)Nz<{0} at {1:#x} {2!r}>)r)�	__class__r�idr)r\rrrr_SszParameter.__repr__cCs%dj|jj�}t|��dS)Nzunhashable type: '{0}')r)rrrr()r\rOrrr�__hash__WszParameter.__hash__cCsXt|jt�oW|j|jkoW|j|jkoW|j|jkoW|j|jkS)N)�
issubclassrrrr[rhrirj)r\�otherrrr�__eq__[s
zParameter.__eq__cCs|j|�S)N)rw)r\rvrrr�__ne__bszParameter.__ne__N)r[rhrirjr#)rrrVrW�	__slots__r5r`r4rar6rcr2rer1rgrX�emptyr&�propertyrr"rr0rUr7r^r_rtrwrxrrrrr�s*	c@s|eZdZdZdd�Zedd��Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�ZdS)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)rC�
_signature)r\r
rCrrrr&ws	zBoundArguments.__init__cCs|jS)N)r|)r\rrrr
{szBoundArguments.signaturecCs�g}x�|jjj�D]~\}}|jttfksC|jrDPy|j|}Wntk
rjPYqX|jt	kr�|j
|�q|j|�qWt|�S)N)
r|r!r?r0r1r2r#rC�KeyErrorr6�extend�appendr.)r\r@�
param_namerQ�argrrrr@s	
zBoundArguments.argscCs�i}d}x�|jjj�D]�\}}|sp|jttfksO|jrXd}n||jkrpd}q|syqy|j|}Wntk
r�YqX|jtkr�|j	|�q|||<qW|S)NFT)
r|r!r?r0r1r2r#rCr}�update)r\r]�kwargs_startedr�rQr�rrrr]�s(		
zBoundArguments.kwargscCs%dj|jj�}t|��dS)Nzunhashable type: '{0}')r)rrrr()r\rOrrrrt�szBoundArguments.__hash__cCs4t|jt�o3|j|jko3|j|jkS)N)rurrrr
rC)r\rvrrrrw�szBoundArguments.__eq__cCs|j|�S)N)rw)r\rvrrrrx�szBoundArguments.__ne__N)rrrVrWr&r{r
r@r]rtrwrxrrrrrfsc@s�eZdZdZdZeZeZe	Z
de	ddd�Zedd	��Z
ed
d��Zedd
��Zeedd�Zdd�Zdd�Zdd�Zddd�Zdd�Zdd�Zdd�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 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�|r�t�}t}x�t|�D]�\}}|j}||kr�d}	|	j||j�}	t|	��n|}|j}
|
dkr�t|�}
|jd|
�}|
|kr�dj|
�}	t|	��|||
<q:Wntdd�|D��}||_	||_
dS)z�Constructs 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)�.0rQrrr�	<genexpr>sz%Signature.__init__.<locals>.<genexpr>)rr5�	enumerater0r)r3rrkr7r�r�)r\r!�return_annotation�__validate_parameters__rH�top_kind�idxrQr0rOrrrrr&�s0			
	zSignature.__init__cCs�t|tj�s'tdj|���|j}|j}|j}|j}t	|d|��}t
|dd�}||||�}t
|di�}	|j}
t
|dd�}|
r�t|
�}nd}g}
||}xI|d|�D]7}|	j
|t�}|
j||d|dt��q�Wx_t||d��D]G\}}|	j
|t�}|
j||d|dtd	|
|��qBW|jd
@r�|||}|	j
|t�}|
j||d|dt��xi|D]a}t}|dk	r
|j
|t�}|	j
|t�}|
j||d|dtd	|��q�W|jd@r�||}|jd
@rs|d7}||}|	j
|t�}|
j||d|dt��||
d
|	j
dt�dd�S)z2Constructs Signature for the given python functionz{0!r} is not a Python functionN�co_kwonlyargcountr�__annotations__�__kwdefaults__rr0r"rf�r r��returnr�F)r
r*r:r(r)�_parameter_cls�__code__�co_argcount�co_varnamesr.r�__defaults__�len�getrXrr4r��co_flagsr6r2r1)rr>r�	func_code�	pos_count�	arg_names�
positional�keyword_only_count�keyword_only�annotations�defaults�
kwdefaults�pos_default_countr!�non_default_countrr�offsetr"�indexrrrr;sd					
#








	zSignature.from_functioncCs@ytj|j�SWn%tk
r;t|jj��SYnXdS)N)r*�MappingProxyTyper�rrr?)r\rrrr!Ts
zSignature.parameterscCs|jS)N)r�)r\rrrr�[szSignature.return_annotationcCsF|tkr|jj�}|tkr0|j}t|�|d|�S)z�Creates a customized copy of the Signature.
        Pass 'parameters' and/or 'return_annotation' arguments
        to override them in the new copy.
        r�)rUr!r/r�r)r\r!r�rrrr7_s	zSignature.replacecCs%dj|jj�}t|��dS)Nzunhashable type: '{0}')r)rrrr()r\rOrrrrtnszSignature.__hash__cCs8tt|�t�sF|j|jksFt|j�t|j�krJdStdd�t|jj��D��}x�t|jj	��D]�\}\}}|j
tkr�y|j|}Wntk
r�dSYq0X||kr0dSq�y||}Wntk
rdSYq�X||ks,||j|kr�dSq�WdS)NFcss!|]\}}||fVqdS)Nr)r�r�rQrrrr�xsz#Signature.__eq__.<locals>.<genexpr>T)
rurr	r�r�r!�dictr��keysr?r0r2r})r\rvZother_positionsr�r�rQZother_paramZ	other_idxrrrrwrs,(
	
	zSignature.__eq__cCs|j|�S)N)rw)r\rvrrrrx�szSignature.__ne__FcCsut�}t|jj��}f}t|�}|rxx?|jj�D].\}}	|	jrF||krF|	j||<qFWx�yt|�}
Wntk
r�yt|�}	Wntk
r�PYn�X|	j	t
kr�Pn�|	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
r�td��Yq{X|	j	ttfkr�td��|	j	t
kr|
g}|j|�t|�||	j<P|	j|krEtdj
d|	j���|
||	j<q{Wd}
x�tj||�D]�}	|	j	tkr�tdj
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 keywordr�z'{arg!r} parameter lacking default valueztoo many positional argumentsz$multiple values for argument {arg!r}Nztoo many keyword arguments %r)r�iterr!r/r?r#r"�next�
StopIterationr0r6rr5r)r(r1rXr2r~r.�	itertools�chainrDr}�_bound_arguments_cls)r\r@r]r=rCr!�
parameters_ex�arg_valsr�rQ�arg_valrOr/�kwargs_paramrrr�_bind�s�	

			
	
	
zSignature._bindcOs|dj|dd�|�S)z�Get 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.
        rr N)r�)r@r]rrr�bindszSignature.bindcOs|j||dd�S)z�Get 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�)r\r@r]rrrrBszSignature.bind_partialc	Cs�g}d}xt|jj��D]h\}}t|�}|j}|tkrXd}n%|tkr}|r}|jd�d}|j|�q"Wdjdj	|��}|j
tk	r�t|j
�}|dj|�7}|S)NTFrpz({0})z, z -> {0})
r�r!r/rkr0r6r2rr)�joinr�rXr)	r\�result�render_kw_only_separatorr�rQrqr0�rendered�annorrrr^!s "		
zSignature.__str__)r�r�)rrrVrWryrr�rr�rXrzr&�classmethodr;r{r!r�rUr7rtrwrxr�r�rBr^rrrrr	�s$%I�)'rW�
__future__rrrr�r<rlr*�collectionsr�ImportErrorZordereddictZfuncsigs.versionr�__all__rr$�_WrapperDescriptor�all�_MethodWrapperrErrrr
�objectrUrXrZrYr5r4r6r2r1rrr	rrrr�<module>s<
�
�a