
    ~ft                        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Zd Zd	 Z G d
 de      Z G d de      Z G d de      Z edd      Z edd      Z edd      Z edd      Z edd      Z  G d de      Z! G d de      Z" G d de      Z#y)!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                     t        | t              r9| j                  dd|fv r| j                  S | j                  dz   | j                  z   S t	        |       S )Nbuiltins__builtin__.)
isinstancetype
__module____name__repr)
annotationbase_modules     O/var/www/cvtools/html/venv/lib/python3.12/site-packages/backcall/_signatures.pyformatannotationr   ,   sT    *d#  Z$LL&&&$$S()<)<<<
    c                     	 | t         u ry t        | |      }|D ]  }t        |||      } 	 t        |t              s|S y # t        $ r Y y w xY wN)r   getattrr   _NonUserDefinedCallablesAttributeError)clsmethod_namenestedmethnames        r   _get_user_defined_methodr#   4   sg    $;sK( 	-D4t,D	-
 $ 89 K :  s   ?  ? 	A
Ac                 |   t        |       st        dj                  |             t        | t        j
                        rKt        | j                        }|j                  t        |j                  j                               dd       S 	 | j                  }||S 	 | j                  }t        |      S # t        $ r Y #w xY w# t        $ r Y nw xY wt        | t        j                        rt         j#                  |       S t        | t$        j&                        r2t        | j(                        }t+        |j                  j-                               }| j.                  xs d}| j0                  xs i }	  |j2                  |i |}n-# t        $ r!}dj                  |       }t5        |      d}~ww xY w|j6                  j-                         D ]\  \  }	}
||	   }|	|v r|j                  |
d      ||	<   &|j8                  t:        t<        fvs?|j>                  rL|jA                  |	       ^ |j                  |j                               S d}t        | tB              rWtE        tC        |       d	      }|t        |      }ngtE        | d
      }|t        |      }nMtE        | d      }|?t        |      }n3t        | tF              s#tE        tC        |       d	d      }|t        |      }||S t        | t        jH                        rdj                  |       }t5        |      t5        dj                  |             )z/Get a signature object for the passed callable.z{0!r} is not a callable object   N)
parameters z,partial object {0!r} has incorrect argumentsT)default_partial_kwarg__call____new____init__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inits                  r   r
   r
   D   s    C=8??DEE#u''( %{{eCNN,A,A,C&DQR&H{II ?J"// !!    
 #u))*&&s++#y(()! !5!5!78
xx~2<<-2	"!!!<D3CDB 	"@GGLCS/!	" $&<<#5#5#7 	)Hix(E++$ (-}}YDH (5 (J
8$ **\?$CC % 4 4x(3	)6 {{j&7&7&9{::
C#t
 (S	:>D/C +3	:Cn 0Z@##D/C56
 (S	:yID/C

#u001=DDSIo
CJJ3O
PPs<   B4 C 4	C ?C 	CC5F 	F2F--F2c                       e Zd ZdZy)_voidz0A private marker - used in Parameter & SignatureN)r   r   __qualname____doc__r'   r   r   rY   rY      s    :r   rY   c                       e Zd Zy)_emptyN)r   r   rZ   r'   r   r   r]   r]      s    r   r]   c                       e Zd Zd Zd Zd Zy)_ParameterKindc                 F    t        j                  | g| }|d   |_        |S )Nr"   )intr+   _name)selfr?   kwargsrI   s       r   r+   z_ParameterKind.__new__   s%    kk$&&6N	
r   c                     | j                   S r   rb   rc   s    r   __str__z_ParameterKind.__str__   s    zzr   c                 8    dj                  | j                        S )Nz<_ParameterKind: {0!r}>)r0   rb   rg   s    r   __repr__z_ParameterKind.__repr__   s    (//

;;r   N)r   r   rZ   r+   rh   rj   r'   r   r   r_   r_      s    
<r   r_   POSITIONAL_ONLYr"   r%   POSITIONAL_OR_KEYWORD   VAR_POSITIONAL   KEYWORD_ONLY   VAR_KEYWORDc                       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Zed        Zed        Zed        Zed        Zeeeeefd	Zd
 Zd Zd Zd Zd Zy)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`.
    )rb   _kind_default_annotationr)   Fc                    |t         t        t        t        t        fvrt        d      || _        |t        ur*|t        t        fv rdj                  |      }t        |      || _	        || _
        |#|t         k7  rt        d      || _        || _        y t        |      }|t         k7  rAt        j                  d|t        j                        sdj                  |      }t        |      || _        || _        y )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_KEYWORDrF   _KEYWORD_ONLYrE   rB   ru   r]   r0   rv   rw   rb   strrematchIr)   )rc   r"   rD   r(   r   r)   rQ   s          r   r,   zParameter.__init__   s     (*@'F FKLL
& 66AHHN o%%<''  "A B BDJ - t9D''bdd0S;BB4H o%DJ,r   c                     | j                   S r   rf   rg   s    r   r"   zParameter.name      zzr   c                     | j                   S r   )rv   rg   s    r   r(   zParameter.default  s    }}r   c                     | j                   S r   )rw   rg   s    r   r   zParameter.annotation  s    r   c                     | j                   S r   )ru   rg   s    r   rD   zParameter.kind  r   r   c                     |t         u r| j                  }|t         u r| j                  }|t         u r| j                  }|t         u r| j                  }|t         u r| j
                  } t        |       |||||      S )z+Creates a customized copy of the Parameter.)r(   r   r)   )rY   rb   ru   rw   rv   r)   r   )rc   r"   rD   r   r(   r)   s         r   r4   zParameter.replace  sy     5=::D5=::D))JemmGU"!00NtDz$g*)79 	9r   c                    | j                   }| j                  }|t        k(  r|d}dj                  |      }| j                  t
        ur%dj                  |t        | j                              }| j                  t
        ur%dj                  |t        | j                              }|t        k(  rd|z   }|S |t        k(  rd|z   }|S )N z<{0}>z{0}:{1}z{0}={1}*z**)rD   rb   ry   r0   rw   r]   r   rv   r   rF   rE   )rc   rD   	formatteds      r   rh   zParameter.__str__1  s    yyJJ	## 	y1I 6)!(('78H8H'IKI ==&!((D4GHI?"iI  \!y(Ir   c                 v    dj                  | j                  j                  t        |       | j                        S )Nz<{0} at {1:#x} {2!r}>)r0   	__class__r   idr"   rg   s    r   rj   zParameter.__repr__I  s0    &--dnn.E.E+-d8TYY@ 	@r   c                 b    dj                  | j                  j                        }t        |      Nzunhashable type: '{0}'r0   r   r   r/   rc   rQ   s     r   __hash__zParameter.__hash__M  &    &--dnn.E.EFnr   c                    t        |j                  t              xrj | j                  |j                  k(  xrO | j                  |j                  k(  xr4 | j
                  |j
                  k(  xr | j                  |j                  k(  S r   )
issubclassr   r   rb   ru   rv   rw   rc   others     r   __eq__zParameter.__eq__Q  sq    5??I6 6

ekk)6

ekk)6 /6   E$5$55		7r   c                 &    | j                  |       S r   r   r   s     r   __ne__zParameter.__ne__X      ;;u%%%r   N)r   r   rZ   r[   	__slots__ry   rk   rz   rm   rF   ro   r{   rq   rE   rs   r]   emptyr,   propertyr"   r(   r   rD   rY   r4   rh   rj   r   r   r   r'   r   r   r   r      s    & PI.O4-N+L*KE+1f %-:           !ue9,0@7&r   r   c                   X    e Zd ZdZd Zed        Zed        Zed        Zd Z	d Z
d Zy	)
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                      || _         || _        y r   )rC   
_signature)rc   r
   rC   s      r   r,   zBoundArguments.__init__m  s    "#r   c                     | j                   S r   )r   rg   s    r   r
   zBoundArguments.signatureq  s    r   c                    g }| j                   j                  j                         D ]{  \  }}|j                  t        t
        fv s|j                  r t        |      S 	 | j                  |   }|j                  t        k(  r|j                  |       k|j                  |       } t        |      S # t        $ r Y  t        |      S w xY wr   )r   r&   r>   rD   rE   r{   r)   rC   rF   extendappendKeyErrorr5   )rc   r?   
param_namerT   args        r   r?   zBoundArguments.argsu  s    !%!;!;!A!A!C 	%J

|];;494H4H
   T{%nnZ0 ::0KK$ KK$+	%. T{    T{s   B00	CCc                 r   i }d}| j                   j                  j                         D ]|  \  }}|s8|j                  t        t
        fv s|j                  rd}n|| j                  vrd}@|sC	 | j                  |   }|j                  t        k(  r|j                  |       x|||<   ~ |S # t        $ r Y w xY w)NFT)
r   r&   r>   rD   rE   r{   r)   rC   updater   )rc   rd   kwargs_startedr   rT   r   s         r   rd   zBoundArguments.kwargs  s    !%!;!;!A!A!C 	-J!JJ<"??050D0D%)N!7)- !
-nnZ0 ::-MM#& *-F:&/	-2   s   -B**	B65B6c                 b    dj                  | j                  j                        }t        |      r   r   r   s     r   r   zBoundArguments.__hash__  r   r   c                     t        |j                  t              xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r   )r   r   r   r
   rC   r   s     r   r   zBoundArguments.__eq__  s?    5??N; 2%//12%//1	3r   c                 &    | j                  |       S r   r   r   s     r   r   zBoundArguments.__ne__  r   r   N)r   r   rZ   r[   r,   r   r
   r?   rd   r   r   r   r'   r   r   r   r   \  sW     $    6  <3
&r   r   c                       e Zd ZdZdZeZeZe	Z
de	dfdZed        Zed        Zed        Zeefd	Zd
 Zd Zd ZddZd Zd Zd Zy)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                    |t               }n|rt               }t        }t        |      D ]  \  }}|j                  }||k  r)d}	|	j	                  ||j                        }	t        |	      |}|j                  }
|
t        |      }
|j                  |
      }|
|v rdj	                  |
      }	t        |	      |||
<    nt        d |D              }|| _	        || _
        y)zConstructs Signature from the given list of Parameter
        objects and 'return_annotation'.  All arguments are optional.
        Nz%wrong parameter order: {0} before {1}rl   zduplicate parameter name: {0!r}c              3   8   K   | ]  }|j                   |f  y wr   rl   ).0rT   s     r   	<genexpr>z%Signature.__init__.<locals>.<genexpr>  s#      &I49 (-zz5&9 &Is   )r   ry   	enumeraterD   r0   rB   r"   r|   r4   r   r   )rc   r&   return_annotation__validate_parameters__paramstop_kindidxrT   rD   rQ   r"   s              r   r,   zSignature.__init__  s      ]F&$+"+J"7 )JC ::DhE!jj5::>(o-#' ::D|"3x %4 8v~?FFtL(o-#(F4L#)& % &I=G&I J ""3r   c           
         t        |t        j                        st        dj	                  |            | j
                  }|j                  }|j                  }|j                  }t        |d|       }t        |dd      }||||z    }t        |di       }	|j                  }
t        |dd      }|
rt        |
      }nd}g }||z
  }|d| D ]6  }|	j                  |t              }|j                   |||t                      8 t#        ||d       D ]=  \  }}|	j                  |t              }|j                   |||t         |
|                ? |j$                  d	z  r<|||z      }|	j                  |t              }|j                   |||t&                     |D ]U  }t        }||j                  |t              }|	j                  |t              }|j                   |||t(        |             W |j$                  d
z  rR||z   }|j$                  d	z  r|dz  }||   }|	j                  |t              }|j                   |||t*                      | ||	j                  dt              d      S )z2Constructs Signature for the given python functionz{0!r} is not a Python functionNco_kwonlyargcountr   __annotations____kwdefaults__)r   rD   )r   rD   r(   rr      r%   returnF)r   r   )r   r1   r9   r/   r0   _parameter_cls__code__co_argcountco_varnamesr5   r   __defaults__lengetr]   r   rz   r   co_flagsrF   r{   rE   )r   r=   r   	func_code	pos_count	arg_names
positionalkeyword_only_countkeyword_onlyannotationsdefaults
kwdefaultspos_default_countr&   non_default_countr"   r   offsetr(   indexs                       r   r:   zSignature.from_function  s    $ 2 23<CCDIJJ&&	 MM	))	))	9Zi01
$Y0CQG I8J,JLd$5r:$$T#3T:
 #H !
 &(991 12 	FD$v6Ji-CE F	F &j1B1C&DE 	CLFD$v6Ji-C080@B C	C $Y);;<D$v6Ji-<> ? ! 	:DG%$..v6$v6Ji-:079 :	: $ 22E!!D(
U#D$v6Ji-9; < :%0__Xv%F+02 	2r   c                     	 t        j                  | j                        S # t        $ r& t	        | j                  j                               cY S w xY wr   )r1   MappingProxyTyper   r   r   r>   rg   s    r   r&   zSignature.parametersJ  sG    	9))$*:*:;; 	9t//55788	9s   ! ,AAc                     | j                   S r   )r   rg   s    r   r   zSignature.return_annotationQ  s    &&&r   c                     |t         u r| j                  j                         }|t         u r| j                  } t	        |       ||      S )zCreates a customized copy of the Signature.
        Pass 'parameters' and/or 'return_annotation' arguments
        to override them in the new copy.
        )r   )rY   r&   r6   r   r   )rc   r&   r   s      r   r4   zSignature.replaceU  sJ     //1J% $ 7 7tDz*,=? 	?r   c                 b    dj                  | j                  j                        }t        |      r   r   r   s     r   r   zSignature.__hash__d  r   r   c                 V   t        t        |      t              rD| j                  |j                  k7  s+t	        | j
                        t	        |j
                        k7  ryt        d t        |j
                  j                               D              }t        | j
                  j                               D ]R  \  }\  }}|j                  t        k(  r	 |j
                  |   }||k7  s2 y	 ||   }||k7  s||j
                  |   k7  sR y y# t        $ r Y  yw xY w# t        $ r Y  yw xY w)NFc              3   *   K   | ]  \  }}||f  y wr   r'   )r   r   rT   s      r   r   z#Signature.__eq__.<locals>.<genexpr>n  s"      Q)sE !&s| Qs   T)r   r   r	   r   r   r&   dictr   keysr>   rD   r{   r   )rc   r   other_positionsr   r   rT   other_param	other_idxs           r   r   zSignature.__eq__h  s'   4;	2**e.E.EE(C0@0@,AA Q-6u7G7G7L7L7N-OQ Q )2$//2G2G2I(J 	%$C$*ezz]*%"'"2"2:">K +$% /
 ;I y($)U-=-=j-I$I$#	%&    ! !   ! !s$   D*D	DD	D('D(c                 &    | j                  |       S r   r   r   s     r   r   zSignature.__ne__  r   r   c                    t               }t        | j                  j                               }d}t        |      }|rC| j                  j	                         D ]&  \  }}	|	j
                  s||vs|	j                  ||<   ( 	 	 t        |      }
	 t        |      }	|	j                  t        t        fv rt        d      |	j                  t        k(  r-|
g}|j                  |       t        |      ||	j                  <   nC|	j                  |v r%t        dj!                  |	j                              |
||	j                  <   d}t)        j*                  ||      D ]s  }	|	j                  t$        k(  r%t        dj!                  |	j                              |	j                  t        k(  r|	}Q|	j                  }	 |j-                  |      }
|
||<   u |r||||j                  <   nt        d      | j1                  | |      S # t"        $ r t        d      w xY w# t"        $ r 	 t        |      }	|	j                  t        k(  rY |	j                  |v rB|	j                  t$        k(  r)d}|j!                  |	j                        }t        |      |	f}Y R|	j                  t        k(  s|	j                  t&        ur|	f}Y }|r|	f}Y d}|j!                  |	j                        }t        |      # t"        $ r Y Y w xY ww xY w# t.        $ rF |s@|	j                  t        k7  r-|	j                  t&        u rt        dj!                  |            Y w xY w)	z$Private method.  Don't use directly.r'   ztoo many positional argumentsz$multiple values for argument {arg!r})r   zA{arg!r} parameter is positional only, but was passed as a keywordz'{arg!r} parameter lacking default valueNztoo many keyword arguments)r   iterr&   r6   r>   r)   r(   nextrD   rE   r{   r/   rF   r   r5   r"   r0   StopIterationry   r]   	itertoolschainrG   r   _bound_arguments_cls)rc   r?   rd   r<   rC   r&   parameters_exarg_valsr   rT   arg_valr6   rQ   kwargs_params                 r   _bindzSignature._bind  sO     M	$//0023
: &*__%:%:%< 7!
E((Zv-E).F:&7
 ?4x.N4 ,E zzlM%BB ((GHHzz_4 #*h/05f	%**-zzV+' )228&UZZ&2HJ J -4Iejj)E L __]J? 	0Ezz--   !> &5:: 68 8 zz\)$J0 **Z0 )0	*%9	0< '/5	,++, <==((y99 % E#$CDDEQ ! #1!1 ,E zz_4 v- ::)99#@C"%***"<C"+C.0).**405V0K */"-2HM!"KC"%***"<C"+C.0? %  	#1f  <
  EJJ/$A49MMV4K#$M$*FzF$:< <<sh   H G> 5L>H	K? K-+K?AK?(K?<K?)K?-	K;6K?:K;;K?AMMc                 &    | j                  ||      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   rc   r?   rd   s      r   bindzSignature.bind	  s    
 zz$''r   c                 *    | j                  ||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)r<   r   r   s      r   rA   zSignature.bind_partial  s    
 zz$z55r   c                    g }d}t        | j                  j                               D ]W  \  }}t        |      }|j                  }|t
        k(  rd}n|t        k(  r|r|j                  d       d}|j                  |       Y dj                  dj                  |            }| j                  t        ur)t        | j                        }|dj                  |      z  }|S )NTFr   z({0})z, z -> {0})r   r&   r6   r|   rD   rF   r{   r   r0   joinr   r]   r   )	rc   resultrender_kw_only_separatorr   rT   r   rD   renderedannos	            r   rh   zSignature.__str__  s    #' #DOO$:$:$<= 	%JCE
I::D& ,1(&+C c" ,1(MM)$#	%& >>$))F"34!!/#D$:$:;D	((..Hr   )F)r   r   rZ   r[   r   r   r   r   r   r]   r   r,   classmethodr:   r   r&   r   rY   r4   r   r   r   r   r   rA   rh   r'   r   r   r	   r	     s    , 6IN)E"&&)-$4L F2 F2P 9 9 ' ' "'% ?<&~:@(6r   r	   r   )$r[   
__future__r   r   r   r   r;   r}   r1   collectionsr   __version____all__r   r*   _WrapperDescriptorall_MethodWrapperrH   r   r   r#   r
   objectrY   r]   ra   r_   ry   rz   rF   r{   rE   r   r   r	   r'   r   r   <module>r     s  $ A @   	 
 $ D $--( cll#.*!557 
 mQ`;F ;	V 	
<S 
< )1BC (1HI (1AB(@(?I& I&X^&V ^&Bv vr   