o
     JAf                     @   s  	 g d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dZdZeefd	d
ZeefddZefddZefddZefddZefddZefddZefddZefddZefddZefddZefdd Zefd!d"Zefd#d$Zd%efd&efd'efgd'efd(efd%efgd(efd'efd&efgd&efd%efd(efgd)Zd*d+ Zd,d- Zzdd.lmZ W n	 e y   Y nw e! Z"e"fd/d0Z#zdd1lm#Z# W n	 e y   Y nw G d2d3 d3Z$zdd4lm$Z$ W n	 e y   Y nw G d5d6 d6e!Z%d7d8 Z&ed9g d:Z'G d;d< d<e(Z)e! fe*e+he,e-e.fd=d>Z/dWdAdBZ0dCdD Z1zddElm1Z1 W n
 e y:   Y nw dFdG Z2dHdI Z3dXdKdLZ4dMdN Z5dOdP Z6dQdR Z7G dSdT dTZ8e! Z9G dUdV dVZ:dJS )Y)update_wrapperwrapsWRAPPER_ASSIGNMENTSWRAPPER_UPDATEStotal_orderingcache
cmp_to_key	lru_cachereducepartialpartialmethodsingledispatchsingledispatchmethodcached_property    )get_cache_token)
namedtuple)recursive_repr)RLock)GenericAlias)
__module____name____qualname____doc____annotations__)__dict__c              	   C   sf   	 |D ]}zt ||}W n	 ty   Y qw t| || q|D ]}t | |t ||i  q|| _| S N)getattrAttributeErrorsetattrupdate__wrapped__)wrapperwrappedassignedupdatedattrvalue r'    /usr/lib/python3.10/functools.pyr   #   s   r   c                 C   s   	 t t| ||dS )Nr"   r#   r$   )r
   r   r)   r'   r'   r(   r   A   s   r   c                 C   ,   	 t | | |}||u r|S | o| |kS r   type__lt__selfotherNotImplemented	op_resultr'   r'   r(   _gt_from_ltY   
   r3   c                 C   *   	 t | | |}||u r|S |p| |kS r   r+   r.   r'   r'   r(   _le_from_lt`   
   r6   c                 C   $   	 t | | |}||u r|S | S r   r+   r.   r'   r'   r(   _ge_from_ltg   
   r9   c                 C   ,   	 t | | |}||u r|S | p| |kS r   r,   __le__r.   r'   r'   r(   _ge_from_len   r4   r>   c                 C   *   	 t | | |}||u r|S |o| |kS r   r<   r.   r'   r'   r(   _lt_from_leu   r7   r@   c                 C   r8   r   r<   r.   r'   r'   r(   _gt_from_le|   r:   rA   c                 C   r*   r   r,   __gt__r.   r'   r'   r(   _lt_from_gt   r4   rD   c                 C   r5   r   rB   r.   r'   r'   r(   _ge_from_gt   r7   rE   c                 C   r8   r   rB   r.   r'   r'   r(   _le_from_gt   r:   rF   c                 C   r;   r   r,   __ge__r.   r'   r'   r(   _le_from_ge   r4   rI   c                 C   r?   r   rG   r.   r'   r'   r(   _gt_from_ge   r7   rJ   c                 C   r8   r   rG   r.   r'   r'   r(   _lt_from_ge   r:   rK   rC   r=   rH   r-   )r-   r=   rC   rH   c                    sX   	  fddt D }|stdt|}t | D ]\}}||vr)||_t || q S )Nc                    s(   h | ]}t  |d t t|d ur|qS r   )r   object).0opclsr'   r(   	<setcomp>   s   ( z!total_ordering.<locals>.<setcomp>z6must define at least one ordering operation: < > <= >=)_convert
ValueErrormaxr   r   )rP   rootsrootopnameopfuncr'   rO   r(   r      s   r   c                    s   	 G  fdddt }|S )Nc                       sZ   e Zd ZdgZdd Z fddZ fddZ fdd	Z fd
dZ fddZ	dZ
dS )zcmp_to_key.<locals>.Kobjc                 S   s
   || _ d S r   rY   )r/   rY   r'   r'   r(   __init__   s   
zcmp_to_key.<locals>.K.__init__c                    s    | j |j dk S Nr   rZ   r/   r0   mycmpr'   r(   r-         zcmp_to_key.<locals>.K.__lt__c                    s    | j |j dkS r\   rZ   r]   r^   r'   r(   rC      r`   zcmp_to_key.<locals>.K.__gt__c                    s    | j |j dkS r\   rZ   r]   r^   r'   r(   __eq__   r`   zcmp_to_key.<locals>.K.__eq__c                    s    | j |j dkS r\   rZ   r]   r^   r'   r(   r=      r`   zcmp_to_key.<locals>.K.__le__c                    s    | j |j dkS r\   rZ   r]   r^   r'   r(   rH      r`   zcmp_to_key.<locals>.K.__ge__N)r   r   r   	__slots__r[   r-   rC   ra   r=   rH   __hash__r'   r^   r'   r(   K   s    rd   )rL   )r_   rd   r'   r^   r(   r      s   r   )r   c                 C   sT   	 t |}|tu rzt|}W n ty   tdd w |}|D ]}| ||}q |S )Nz0reduce() of empty iterable with no initial value)iter_initial_missingnextStopIteration	TypeError)functionZsequenceinitialitr&   elementr'   r'   r(   r	      s    r	   )r	   c                       sH   e Zd Z	 dZ fddZdd Ze dd Zdd	 Zd
d Z	  Z
S )r
   )funcargskeywordsr   __weakref__c                   s^   t |stdt|dr|j| }i |j|}|j}tt| | }||_||_||_|S )Nz#the first argument must be callablern   )	callableri   hasattrro   rp   rn   superr
   __new__)rP   rn   ro   rp   r/   	__class__r'   r(   ru     s   

zpartial.__new__c                O   s*   i | j |}| jg | j|R i |S r   rp   rn   ro   )r/   ro   rp   r'   r'   r(   __call__+  s   zpartial.__call__c                 C   s   t | j}t| jg}|dd | jD  |dd | j D  t | jdkr6d| dd	| dS | dd	| dS )	Nc                 s   s    | ]}t |V  qd S r   )repr)rM   xr'   r'   r(   	<genexpr>3      z#partial.__repr__.<locals>.<genexpr>c                 s   s"    | ]\}}| d |V  qdS )=Nr'   rM   kvr'   r'   r(   r|   4  s     	functoolsz
functools.(, ))
r,   r   rz   rn   extendro   rp   itemsr   join)r/   qualnamero   r'   r'   r(   __repr__/  s   
zpartial.__repr__c                 C   s*   t | | jf| j| j| jpd | jpd ffS r   )r,   rn   ro   rp   r   r/   r'   r'   r(   
__reduce__9  s   zpartial.__reduce__c                 C   s   t |ts	tdt|dkrtdt| |\}}}}t|r9t |tr9|d ur0t |tr9|d ur=t |ts=tdt|}|d u rHi }n
t|turRt|}|d u rXi }|| _|| _|| _	|| _
d S )Nz(argument to __setstate__ must be a tuple   zexpected 4 items in state, got zinvalid partial state)
isinstancetupleri   lenrr   dictr,   r   rn   ro   rp   )r/   statern   ro   kwds	namespacer'   r'   r(   __setstate__=  s(   

zpartial.__setstate__)r   r   r   rb   ru   ry   r   r   r   r   __classcell__r'   r'   rv   r(   r
     s    
	r
   )r
   c                   @   sD   e Zd Z	 dd Zdd Zdd Zddd	Zed
d Ze	e
ZdS )r   c                O   sh   t |st|dstd|t|tr)|j| _|j| | _i |j|| _d S || _|| _|| _d S )N__get__z${!r} is not callable or a descriptor)	rr   rs   ri   formatr   r   rn   ro   rp   )r/   rn   ro   rp   r'   r'   r(   r[   c  s   

zpartialmethod.__init__c                 C   sN   d tt| j}d dd | j D }d}|j| jj| jj	| j
||dS )Nr   c                 s   s     | ]\}}d  ||V  qdS )z{}={!r}N)r   r   r'   r'   r(   r|   x  s    z)partialmethod.__repr__.<locals>.<genexpr>z*{module}.{cls}({func}, {args}, {keywords}))modulerP   rn   ro   rp   )r   maprz   ro   rp   r   r   rw   r   r   rn   )r/   ro   rp   format_stringr'   r'   r(   r   v  s   

zpartialmethod.__repr__c                    s    fdd} j |_  |_|S )Nc                   s,   i  j |} j| g j|R i |S r   rx   )cls_or_selfro   rp   r   r'   r(   _method  s   z3partialmethod._make_unbound_method.<locals>._method)__isabstractmethod___partialmethod)r/   r   r'   r   r(   _make_unbound_method  s   z"partialmethod._make_unbound_methodNc                 C   s   t | jdd }d }|d ur4|||}|| jur4t|g| jR i | j}z|j|_W n	 ty3   Y nw |d u r@|  ||}|S )Nr   )	r   rn   r
   ro   rp   __self__r   r   r   )r/   rY   rP   getresultnew_funcr'   r'   r(   r     s   

zpartialmethod.__get__c                 C      t | jddS Nr   Fr   rn   r   r'   r'   r(   r        z"partialmethod.__isabstractmethod__r   )r   r   r   r[   r   r   r   propertyr   classmethodr   __class_getitem__r'   r'   r'   r(   r   [  s    

r   c                 C   s   t | tr| j} t | ts| S r   )r   r
   rn   rn   r'   r'   r(   _unwrap_partial  s   

r   	CacheInfo)hitsmissesmaxsizecurrsizec                   @   s&   e Zd Z	 dZefddZdd ZdS )
_HashedSeq	hashvaluec                 C   s   || d d < ||| _ d S r   r   )r/   tuphashr'   r'   r(   r[     s   z_HashedSeq.__init__c                 C   s   | j S r   r   r   r'   r'   r(   rc     s   z_HashedSeq.__hash__N)r   r   r   rb   r   r[   rc   r'   r'   r'   r(   r     s
    r   c           
         s   	 | }|r||7 }|  D ]}	||	7 }q|r8|| fdd| D 7 }|r4|| fdd| D 7 }t|S ||dkrJ |d |v rJ|d S t|S )Nc                 3       | ]} |V  qd S r   r'   rM   r   r,   r'   r(   r|     r}   z_make_key.<locals>.<genexpr>c                 3   r   r   r'   r   r   r'   r(   r|     r}      r   )r   valuesr   )
ro   r   typedkwd_mark	fasttypesr   r,   r   keyitemr'   r   r(   	_make_key  s   
r      Fc                    s   	 t  tr dk rd n*t r/t tr/ d} t| t} fdd|_t||S  d ur7td fdd}|S )Nr   r   c                      
    dS Nr   r   r'   r'   r   r'   r(   <lambda>      
 zlru_cache.<locals>.<lambda>z=Expected first argument to be an integer, a callable, or Nonec                    s(   t |  t} fdd|_t|| S )Nc                      r   r   r'   r'   r   r'   r(   r     r   z8lru_cache.<locals>.decorating_function.<locals>.<lambda>)_lru_cache_wrapper
_CacheInfocache_parametersr   )user_functionr!   r   r'   r(   decorating_function  s   
z&lru_cache.<locals>.decorating_function)	r   intrr   boolr   r   r   r   ri   )r   r   r   r!   r   r'   r   r(   r     s    


r   c                    s   t  td\ i d 	djjt 
g d d gd d < dkr4fdd}n'd u rF	fdd}n 	
fdd}	
fdd	}	
fd
d}||_||_|S )N)r   r         r   Fc                     s    d7  | i |}|S Nr   r'   )ro   r   r   )r   r   r'   r(   r!     s   z#_lru_cache_wrapper.<locals>.wrapperc                     sL   | |}|}|urd7 |S d7 | i |}| |< |S r   r'   )ro   r   r   r   )r   	cache_getr   make_keyr   sentinelr   r   r'   r(   r!   '  s   
c                     s  
| |}	C |}|d ur@|\}}}}||< ||<  }| |< < ||< |< d7 |W  d    S d7 W d    n1 sNw   Y  | i |}	a |v rbnKr}	||	 < ||	< |	   }
 }d   < < |
= |	|< n+ }|||g}| |<  < |<  kW d    |S W d    |S W d    |S 1 sw   Y  |S r   r'   )ro   r   r   linkZ	link_prevZ	link_next_keyr   ZlastZoldrootZoldkeyZ	oldresult)KEYNEXTPREVRESULTr   r   	cache_lenfullr   lockr   r   r   rV   r   r   r'   r(   r!   6  sX   


$
$
$$c                      s:   	    W  d    S 1 sw   Y  d S r   r'   r'   )r   r   r   r   r   r   r'   r(   
cache_infoo  s   $z&_lru_cache_wrapper.<locals>.cache_infoc                      sT   	      d d gd d < d dW d    d S 1 s#w   Y  d S )Nr   F)clearr'   )r   r   r   r   r   rV   r'   r(   cache_cleart  s   "z'_lru_cache_wrapper.<locals>.cache_clear)rL   r   r   __len__r   r   r   )r   r   r   r   r!   r   r   r'   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   rV   r   r   r   r(   r     s*   *9	r   )r   c                C   s   	 t d d| S )N)r   )r   )r   r'   r'   r(   r     s   r   c                 C   s   	 g }	 dd | D } | s|S | D ]}|d }| D ]}||dd  v r'd } nq nq|d u r3t d|| | D ]}|d |krE|d= q:q)NTc                 S   s   g | ]}|r|qS r'   r'   rM   sr'   r'   r(   
<listcomp>  s    z_c3_merge.<locals>.<listcomp>r   r   zInconsistent hierarchy)RuntimeErrorappend)	sequencesr   s1	candidates2seqr'   r'   r(   	_c3_merge  s.   
r   Nc           
         s  	 t t| jD ]\}tdrt| j| } nqd} r#t ng  t| jd | }g }t| j|d  } D ]t| rStfdd| jD sS| q;|D ] 	 qV fdd|D } fdd|D } fdd|D }	t
| gg| | |	 |g |g |g S )	N__abstractmethods__r   c                 3   s    | ]}t | V  qd S r   )
issubclass)rM   b)baser'   r(   r|     s    

z_c3_mro.<locals>.<genexpr>c                       g | ]}t | d qS abcs_c3_mrorM   r   r   r'   r(   r         z_c3_mro.<locals>.<listcomp>c                    r   r   r   r   r   r'   r(   r     r   c                    r   r   r   r   r   r'   r(   r     r   )	enumeratereversed	__bases__rs   r   listr   anyr   remover   )
rP   r   iboundaryexplicit_basesabstract_basesother_basesexplicit_c3_mrosabstract_c3_mrosother_c3_mrosr'   )r   r   r(   r     sJ   

r   c                    s   	 t j  fddfddD fddfddD t g }D ]C}g }| D ]}| vrMt|rM|fdd|jD  q5|sV|| q-|jtd	d
 |D ]}|D ]}||vrn|| qcq_q-t|dS )Nc                    s(   |  vot | dot| t ot| S )N__mro__)rs   r   r   r   )typ)basesrP   r'   r(   
is_related  s
   
z _compose_mro.<locals>.is_relatedc                    s   g | ]} |r|qS r'   r'   rM   n)r  r'   r(   r     r   z _compose_mro.<locals>.<listcomp>c                    s&    D ]}| |kr| |j v r dS qdS )NTF)r  )r	  r0   )typesr'   r(   is_strict_base  s
   z$_compose_mro.<locals>.is_strict_basec                    s   g | ]} |s|qS r'   r'   r  )r  r'   r(   r     r   c                    s   g | ]}| v r|qS r'   r'   r   )type_setr'   r(   r     r   T)r   reverser   )setr  __subclasses__r   r   sortr   r   )rP   r  mror	  foundsubsubclsr'   )r
  rP   r  r  r  r  r(   _compose_mro  s4   


r  c                 C   sv   	 t | | }d }|D ])}|d ur/||v r-|| jvr-|| jvr-t||s-td|| n||v r5|}q||S )NzAmbiguous dispatch: {} or {})r  keysr  r   r   r   r   )rP   registryr  matchtr'   r'   r(   
_find_impl  s"   	

r  c                    s   	 dd l }dd l}i | d fdddd  d fdd	fdd	}t| d
d| t< |_|_||_j	|_
t||  |S )Nr   c                    sz   	  d urt  } |kr  | z|  }W |S  ty<   z|  }W n ty4   t| }Y nw || < Y |S w r   )r   r   KeyErrorr  )rP   current_tokenimpl)cache_tokendispatch_cacher  r'   r(   dispatch2  s$   

z singledispatch.<locals>.dispatchc                 S   s   t | to
t | t S r   )r   r,   r   rO   r'   r'   r(   _is_valid_dispatch_typeI  s   z/singledispatch.<locals>._is_valid_dispatch_typec                    s   	  r|d u r fddS n?|d urt d dt di }|s-t d d }dd	lm} tt|| \}  sPt d
|d d| < d u r`t dr`t 	  |S )Nc                    s
    | S r   r'   )f)rP   registerr'   r(   r   U  r   z2singledispatch.<locals>.register.<locals>.<lambda>z(Invalid first argument to `register()`. z is not a class.r   z(Invalid first argument to `register()`: zS. Use either `@register(some_class)` or plain `@register` on an annotated function.r   )get_type_hintszInvalid annotation for z. r   )
ri   r   typingr(  rg   re   r   rs   r   r   )rP   rn   annr(  argname)r%  r"  r#  r'  r  rO   r(   r'  L  s<   
z singledispatch.<locals>.registerc                     s*   | s	t  d | d j| i |S )Nz( requires at least 1 positional argumentr   )ri   rw   )ro   kw)r$  funcnamer'   r(   r!   t  s   zsingledispatch.<locals>.wrapperr   zsingledispatch functionr   )r  weakrefWeakKeyDictionaryr   rL   r'  r$  MappingProxyTyper  r   _clear_cacher   )rn   r  r.  r!   r'   )r%  r"  r$  r#  r-  r'  r  r(   r      s"   (
r   c                   @   s6   e Zd Z	 dd Zd
ddZd
ddZedd	 ZdS )r   c                 C   s4   t |st|dst|dt|| _|| _d S )Nr   z  is not callable or a descriptor)rr   rs   ri   r   
dispatcherrn   r/   rn   r'   r'   r(   r[     s   

zsingledispatchmethod.__init__Nc                 C   s   	 | j j||dS )Nr   )r2  r'  )r/   rP   methodr'   r'   r(   r'    s   zsingledispatchmethod.registerc                    s0    fdd}j |_ j|_t|j |S )Nc                     s(   j | d j}| | i |S r\   )r2  r$  rw   r   )ro   kwargsr4  rP   rY   r/   r'   r(   r     s   z-singledispatchmethod.__get__.<locals>._method)r   r'  r   rn   )r/   rY   rP   r   r'   r6  r(   r     s
   zsingledispatchmethod.__get__c                 C   r   r   r   r   r'   r'   r(   r     r   z)singledispatchmethod.__isabstractmethod__r   )r   r   r   r[   r'  r   r   r   r'   r'   r'   r(   r     s    


r   c                   @   s.   e Zd Zdd Zdd ZdddZeeZdS )	r   c                 C   s    || _ d | _|j| _t | _d S r   )rn   attrnamer   r   r   r3  r'   r'   r(   r[     s   zcached_property.__init__c                 C   s:   | j d u r
|| _ d S || j krtd| j d|dd S )Nz?Cannot assign the same cached_property to two different names (z and z).)r7  ri   )r/   ownernamer'   r'   r(   __set_name__  s   


zcached_property.__set_name__Nc              	   C   s  |d u r| S | j d u rtdz|j}W n ty-   dt|jd| j d}t|d w || j t}|tu r| jB || j t}|tu rn| 	|}z||| j < W n! tym   dt|jd| j d}t|d w W d    |S W d    |S 1 sw   Y  |S )NzGCannot use cached_property instance without calling __set_name__ on it.zNo '__dict__' attribute on z instance to cache z
 property.zThe '__dict__' attribute on z7 instance does not support item assignment for caching )
r7  ri   r   r   r,   r   r   
_NOT_FOUNDr   rn   )r/   instancer8  r   msgvalr'   r'   r(   r     sL   






zcached_property.__get__r   )	r   r   r   r[   r:  r   r   r   r   r'   r'   r'   r(   r     s
    
	r   )r   Fr   );__all__abcr   collectionsr   reprlibr   _threadr   r  r   r   r   r   r   r1   r3   r6   r9   r>   r@   rA   rD   rE   rF   rI   rJ   rK   rR   r   r   
_functoolsImportErrorrL   rf   r	   r
   r   r   r   r   r   r   strr   r,   r   r   r   r   r   r   r   r  r  r   r   r;  r   r'   r'   r'   r(   <module>   s    


	AJ	

.t	
-*f(