
    Yh_                     Z    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Z G d de          ZdS )    N)AsyncFileSystemrunning_asyncc                 J     t          j                    f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                     K   rG4 d {V  t          j        g| R i | d {V cd d d           d {V  S # 1 d {V swxY w Y   t          j        g| R i | d {V S N)asyncio	to_thread)argskwargsfunc	semaphores     u/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/fsspec/implementations/asyn_wrapper.pywrapperzasync_wrapper.<locals>.wrapper   sQ      	F  F F F F F F F F$.tEdEEEfEEEEEEEEF F F F F F F F F F F F F F F F F F F F F F F F F F F F&t=d===f=========s   <
A	A)	functoolswraps)r   objr   r   s   ` ` r   async_wrapperr   	   s@    & _T> > > > > > N    c                   j     e Zd ZdZdZdZ	 	 	 	 	 	 d	 fd	Zed             Zd Z	e
d             Z x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.
    )asyncwrapperr   FNc                     |t                      } t                      j        dd|i| ||| _        nt	          j        |fi || _        | j        j        | _        || _        |                                  d S )Nasynchronous )	r   super__init__sync_fsfsspec
filesystemprotocolr   _wrap_all_sync_methods)	selffsr   target_protocoltarget_optionsr   max_concurrent_tasksr   	__class__s	           r   r   zAsyncFileSystemWrapper.__init__6   s     (??L==l=f===>DLL!,_OOOODL-"##%%%%%r   c                      d| j         j         S )Nasync_)r   fsid)r"   s    r   r*   zAsyncFileSystemWrapper.fsidK   s    +)+++r   c                    dh}t          | j                  D ]}|                    d          s||v rt          j        | j        |          }t          |t                    rLt          | j        |          }t          |          r?t          j	        |          s+t          || | j                  }t          | d| |           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"   excluded_methodsmethod_nameattrmethodasync_methods         r   r!   z-AsyncFileSystemWrapper._wrap_all_sync_methodsO   s     #8t|,, 	? 	?K%%c** k=M.M.M)$,DDD$)) T\;77F ?(CF(K(K ?,VXXX/+//>>>	? 	?r   c                 H     G f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                   "     e Zd Z fdZ xZS )JAsyncFileSystemWrapper.wrap_class.<locals>.GeneratedAsyncFileSystemWrapperc                 Z     |i |}t                                          |           d S r   )r   r   )r"   r
   r   r   r'   sync_fs_classs       r   r   zSAsyncFileSystemWrapper.wrap_class.<locals>.GeneratedAsyncFileSystemWrapper.__init__s   s5    '-888  )))))r   )__name__
__module____qualname__r   __classcell__)r'   rA   s   @r   GeneratedAsyncFileSystemWrapperr?   r   s>        * * * * * * * * * *r   rF   AsyncWrapper)rB   )clsrA   rF   s    ` r   
wrap_classz!AsyncFileSystemWrapper.wrap_classa   sZ    "	* 	* 	* 	* 	* 	* 	*c 	* 	* 	* 4M*333 	(0 /.r   )NNNNNN)rB   rC   rD   __doc__r    cachabler   r3   r*   r!   classmethodrJ   rE   )r'   s   @r   r   r   &   s        
 
 /HH !& & & & & &* , , X,? ? ?$ / / [/ / / / /r   r   )NN)	r   r   r0   r   fsspec.asynr   r   r   r   r   r   r   <module>rO      s           6 6 6 6 6 6 6 6   :T/ T/ T/ T/ T/_ T/ T/ T/ T/ T/r   