o
    iv                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
Z
d dlZe
 dd ZG dd dZe
jdd	d
deeddf fddZe
jdddd ZdS )    N)deque)	GeneratorSequencec               	   c   s|    t d} | j  | j  | jd z| V  W | j  | j  | jd dS | j  | j  | jd w )z0
    Fixture providing a memory filesystem.
    Zmemory N)fsspec
filesystemstoreclearZpseudo_dirsappend)m r   ^/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/fsspec/conftest.pyr      s   






r   c                   @   s:   e Zd ZdZdddZdddedeeef fd	d
Z	dS )InstanceCacheInspectorzQ
    Helper class to inspect instance caches of filesystem classes in tests.
    returnNc                 C   s<   t tjjg}|r| }|  ||  |s	dS dS )zU
        Clear instance caches of all currently imported filesystem classes.
        N)r   r   specAbstractFileSystempopleftZclear_instance_cacheextend__subclasses__)selfclassesclsr   r   r   r	   $   s   zInstanceCacheInspector.clearT)	omit_zeror   c                C   sz   i }t tjjg}|r;| }t|j}t|jt	t
fr2t|jt
r%|jn|jd }|s.|s2|||< ||  |s|S )a  
        Gather counts of filesystem instances in the instance caches
        of all currently imported filesystem classes.

        Parameters
        ----------
        omit_zero:
            Whether to omit instance types with no cached instances.
        r   )r   r   r   r   r   len_cache
isinstanceprotocolr   strr   r   )r   r   outr   r   countkeyr   r   r   gather_counts.   s   


z$InstanceCacheInspector.gather_counts)r   N)
__name__
__module____qualname____doc__r	   booldictr   intr!   r   r   r   r   r      s    
$
r   functionT)scopeZautouser   c                  c   s0    t  } |   z
| V  W |   dS |   w )as  
    Fixture to ensure empty filesystem instance caches before and after a test.

    Used by default for all tests.
    Clears caches of all imported filesystem classes.
    Can be used to write test assertions about instance caches.

    Usage:

        def test_something(instance_caches):
            # Test code here
            fsspec.open("file://abc")
            fsspec.open("memory://foo/bar")

            # Test assertion
            assert instance_caches.gather_counts() == {"file": 1, "memory": 1}

    Returns
    -------
    instance_caches: An instance cache inspector for clearing and inspecting caches.
    N)r   r	   )Zicr   r   r   instance_cachesG   s   r+   )r*   c                 c   s    t d t| }ttj|dd}|dd  W d   n1 s&w   Y  t	t
jddd|d	d
dddg
}z$td dV  W |  |  zt|  W dS  ty_   Y dS w |  |  zt|  W w  tyx   Y w w )z6
    Fixture providing a writable FTP filesystem.
    Z	pyftpdlibr   wbs   helloi'  Nz-mz-dz-uuserz-Ppassz-w   )	localhostiI  r-   r.   )pytestZimportorskipr   openospathjoinwrite
subprocessPopensys
executabletimesleep	terminatewaitshutilrmtree	Exception)ZtmpdirdfPr   r   r   ftp_writableg   s4   

rE   )r3   r?   r7   r9   r;   collectionsr   collections.abcr   r   r1   r   Zfixturer   r   r+   rE   r   r   r   r   <module>   s     
(
