
    g
                     :    d dl Z d dlmZ d dlmZ  G d de      Zy)    N)MutableMapping)	lru_cachec                   N    e Zd ZdZ	 	 	 ddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zy)DirCachea  
    Caching of directory listings, in a structure like::

        {"path0": [
            {"name": "path0/file0",
             "size": 123,
             "type": "file",
             ...
            },
            {"name": "path0/file1",
            },
            ...
            ],
         "path1": [...]
        }

    Parameters to this class control listing expiry or indeed turn
    caching off
    Nc                      i  _         i  _        |r t        |dz          fd       _        | _        | _        | _        y)a  

        Parameters
        ----------
        use_listings_cache: bool
            If False, this cache never returns items, but always reports KeyError,
            and setting items has no effect
        listings_expiry_time: int or float (optional)
            Time in seconds that a listing is considered valid. If None,
            listings do not expire.
        max_paths: int (optional)
            The number of most recent listings that are considered valid; 'recent'
            refers to when the entry was set.
           c                 <    j                   j                  | d       S N)_cachepop)keyselfs    D/var/www/openai/venv/lib/python3.12/site-packages/fsspec/dircache.py<lambda>z#DirCache.__init__.<locals>.<lambda>3   s    4;;??3PT;U    N)r   _timesr   _quse_listings_cachelistings_expiry_time	max_paths)r   r   r   r   kwargss   `    r   __init__zDirCache.__init__   sE    * .i	A./UVDG"4$8!"r   c                 
   | j                   L| j                  j                  |d      t        j                         z
  | j                    k  r| j                  |= | j
                  r| j                  |       | j                  |   S )Nr   )r   r   gettimer   r   r   r   items     r   __getitem__zDirCache.__getitem__8   sf    $$0{{tQ'$))+59R9R8RRKK%>>GGDM{{4  r   c                 8    | j                   j                          y r
   )r   clearr   s    r   r    zDirCache.clear@   s    r   c                 ,    t        | j                        S r
   )lenr   r!   s    r   __len__zDirCache.__len__C   s    4;;r   c                 .    	 | |    y# t         $ r Y yw xY w)NTF)KeyErrorr   s     r   __contains__zDirCache.__contains__F   s#    	J 		s    	c                     | j                   sy | j                  r| j                  |       || j                  |<   | j                  "t        j
                         | j                  |<   y y r
   )r   r   r   r   r   r   r   )r   r   values      r   __setitem__zDirCache.__setitem__M   sS    &&>>GGCL C$$0#yy{DKK 1r   c                     | j                   |= y r
   )r   )r   r   s     r   __delitem__zDirCache.__delitem__V   s    KKr   c                 D     t         j                        } fd|D        S )Nc              3   ,   K   | ]  }|v s|  y wr
    ).0kr   s     r   	<genexpr>z$DirCache.__iter__.<locals>.<genexpr>\   s     07aa4i7s   	)listr   )r   entriess   ` r   __iter__zDirCache.__iter__Y   s    t{{#0700r   c                 T    t         | j                  | j                  | j                  ffS r
   )r   r   r   r   r!   s    r   
__reduce__zDirCache.__reduce__^   s)    $$d&?&?P
 	
r   )TNN)__name__
__module____qualname____doc__r   r   r    r$   r'   r*   r,   r5   r7   r/   r   r   r   r      s?    ,  !	#:! +1

r   r   )r   collections.abcr   	functoolsr   r   r/   r   r   <module>r>      s     * \
~ \
r   