
    hg                     T    d Z ddlmZ ddlZddlZddlmZ dgZ G d de          Z	dS )zd
backports.weakref_finalize
~~~~~~~~~~~~~~~~~~

Backports the Python 3 ``weakref.finalize`` method.
    )absolute_importN)refweakref_finalizec                       e Zd ZdZdZi ZdZ ej                    Z	dZ
dZ G d de          Zd ZddZd	 Zd
 Zed             Zed             Zej        d             Zd Zed             Zed             ZdS )r   a  Class for finalization of weakrefable objects
    finalize(obj, func, *args, **kwargs) returns a callable finalizer
    object which will be called when obj is garbage collected. The
    first time the finalizer is called it evaluates func(*arg, **kwargs)
    and returns the result. After this the finalizer is dead, and
    calling it just returns None.
    When the program exits any remaining finalizers for which the
    atexit attribute is true will be run in reverse order of creation.
    By default atexit is true.
     Fc                       e Zd ZdZdS )weakref_finalize._Info)weakreffuncargskwargsatexitindexN)__name__
__module____qualname__	__slots__r       d/var/www/fb-scrape/myenv/lib/python3.11/site-packages/urllib3/packages/backports/weakref_finalize.py_Infor	   (   s        L			r   r   c                 T   | j         s*dd l}|                    | j                   dt          _         |                                 }t          ||           |_        ||_        ||_	        |pd |_
        d|_        t          | j                  |_        || j        | <   dt          _        d S )Nr   T)_registered_with_atexitr   register	_exitfuncr   r   r   r
   r   r   r   next_index_iterr   	_registry_dirty)selfobjr   r   r   r   infos          r   __init__zweakref_finalize.__init__+   s    + 	< MMMOODN+++7;4zz||3~~		n$*++
#t"&r   Nc                     | j                             | d          }|r | j        s |j        |j        i |j        pi S dS dS )zZIf alive then mark as dead and return func(*args, **kwargs);
        otherwise return NoneN)r   pop	_shutdownr   r   r   )r   _r!   s      r   __call__zweakref_finalize.__call__=   sf     ~!!$-- 	@ 	@49di?DK,=2???	@ 	@ 	@ 	@r   c                     | j                             |           }|o|                                }|2| j                             | d          r||j        |j        |j        pi fS dS dS )z^If alive then mark as dead and return (obj, func, args, kwargs);
        otherwise return NoneN)r   getr
   r$   r   r   r   r   r!   r    s      r   detachzweakref_finalize.detachD   sk     ~!!$''%t||~~?t~11$==?DIt{/@bAA ???r   c                     | j                             |           }|o|                                }|||j        |j        |j        pi fS dS )zMIf alive then return (obj, func, args, kwargs);
        otherwise return NoneN)r   r)   r
   r   r   r   r*   s      r   peekzweakref_finalize.peekL   sQ     ~!!$''%t||~~?DIt{/@bAA ?r   c                     | | j         v S )zWhether finalizer is alive)r   )r   s    r   alivezweakref_finalize.aliveT   s     t~%%r   c                 b    | j                             |           }t          |          o|j        S )z*Whether finalizer should be called at exitr   r)   boolr   )r   r!   s     r   r   zweakref_finalize.atexitY   s,     ~!!$''Dzz)dk)r   c                 j    | j                             |           }|rt          |          |_        d S d S Nr1   )r   valuer!   s      r   r   zweakref_finalize.atexit_   s:    ~!!$'' 	&u++DKKK	& 	&r   c                 @   | j                             |           }|o|                                }|&dt          |           j        t          |           fz  S dt          |           j        t          |           t          |          j        t          |          fz  S )Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)r   r)   r
   typer   idr*   s      r   __repr__zweakref_finalize.__repr__e   s    ~!!$''%t||~~;-d1Dbhh0OOO6T

#4S		"3	:  r   c                     d | j                                         D             }|                    d            d |D             S )Nc                 *    g | ]\  }}|j         ||fS r   )r   .0fis      r   
<listcomp>z5weakref_finalize._select_for_exit.<locals>.<listcomp>u   s'    DDDA18DaVDDDr   c                     | d         j         S )N   )r   )items    r   <lambda>z3weakref_finalize._select_for_exit.<locals>.<lambda>v   s    Q r   )keyc                     g | ]\  }}|S r   r   r<   s      r   r@   z5weakref_finalize._select_for_exit.<locals>.<listcomp>w   s    """fq!"""r   )r   itemssort)clsLs     r   _select_for_exitz!weakref_finalize._select_for_exitr   sR     ED#-"5"5"7"7DDD	--...""""""r   c                 ,   d}	 | j         rdd l}|                                rd}|                                 d }	 |t          j        r |                                 }dt          _        |sn[|                                }	  |             n/# t          $ r" t          j
        t          j                      Y nw xY w|| j         vsJ dt          _        |r|                                 d S d S # dt          _        |r|                                 w w xY w)NFr   T)r   gc	isenableddisabler   r   rK   r$   	Exceptionsys
excepthookexc_infor%   enable)rI   reenable_gcrM   pendingr>   s        r   r   zweakref_finalize._exitfuncy   sE   
 	} 2			<<>> !"&KJJLLL2*:*A"%"6"6"8"827(/" A8
 $ 8 8 877778CM11112$ *.& 		  *.& 		s0   A=C. 
B C. )B96C. 8B99C. .%Dr4   )r   r   r   __doc__r   r   r%   	itertoolscountr   r   r   objectr   r"   r'   r+   r-   propertyr/   r   setterr9   classmethodrK   r   r   r   r   r   r      s^       	 	 III!)/##KF#M M M M M M M M' ' '$@ @ @ @B B BB B B & & X& * * X*
 ]& & ]&
   # # [# ! ! [! ! !r   )
rW   
__future__r   rX   rQ   r
   r   __all__rZ   r   r   r   r   <module>r`      s     ' & & & & &     



      
J J J J Jv J J J J Jr   