
    %h%                        d dl mZ d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ eZg dZ G d d	ej                  Z G d
 de          ZeZ G d d          ZdS )    )annotationsN)ref)_IterationGuard)MutableMappingMapping)Tensor)TensorWeakRef	WeakIdRefWeakIdKeyDictionaryWeakTensorKeyDictionaryc                  <     e Zd ZdgZd fd	Z fdZd Zd Z xZS )r
   _idNc                t    t          |          | _        t                                          ||           d S N)idr   super__init__)selfkeycallback	__class__s      P/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/torch/utils/weak.pyr   zWeakIdRef.__init__-   s2     c77h'''''    c                    t                                                      }t          |d          r|                                 |S )N_fix_weakref)r   __call__hasattrr   )r   rr   s     r   r   zWeakIdRef.__call__6   s?    GG1n%% 	NNr   c                    | j         S r   )r   r   s    r   __hash__zWeakIdRef.__hash__=   s	    xr   c                B     |             } |            }||||u S | |u S r    )r   otherabs       r   __eq__zWeakIdRef.__eq__@   s6     DFFEGG=Q]6Mu}r   r   )	__name__
__module____qualname__	__slots__r   r   r!   r'   __classcell__)r   s   @r   r
   r
   *   s{        I( ( ( ( ( (            r   r
   c                      e Zd ZU ded<   ddZd Zd Zd Zd Zd	 Z	d
 Z
d Zd ZeZd ZddZd Zd Zd ZeZd Zd Zd Zd ZddZddZd Zd Zd Zd ZdS )r   zdict[WeakIdRef, object]dataNc                    i | _         t          |           fd}|| _        g | _        t	                      | _        d| _        ||                     |           d S d S )Nc                     |            }|?|j         r|j                            |            d S 	 |j        | = d S # t          $ r Y d S w xY wd S r   )
_iterating_pending_removalsappendr.   KeyError)kselfrefr   s      r   removez,WeakIdKeyDictionary.__init__.<locals>.removeZ   sv    799D? *11!44444 IaLLL#     s   ; 
A	A	F)r.   r   _remover2   setr1   
_dirty_lenupdate)r   dictr7   s      r   r   zWeakIdKeyDictionary.__init__W   so    	!$ii 		 		 		 		 !#%%KK r   c                    | j         j        }| j        }	 	  |            }n# t          $ r Y d S w xY w	 ||= n# t          $ r Y nw xY w3r   )r2   popr.   
IndexErrorr4   )r   r>   dr   s       r   _commit_removalsz$WeakIdKeyDictionary._commit_removalsl   s    
 $(I		cee   cFF   		s   
! 
//7 
AAc                T    | j         fd| j        D             | _        d| _        d S )Nc                    g | ]}|v |	S r#   r#   ).0r5   r@   s     r   
<listcomp>z7WeakIdKeyDictionary._scrub_removals.<locals>.<listcomp>   s    !N!N!NqAvv!vvvr   F)r.   r2   r:   )r   r@   s    @r   _scrub_removalsz#WeakIdKeyDictionary._scrub_removals~   s4    I!N!N!N!NT-C!N!N!Nr   c                >    d| _         | j        t          |          = d S NT)r:   r.   r
   r   r   s     r   __delitem__zWeakIdKeyDictionary.__delitem__   s    Iinn%%%r   c                6    | j         t          |                   S r   )r.   r
   rI   s     r   __getitem__zWeakIdKeyDictionary.__getitem__   s    y3((r   c                    | j         r| j        r|                                  t          | j                  t          | j                  z
  S r   )r:   r2   rF   lenr.   r    s    r   __len__zWeakIdKeyDictionary.__len__   sH    ? 	#t5 	#   """49~~D$: ; ;;;r   c                D    d| j         j         dt          |           ddS )N<z at z#x>)r   r(   r   r    s    r   __repr__zWeakIdKeyDictionary.__repr__   s)    >4>*>>4>>>>>r   c                @    || j         t          || j                  <   d S r   )r.   r
   r8   )r   r   values      r   __setitem__zWeakIdKeyDictionary.__setitem__   s     27	)C..///r   c                    t                      }t          |           5  | j                                        D ]\  }} |            }||||<   	 d d d            n# 1 swxY w Y   |S r   )r   r   r.   items)r   newr   rU   os        r   copyzWeakIdKeyDictionary.copy   s    !##T"" 	# 	#"ioo// # #
UCEE="CF#	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#
 
s   1AA #A c                    ddl m} |                                 }t          |           5  | j                                        D ] \  }} |            }| |||          ||<   !	 d d d            n# 1 swxY w Y   |S )Nr   )deepcopy)r[   r]   r   r   r.   rX   )r   memor]   rY   r   rU   rZ   s          r   __deepcopy__z WeakIdKeyDictionary.__deepcopy__   s    !!!!!!nnT"" 	3 	3"ioo// 3 3
UCEE=%XeT22CF3	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3
 
s   ;A22A69A6c                R    | j                             t          |          |          S r   )r.   getr
   r   r   defaults      r   ra   zWeakIdKeyDictionary.get   s    y}}Ys^^W555r   c                X    	 t          |          }n# t          $ r Y dS w xY w|| j        v S )NF)r
   	TypeErrorr.   )r   r   wrs      r   __contains__z WeakIdKeyDictionary.__contains__   sB    	3BB 	 	 	55	TYs    
  c              #     K   t          |           5  | j                                        D ]\  }} |            }|||fV  	 d d d            d S # 1 swxY w Y   d S r   r   r.   rX   )r   rf   rU   r   s       r   rX   zWeakIdKeyDictionary.items   s      T"" 	% 	%!Y__.. % %	Ebdd?u*$$$%	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   2AAAc              #     K   t          |           5  | j        D ]} |            }||V  	 d d d            d S # 1 swxY w Y   d S r   )r   r.   )r   rf   objs      r   keyszWeakIdKeyDictionary.keys   s      T"" 	 	i  bdd?III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   ;??c              #     K   t          |           5  | j                                        D ]\  }} |            |V  	 d d d            d S # 1 swxY w Y   d S r   ri   )r   rf   rU   s      r   valueszWeakIdKeyDictionary.values   s      T"" 	  	 !Y__..    	E244#KKK 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   .AAAc                *    t          | j                  S )az  Return a list of weak references to the keys.

        The references are not guaranteed to be 'live' at the time
        they are used, so the result of calling the references needs
        to be checked before being used.  This can be used to avoid
        creating references that will cause the garbage collector to
        keep the keys around longer than needed.

        )listr.   r    s    r   keyrefszWeakIdKeyDictionary.keyrefs   s     DIr   c                l    d| _         	 | j                                        \  }} |            }|||fS -rH   )r:   r.   popitem)r   r   rU   rZ   s       r   rs   zWeakIdKeyDictionary.popitem   sC    	 **,,JCA}%x		 r   c                P    d| _          | j        j        t          |          g|R  S rH   )r:   r.   r>   r
   )r   r   argss      r   r>   zWeakIdKeyDictionary.pop   s+    ty}Ys^^3d3333r   c                ^    | j                             t          || j                  |          S r   )r.   
setdefaultr
   r8   rb   s      r   rw   zWeakIdKeyDictionary.setdefault   s&    y##Ic4<$@$@'JJJr   c                   | j         }|Zt          |d          s t          i           |          }|                                D ]\  }}||t	          || j                  <   t          |          r|                     |           d S d S )NrX   )r.   r   typerX   r
   r8   rN   r;   )r   r<   kwargsr@   r   rU   s         r   r;   zWeakIdKeyDictionary.update   s    I4)) &tBxx~~"jjll 8 8
U27)C..//v;; 	 KK	  	 r   c                0    |                      |           | S r   )r;   r   r$   s     r   __ior__zWeakIdKeyDictionary.__ior__   s    Er   c                    t          |t          j                  r+|                                 }|                    |           |S t
          S r   )
isinstance_collections_abcr   r[   r;   NotImplementedr   r$   cs      r   __or__zWeakIdKeyDictionary.__or__   s?    e-566 			AHHUOOOHr   c                    t          |t          j                  r@|                                 }|                    |           |                    |            |S t
          S r   )r   r   r   r   r;   r   r   s      r   __ror__zWeakIdKeyDictionary.__ror__   sP    e-566 	  AHHUOOOHHTNNNHr   c                    t          |t                    st          S d |                                 D             d |                                D             k    S )Nc                4    i | ]\  }}t          |          |S r#   r   rD   r5   vs      r   
<dictcomp>z.WeakIdKeyDictionary.__eq__.<locals>.<dictcomp>	  s$    222TQ1q222r   c                4    i | ]\  }}t          |          |S r#   r   r   s      r   r   z.WeakIdKeyDictionary.__eq__.<locals>.<dictcomp>	  s$    6Z6Z6ZDAqr!uua6Z6Z6Zr   )r   r   r   rX   r|   s     r   r'   zWeakIdKeyDictionary.__eq__  sR    %)) 	"!!22TZZ\\2226Z6ZEKKMM6Z6Z6ZZZr   r   )r(   r)   r*   __annotations__r   rA   rF   rJ   rL   rO   rS   rV   r[   __copy__r_   ra   rg   rX   rl   __iter__rn   rq   rs   r>   rw   r;   r}   r   r   r'   r#   r   r   r   r   T   s        !!!!   *  $     
& & &) ) )< < <? ? ?8 8 8   H  6 6 6 6  % % %   H     
 
 
     4 4 4K K K K             [ [ [ [ [r   r   c                  ,    e Zd ZU dZded<   d	dZd ZdS )
r	   zuWrapper around a weak ref of a Tensor that handles the _fix_weakref() call required when unwrapping a Tensor weakref.zWeakRef[Tensor]r   tensorr   c                f    t          |t                    sJ t          j        |          | _        d S r   )r   r   weakrefr   )r   r   s     r   r   zTensorWeakRef.__init__  s-    &&)))));v&&r   c                    |                                  }||S t          |t                    sJ |                                 |S r   )r   r   r   r   )r   outs     r   r   zTensorWeakRef.__call__  sF    hhjj;J#v&&&&&
r   N)r   r   )r(   r)   r*   __doc__r   r   r   r#   r   r   r	   r	     sK         ' ' ' '    r   r	   )
__future__r   r   r   _weakrefsetr   collections.abcr   r   torchr   abcr   WeakRef__all__r
   r   r   r	   r#   r   r   <module>r      s7   " " " " " "        ' ' ' ' ' ' 3 3 3 3 3 3 3 3       * * * * * *  [
Z
Z8' ' ' ' ' ' ' 'Tu[ u[ u[ u[ u[. u[ u[ u[p .          r   