a
    lct                     @   s*  d Z ddlmZmZmZ ddlZddlZddlZddlZddl	m
Z
 dZg dZeejZeejZeeejfZd#ddZd	d
 Zdd ZG dd deZG dd deZG dd deZedddZedddZedddZedddZedddZ G dd deZ!G dd  d eZ"G d!d" d"eZ#dS )$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.2+.
    )absolute_importdivisionprint_functionN)OrderedDictz0.3)BoundArguments	Parameter	Signature	signaturec                 C   s8   t | tr0| jdd|fv r | jS | jd | j S t| S )Nbuiltins__builtin__.)
isinstancetype
__module____name__repr)
annotationbase_module r   P/var/www/html/django/DPS/env/lib/python3.9/site-packages/backcall/_signatures.pyformatannotation,   s
    
r   c                 G   sZ   z2| t u rW d S t| |}|D ]}t|||}qW n tyF   Y d S 0 t|tsV|S d S N)r   getattrAttributeErrorr   _NonUserDefinedCallables)clsmethod_namenestedmethnamer   r   r   _get_user_defined_method4   s    

r    c              
   C   s  t | std| t| tjrJt| j}|jt	|j
 dd dS z
| j}W n tyf   Y n0 |durt|S z
| j}W n ty   Y n
0 t|S t| tjrt| S t| tjrt| j}t|j
 }| jpd}| jpi }z|j|i |}W n8 ty6 } zd| }t|W Y d}~n
d}~0 0 |j D ]R\}	}
||	 }|	|v rp|j|
dd||	< n"|jttfvrB|jsB| |	 qB|j| dS d}t| t!rt"t!| d	}|durt|}n:t"| d
}|durt|}nt"| d}|durBt|}n.t| t#sBt"t!| d	d}|durBt|}|durP|S t| tj$rpd| }t|td| dS )z/Get a signature object for the passed callable.z{0!r} is not a callable object   N)
parametersr   z,partial object {0!r} has incorrect argumentsT)default_partial_kwarg__call____new____init__Zim_funcz-no signature found for builtin function {0!r}z,callable {0!r} is not supported by signature)%callable	TypeErrorformatr   types
MethodTyper	   __func__replacetupler"   values__signature__r   __wrapped__FunctionTyper   from_function	functoolspartialfuncr   itemsargskeywordsbind_partial
ValueError	argumentskind_VAR_KEYWORD_VAR_POSITIONALr$   popr   r    r   BuiltinFunctionType)objsigwrapped
new_paramspartial_argspartial_keywordsbaexmsgZarg_name	arg_valueparamcallnewinitr   r   r   r	   D   sx    



















r	   c                   @   s   e Zd ZdZdS )_voidz0A private marker - used in Parameter & SignatureN)r   r   __qualname____doc__r   r   r   r   rQ      s   rQ   c                   @   s   e Zd ZdS )_emptyN)r   r   rR   r   r   r   r   rT      s   rT   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_ParameterKindc                 O   s    t j| g|R  }|d |_|S )Nr   )intr&   _name)selfr9   kwargsrC   r   r   r   r&      s    
z_ParameterKind.__new__c                 C   s   | j S r   rW   rX   r   r   r   __str__   s    z_ParameterKind.__str__c                 C   s   d | jS )Nz<_ParameterKind: {0!r}>)r*   rW   r[   r   r   r   __repr__   s    z_ParameterKind.__repr__N)r   r   rR   r&   r\   r]   r   r   r   r   rU      s   rU   POSITIONAL_ONLYr   r!   POSITIONAL_OR_KEYWORD   VAR_POSITIONAL   KEYWORD_ONLY   VAR_KEYWORDc                   @   s   e Zd ZdZdZeZeZe	Z
eZeZeZeedfddZedd Zedd	 Zed
d Zedd ZeeeeefddZdd Zdd Zdd Zdd Zdd ZdS )r   a  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`.
    )rW   _kind_default_annotationr$   Fc                 C   s   |t ttttfvrtd|| _|turF|ttfv rFd|}t||| _	|| _
|d u rr|t krjtd|| _n8t|}|t krtd|tjsd|}t||| _|| _d S )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)_POSITIONAL_ONLY_POSITIONAL_OR_KEYWORDr@   _KEYWORD_ONLYr?   r<   rg   rT   r*   rh   ri   rW   strrematchIr$   )rX   r   r>   r#   r   r$   rK   r   r   r   r'      s*    

zParameter.__init__c                 C   s   | j S r   rZ   r[   r   r   r   r     s    zParameter.namec                 C   s   | j S r   )rh   r[   r   r   r   r#     s    zParameter.defaultc                 C   s   | j S r   )ri   r[   r   r   r   r     s    zParameter.annotationc                 C   s   | j S r   )rg   r[   r   r   r   r>     s    zParameter.kindc                 C   s\   |t u r| j}|t u r| j}|t u r*| j}|t u r8| j}|t u rF| j}t| |||||dS )z+Creates a customized copy of the Parameter.)r#   r   r$   )rQ   rW   rg   ri   rh   r$   r   )rX   r   r>   r   r#   r$   r   r   r   r.     s    zParameter.replacec                 C   s   | j }| j}|tkr*|d u r d}d|}| jturFd|t| j}| jturbd|t| j}|t	krtd| }n|t
krd| }|S )N z<{0}>z{0}:{1}z{0}={1}*z**)r>   rW   rj   r*   ri   rT   r   rh   r   r@   r?   )rX   r>   	formattedr   r   r   r\   1  s"    



zParameter.__str__c                 C   s   d | jjt| | jS )Nz<{0} at {1:#x} {2!r}>)r*   	__class__r   idr   r[   r   r   r   r]   I  s    

zParameter.__repr__c                 C   s   d | jj}t|d S Nzunhashable type: '{0}'r*   rt   r   r)   rX   rK   r   r   r   __hash__M  s    zParameter.__hash__c                 C   s<   t |jto:| j|jko:| j|jko:| j|jko:| j|jkS r   )
issubclassrt   r   rW   rg   rh   ri   rX   otherr   r   r   __eq__Q  s    



zParameter.__eq__c                 C   s   |  | S r   r}   r{   r   r   r   __ne__X  s    zParameter.__ne__N)r   r   rR   rS   	__slots__rj   r^   rk   r`   r@   rb   rl   rd   r?   rf   rT   emptyr'   propertyr   r#   r   r>   rQ   r.   r\   r]   ry   r}   r   r   r   r   r   r      s6   





r   c                   @   sT   e Zd ZdZdd Zedd Zedd Zedd	 Zd
d Z	dd Z
dd ZdS )r   a  Result 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.
    c                 C   s   || _ || _d S r   )r=   
_signature)rX   r	   r=   r   r   r   r'   m  s    zBoundArguments.__init__c                 C   s   | j S r   )r   r[   r   r   r   r	   q  s    zBoundArguments.signaturec              	   C   s   g }| j j D ]h\}}|jttfv s,|jr0 qzz| j| }W n tyV   Y  qzY q0 |jt	krn|
| q|| qt|S r   )r   r"   r8   r>   r?   rl   r$   r=   KeyErrorr@   extendappendr/   )rX   r9   
param_namerM   argr   r   r   r9   u  s    
zBoundArguments.argsc              	   C   s   i }d}| j j D ]|\}}|sJ|jttfv s4|jr:d}n|| jvrJd}q|sPqz| j| }W n typ   Y q0 |jtkr|	| q|||< q|S )NFT)
r   r"   r8   r>   r?   rl   r$   r=   r   update)rX   rY   kwargs_startedr   rM   r   r   r   r   rY     s*    


zBoundArguments.kwargsc                 C   s   d | jj}t|d S rv   rw   rx   r   r   r   ry     s    zBoundArguments.__hash__c                 C   s$   t |jto"| j|jko"| j|jkS r   )rz   rt   r   r	   r=   r{   r   r   r   r}     s
    

zBoundArguments.__eq__c                 C   s   |  | S r   r~   r{   r   r   r   r     s    zBoundArguments.__ne__N)r   r   rR   rS   r'   r   r	   r9   rY   ry   r}   r   r   r   r   r   r   \  s   


r   c                   @   s   e Zd ZdZdZeZeZe	Z
de	dfddZedd Zed	d
 Zedd ZeefddZdd Zdd Zdd ZdddZdd Zdd Zdd ZdS )r   a  A 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_parametersNTc                 C   s   |du rt  }n|rt  }t}t|D ]z\}}|j}||k rXd}	|	||j}	t|	n|}|j}
|
du r~t|}
|j|
d}|
|v rd|
}	t|	|||
< q&nt dd |D }|| _	|| _
dS )zConstructs Signature from the given list of Parameter
        objects and 'return_annotation'.  All arguments are optional.
        Nz%wrong parameter order: {0} before {1}r_   zduplicate parameter name: {0!r}c                 s   s   | ]}|j |fV  qd S r   r_   ).0rM   r   r   r   	<genexpr>  s   z%Signature.__init__.<locals>.<genexpr>)r   rj   	enumerater>   r*   r<   r   rm   r.   r   r   )rX   r"   return_annotation__validate_parameters__paramstop_kindidxrM   r>   rK   r   r   r   r   r'     s2    

zSignature.__init__c              	   C   s  t |tjstd|| j}|j}|j}|j}t	|d| }t
|dd}||||  }t
|di }	|j}
t
|dd}|
rt|
}nd}g }|| }|d| D ]$}|	|t}||||td qt||d D ].\}}|	|t}||||t|
| d q|jd	@ rD|||  }|	|t}||||td |D ]B}t}|durf||t}|	|t}||||t|d qH|jd
@ r|| }|jd	@ r|d7 }|| }|	|t}||||td | ||	dtddS )z2Constructs Signature for the given python functionz{0!r} is not a Python functionNco_kwonlyargcountr   __annotations____kwdefaults__)r   r>   )r   r>   r#   re      r!   returnF)r   r   )r   r+   r3   r)   r*   _parameter_cls__code__co_argcountco_varnamesr/   r   __defaults__lengetrT   r   rk   r   co_flagsr@   rl   r?   )r   r7   r   	func_code	pos_count	arg_names
positionalkeyword_only_countkeyword_onlyannotationsdefaults
kwdefaultspos_default_countr"   non_default_countr   r   offsetr#   indexr   r   r   r4     sp    









zSignature.from_functionc                 C   s4   zt | jW S  ty.   t| j  Y S 0 d S r   )r+   MappingProxyTyper   r   r   r8   r[   r   r   r   r"   J  s    zSignature.parametersc                 C   s   | j S r   )r   r[   r   r   r   r   Q  s    zSignature.return_annotationc                 C   s0   |t u r| j }|t u r | 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   )rQ   r"   r0   r   r   )rX   r"   r   r   r   r   r.   U  s    
zSignature.replacec                 C   s   d | jj}t|d S rv   rw   rx   r   r   r   ry   d  s    zSignature.__hash__c              	   C   s   t t|tr.| j|jks.t| jt|jkr2dS tdd t|j D }t| j	 D ]\}\}}|j
tkrz|j| }W n ty   Y  dS 0 ||kr dS q\z|| }W n ty   Y  dS 0 ||ks||j| kr\ dS q\dS )NFc                 s   s   | ]\}}||fV  qd S r   r   )r   r   rM   r   r   r   r   n  s   z#Signature.__eq__.<locals>.<genexpr>T)rz   r   r   r   r   r"   dictr   keysr8   r>   rl   r   )rX   r|   Zother_positionsr   r   rM   Zother_paramZ	other_idxr   r   r   r}   h  s4    



zSignature.__eq__c                 C   s   |  | S r   r~   r{   r   r   r   r     s    zSignature.__ne__Fc                 C   s  t  }t| j }d}t|}|rP| j D ] \}}	|	jr.||vr.|	j||< q.zt|}
W n ty8   zt|}	W n ty   Y Y qY n0 |	j	t
krY qn|	j|v r|	j	tkrd}|j|	jd}t||	f}Y qnR|	j	tks|	jtur|	f}Y qn.|r|	f}Y qnd}|j|	jd}t|Y qP0 zt|}	W n tyb   tdY qP0 |	j	ttfv r|td|	j	t
kr|
g}|| t|||	j< q|	j|v rtdj|	jd|
||	j< qPd}t||D ]}	|	j	tkrtdj|	jd|	j	tkr|	}q|	j}z||}
W nB typ   |sl|	j	t
krl|	jtu rltdj|dY n
0 |
||< q|r|dur|||j< ntd| | |S )	z$Private method.  Don't use directly.r   zA{arg!r} parameter is positional only, but was passed as a keyword)r   z'{arg!r} parameter lacking default valueztoo many positional argumentsz$multiple values for argument {arg!r}Nztoo many keyword arguments)r   iterr"   r0   r8   r$   r#   nextStopIterationr>   r@   r   rj   r*   r)   r?   rT   rl   r   r/   	itertoolschainrA   r   _bound_arguments_cls)rX   r9   rY   r6   r=   r"   parameters_exarg_valsr   rM   arg_valrK   r0   kwargs_paramr   r   r   _bind  s    





zSignature._bindc                 O   s   |  ||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.
        r   rX   r9   rY   r   r   r   bind	  s    zSignature.bindc                 O   s   | j ||ddS )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.
        T)r6   r   r   r   r   r   r;     s    zSignature.bind_partialc           	      C   s   g }d}t | j D ]H\}}t|}|j}|tkr:d}n|tkrT|rT|d d}|| qdd	|}| j
turt| j
}|d|7 }|S )NTFrr   z({0})z, z -> {0})r   r"   r0   rm   r>   r@   rl   r   r*   joinr   rT   r   )	rX   resultrender_kw_only_separatorr   rM   rs   r>   renderedannor   r   r   r\     s     


zSignature.__str__)F)r   r   rR   rS   r   r   r   r   r   rT   r   r'   classmethodr4   r   r"   r   rQ   r.   ry   r}   r   r   r   r;   r\   r   r   r   r   r     s.   
&
H


 r   )N)$rS   
__future__r   r   r   r   r5   rn   r+   collectionsr   __version____all__r   r%   _WrapperDescriptorall_MethodWrapperrB   r   r   r    r	   objectrQ   rT   rV   rU   rj   rk   r@   rl   r?   r   r   r   r   r   r   r   <module>   s:   


p a