o
    h_                     @   sN   d dl Z d dlZd dlZd dlZd dlmZmZ dddZG dd deZdS )    N)AsyncFileSystemrunning_asyncc                    s   t   fdd}|S )a  
    Wraps a synchronous function to make it awaitable.

    Parameters
    ----------
    func : callable
        The synchronous function to wrap.
    obj : object, optional
        The instance to bind the function to, if applicable.
    semaphore : asyncio.Semaphore, optional
        A semaphore to limit concurrent calls.

    Returns
    -------
    coroutine
        An awaitable version of the function.
    c               	      sz   r.4 I d H  t j g| R i |I d H W  d   I d H  S 1 I d H s)w   Y  t j g| R i |I d H S N)asyncioZ	to_thread)argskwargsfunc	semaphore i/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/fsspec/implementations/asyn_wrapper.pywrapper   s   ,zasync_wrapper.<locals>.wrapper)	functoolswraps)r	   objr
   r   r   r   r   async_wrapper	   s   r   c                       sV   e Zd ZdZdZdZ						d fdd	Zedd Zd	d
 Z	e
dd Z  ZS )AsyncFileSystemWrapperaX  
    A wrapper class to convert a synchronous filesystem into an asynchronous one.

    This class takes an existing synchronous filesystem implementation and wraps all
    its methods to provide an asynchronous interface.

    Parameters
    ----------
    sync_fs : AbstractFileSystem
        The synchronous filesystem instance to wrap.
    )Zasyncwrapperr   FNc                    sd   |d u rt  }t jdd|i| |d ur|| _n
tj|fi || _| jj| _|| _|   d S )Nasynchronousr   )	r   super__init__sync_fsfsspec
filesystemprotocolr
   _wrap_all_sync_methods)selffsr   Ztarget_protocolZtarget_optionsr
   Zmax_concurrent_tasksr   	__class__r   r   r   6   s   

zAsyncFileSystemWrapper.__init__c                 C   s   d| j j S )NZasync_)r   fsid)r   r   r   r   r   K   s   zAsyncFileSystemWrapper.fsidc                 C   s   dh}t | jD ]9}|ds||v rqt| j|}t|tr!qt| j|}t|rAt	|sAt
|| | jd}t| d| | qdS )zg
        Wrap all synchronous methods of the underlying filesystem with asynchronous versions.
        open_)r   r
   N)dirr   
startswithinspectgetattr_static
isinstancepropertygetattrcallableiscoroutinefunctionr   r
   setattr)r   Zexcluded_methodsmethod_nameattrmethodZasync_methodr   r   r   r   O   s   
z-AsyncFileSystemWrapper._wrap_all_sync_methodsc                    s(   G  fddd| }d j  d|_ |S )a  
        Create a new class that can be used to instantiate an AsyncFileSystemWrapper
        with lazy instantiation of the underlying synchronous filesystem.

        Parameters
        ----------
        sync_fs_class : type
            The class of the synchronous filesystem to wrap.

        Returns
        -------
        type
            A new class that wraps the provided synchronous filesystem class.
        c                       s   e Zd Z fddZ  ZS )zJAsyncFileSystemWrapper.wrap_class.<locals>.GeneratedAsyncFileSystemWrapperc                    s   |i |}t  | d S r   )r   r   )r   r   r   r   )r   sync_fs_classr   r   r   s   s   zSAsyncFileSystemWrapper.wrap_class.<locals>.GeneratedAsyncFileSystemWrapper.__init__)__name__
__module____qualname__r   __classcell__r   r/   r   r   GeneratedAsyncFileSystemWrapperr   s    r5   ZAsyncZWrapper)r0   )clsr/   r5   r   r4   r   
wrap_classa   s   z!AsyncFileSystemWrapper.wrap_class)NNNNNN)r0   r1   r2   __doc__r   Zcachabler   r'   r   r   classmethodr7   r3   r   r   r   r   r   &   s     
r   )NN)	r   r   r$   r   Zfsspec.asynr   r   r   r   r   r   r   r   <module>   s    
