U
    -et                     @   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dddd	g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kr | jS | jd | j S t| S )Nbuiltins__builtin__.)
isinstancetype
__module____name__repr)
annotationbase_module r   U/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/backcall/_signatures.pyformatannotation,   s
    
r   c                 G   s\   z2| t krW d S t| |}|D ]}t|||}qW n tk
rH   Y d S X t|tsX|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k
rh   Y nX |dk	rv|S z
| j}W n tk
r   Y n
X t|S t| tjrt| S t| tjrt| j}t|j
 }| jpd}| jpi }z|j||}W n6 tk
r4 } zd| }t|W 5 d}~X Y nX |j D ]R\}	}
||	 }|	|krn|j|
dd||	< n"|jttfkr@|js@| |	 q@|j| dS d}t| t!rt"t!| d	}|dk	rt|}n:t"| d
}|dk	rt|}nt"| d}|dk	r@t|}n.t| t#s@t"t!| d	d}|dk	r@t|}|dk	rN|S t| tj$rnd| }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msgarg_name	arg_valueparamcallnewinitr   r   r   r	   D   sx    



















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   rR      s   rR   c                   @   s   e Zd ZdS )_emptyN)r   r   rS   r   r   r   r   rU      s   rU   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_ParameterKindc                 O   s   t j| f| }|d |_|S )Nr   )intr&   _name)selfr9   kwargsrC   r   r   r   r&      s    
z_ParameterKind.__new__c                 C   s   | j S r   rX   rY   r   r   r   __str__   s    z_ParameterKind.__str__c                 C   s   d | jS )Nz<_ParameterKind: {0!r}>)r*   rX   r\   r   r   r   __repr__   s    z_ParameterKind.__repr__N)r   r   rS   r&   r]   r^   r   r   r   r   rV      s   rV   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`.
    )rX   _kind_default_annotationr$   Fc                 C   s   |t ttttfkrtd|| _|tk	rF|ttfkrFd|}t||| _	|| _
|d k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<   rh   rU   r*   ri   rj   rX   strrematchIr$   )rY   r   r>   r#   r   r$   rK   r   r   r   r'      s.      

zParameter.__init__c                 C   s   | j S r   r[   r\   r   r   r   r     s    zParameter.namec                 C   s   | j S r   )ri   r\   r   r   r   r#     s    zParameter.defaultc                 C   s   | j S r   )rj   r\   r   r   r   r     s    zParameter.annotationc                 C   s   | j S r   )rh   r\   r   r   r   r>     s    zParameter.kindc                 C   s\   |t kr| j}|t kr| j}|t kr*| j}|t kr8| j}|t krF| j}t| |||||dS )z+Creates a customized copy of the Parameter.)r#   r   r$   )rR   rX   rh   rj   ri   r$   r   )rY   r   r>   r   r#   r$   r   r   r   r.     s    zParameter.replacec                 C   s   | j }| j}|tkr*|d kr d}d|}| jtk	rFd|t| j}| jtk	rbd|t| j}|t	krtd| }n|t
krd| }|S )N z<{0}>z{0}:{1}z{0}={1}*z**)r>   rX   rk   r*   rj   rU   r   ri   r   r@   r?   )rY   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*   ru   r   r)   rY   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   )
issubclassru   r   rX   rh   ri   rj   rY   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   rS   rT   	__slots__rk   r_   rl   ra   r@   rc   rm   re   r?   rg   rU   emptyr'   propertyr   r#   r   r>   rR   r.   r]   r^   rz   r~   r   r   r   r   r   r      s8   




 
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)rY   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 ]j\}}|jttfks,|jr0 q|z| j| }W n tk
rX   Y  q|Y qX |jt	krp|
| q|| qt|S r   )r   r"   r8   r>   r?   rm   r$   r=   KeyErrorr@   extendappendr/   )rY   r9   
param_namerN   argr   r   r   r9   u  s    
zBoundArguments.argsc              	   C   s   i }d}| j j D ]~\}}|sJ|jttfks4|jr:d}n|| jkrJd}q|sPqz| j| }W n tk
rr   Y qX |jtkr|	| q|||< q|S )NFT)
r   r"   r8   r>   r?   rm   r$   r=   r   update)rY   rZ   kwargs_startedr   rN   r   r   r   r   rZ     s*    


zBoundArguments.kwargsc                 C   s   d | jj}t|d S rw   rx   ry   r   r   r   rz     s    zBoundArguments.__hash__c                 C   s$   t |jto"| j|jko"| j|jkS r   )r{   ru   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   rS   rT   r'   r   r	   r9   rZ   rz   r~   r   r   r   r   r   r   \  s   


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krt  }n|rt  }t}t|D ]z\}}|j}||k rXd}	|	||j}	t|	n|}|j}
|
dkr~t|}
|j|
d}|
|k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`   ).0rN   r   r   r   	<genexpr>  s   z%Signature.__init__.<locals>.<genexpr>)r   rk   	enumerater>   r*   r<   r   rn   r.   r   r   )rY   r"   return_annotation__validate_parameters__paramstop_kindidxrN   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k	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#   rf      r!   returnF)r   r   )r   r+   r3   r)   r*   _parameter_cls__code__co_argcountco_varnamesr/   r   __defaults__lengetrU   r   rl   r   co_flagsr@   rm   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   s6   zt | jW S  tk
r0   t| j  Y S X 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 kr| j }|t k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   )rR   r"   r0   r   r   )rY   r"   r   r   r   r   r.   U  s    
zSignature.replacec                 C   s   d | jj}t|d S rw   rx   ry   r   r   r   rz   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k
r   Y  dS X ||kr dS q\z|| }W n tk
r   Y  dS X ||ks||j| kr\ dS q\dS )NFc                 s   s   | ]\}}||fV  qd S r   r   )r   r   rN   r   r   r   r   n  s   z#Signature.__eq__.<locals>.<genexpr>T)r{   r   r   r   r   r"   dictr   keysr8   r>   rm   r   )rY   r}   Zother_positionsr   r   rN   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.||kr.|	j||< q.zt|}
W n tk
r<   zt|}	W n tk
r   Y Y qY nX |	j	t
krY qn|	j|kr|	j	tkrd}|j|	jd}t||	f}Y qnR|	j	tks|	jtk	r
|	f}Y qn.|r|	f}Y qnd}|j|	jd}t|Y qPX zt|}	W n tk
rh   tdY qPX |	j	ttfkrtd|	j	t
kr|
g}|| t|||	j< q|	j|k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 nD tk
rx   |st|	j	t
krt|	jtkrttdj|dY n
X |
||< q|r|dk	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   rk   r*   r)   r?   rU   rm   r   r/   	itertoolschainrA   r   _bound_arguments_cls)rY   r9   rZ   r6   r=   r"   parameters_exarg_valsr   rN   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   rY   r9   rZ   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k	rt| j
}|d|7 }|S )NTFrs   z({0})z, z -> {0})r   r"   r0   rn   r>   r@   rm   r   r*   joinr   rU   r   )	rY   resultrender_kw_only_separatorr   rN   rt   r>   renderedannor   r   r   r]     s     


zSignature.__str__)F)r   r   rS   rT   r   r   r   r   r   rU   r   r'   classmethodr4   r   r"   r   rR   r.   rz   r~   r   r   r   r;   r]   r   r   r   r   r     s.   
&
H


 )N)$rT   
__future__r   r   r   r   r5   ro   r+   collectionsr   __version____all__r   r%   _WrapperDescriptorall_MethodWrapperrB   r   r   r    r	   objectrR   rU   rW   rV   rk   rl   r@   rm   r?   r   r   r   r   r   r   r   <module>   s:   


p a