
    |;3h                     R    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y)    N)AsyncFileSystemrunning_asyncc                 B     t        j                          fd       }|S )aF  
    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.

    Returns
    -------
    coroutine
        An awaitable version of the function.
    c                  R   K   t        j                  g| i | d {   S 7 wN)asyncio	to_thread)argskwargsfuncs     c/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/fsspec/implementations/asyn_wrapper.pywrapperzasync_wrapper.<locals>.wrapper   s(     &&t=d=f====s   '%')	functoolswraps)r   objr   s   `  r   async_wrapperr   	   s'    " __T> > N    c                   Z     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   Fc                     |
t               }t        |   dd|i| ||| _        nt	        j
                  |fi || _        | j                  j                  | _        | j                          y )Nasynchronous )r   super__init__sync_fsfsspec
filesystemprotocol_wrap_all_sync_methods)selffsr   target_protocoltarget_optionsr   	__class__s         r   r   zAsyncFileSystemWrapper.__init__1   sg     (?L=l=f=>DL!,,_OODL--##%r   c                 4    d| j                   j                   S )Nasync_)r   fsid)r!   s    r   r(   zAsyncFileSystemWrapper.fsidC   s    ))*++r   c                 v   dh}t        | j                        D ]  }|j                  d      s||v rt        j                  | j                  |      }t        |t              rJt        | j                  |      }t        |      slt        j                  |      rt        ||       }t        | d| |        y)zg
        Wrap all synchronous methods of the underlying filesystem with asynchronous versions.
        open_)r   N)dirr   
startswithinspectgetattr_static
isinstancepropertygetattrcallabler   iscoroutinefunctionr   setattr)r!   excluded_methodsmethod_nameattrmethodasync_methods         r   r    z-AsyncFileSystemWrapper._wrap_all_sync_methodsG   s     #8t||, 	?K%%c*k=M.M))$,,DD$)T\\;7F(C(CF(K,V>+/>	?r   c                 L     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                 4     |i |}t         |   |       y r   )r   r   )r!   r
   r   r   r%   sync_fs_classs       r   r   zSAsyncFileSystemWrapper.wrap_class.<locals>.GeneratedAsyncFileSystemWrapper.__init__k   s    '88 )r   )__name__
__module____qualname__r   __classcell__)r%   r?   s   @r   GeneratedAsyncFileSystemWrapperr=   j   s    * *r   rD   AsyncWrapper)r@   )clsr?   rD   s    ` r   
wrap_classz!AsyncFileSystemWrapper.wrap_classY   s4    "	*c 	* M**+73 	(0 /.r   )NNNN)r@   rA   rB   __doc__r   cachabler   r1   r(   r    classmethodrH   rC   )r%   s   @r   r   r   !   sT    
 /HH &$ , ,?$ / /r   r   r   )	r   r   r.   r   fsspec.asynr   r   r   r   r   r   r   <module>rM      s'        60Q/_ Q/r   