
    3 d                         U 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	  e
d          Z ee	          Zee
e	f         ed<    G d	 d
          ZefdZd Zd Zd ZdS )a  This module provides some functions and classes to record and report
references to live object instances.

If you want live objects for a particular class to be tracked, you only have to
subclass from object_ref (instead of object).

About performance: This library has a minimal performance impact when enabled,
and no performance penalty at all when disabled (as object_ref becomes just an
alias to object in that case).
    )defaultdict)
itemgetter)time)DefaultDict)WeakKeyDictionaryN	live_refsc                       e Zd ZdZdZd ZdS )
object_refz<Inherit from this class to a keep a record of live instances c                 r    t                               |           }t                      t          |          |<   |S )N)object__new__r   r   )clsargskwargsobjs       5lib/python3.11/site-packages/scrapy/utils/trackref.pyr   zobject_ref.__new__   s*    nnS!!"ff	#s
    N)__name__
__module____qualname____doc__	__slots__r   r   r   r   r
   r
      s.        FFI    r   r
   c           
      R   d}t                      }t          t                                          d           D ]l\  }}|st	          ||           rt          |                                          }||j        ddt          |          ddt          ||z
             dz  }m|S )	z2Return a tabular representation of tracked objectszLive References

c                     | d         j         S )Nr   )r   )xs    r   <lambda>z"format_live_refs.<locals>.<lambda>%   s    adm r   keyz<30 6z   oldest: zs ago
)
r   sortedr   items
issubclassminvaluesr   lenint)ignoresnowr   wdictoldests         r   format_live_refsr.   !   s    A
&&CY__..4K4KLLL W W
U 	c6"" 	U\\^^$$	VVV3u::VVVCf<M<MVVVVHr   c                  8    t          t          | i |           dS )zPrint tracked objectsN)printr.   )akws     r   print_live_refsr3   /   s$    	
A
$
$
$%%%%%r   c                     t                                           D ]M\  }}|j        | k    r=|s dS t          |                                t	          d                    d         c S NdS )z/Get the oldest object for a specific class name   r   r   N)r   r#   r   r%   r   
class_namer   r,   s      r   
get_oldestr8   4   sx    oo'' < <
U<:% 	< u{{}}*Q--888;;;;	<< <r   c                     t                                           D ]&\  }}|j        | k    r|                                c S 'dS )z<Iterate over all objects of the same class by its class nameN)r   r#   r   keysr6   s      r   iter_allr;   =   sQ    oo''    
U<:% 	 ::<<	    r   )r   collectionsr   operatorr   r   typingr   weakrefr   typeNoneTyper   __annotations__r
   r.   r3   r8   r;   r   r   r   <module>rC      s  	 	 	 $ # # # # #                   % % % % % %4::2=+>O2P2P	;t../ P P P        %    & & &
< < <         r   