
    wg0                     F    d dl Z d dlZd dlZd dlmZ ddZ G d de      Zy)    N)AsyncFileSystemc                 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     h/home/mcse/projects/flask/flask-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                   H     e Zd ZdZ 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.
    c                     t        |   |i | d| _        || _        | j                  j                  | _        | j                          y )NT)super__init__asynchronoussync_fsprotocol_wrap_all_sync_methods)selfr   r	   r
   	__class__s       r   r   zAsyncFileSystemWrapper.__init__-   sA    $)&) --##%r   c                 4    d| j                   j                   S )Nasync_)r   fsid)r   s    r   r    zAsyncFileSystemWrapper.fsid4   s    ))*++r   c                 h   t        | j                        D ]  }|j                  d      rt        j                  | j                  |      }t        |t              rFt        | j                  |      }t        |      sht        j                  |      r~t        ||       }t        | d| |        y)zg
        Wrap all synchronous methods of the underlying filesystem with asynchronous versions.
        _)r   N)dirr   
startswithinspectgetattr_static
isinstancepropertygetattrcallabler   iscoroutinefunctionr   setattr)r   method_nameattrmethodasync_methods        r   r   z-AsyncFileSystemWrapper._wrap_all_sync_methods8   s     t||, 	?K%%c*))$,,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__[   s    '88 )r   )__name__
__module____qualname__r   __classcell__)r   r5   s   @r   GeneratedAsyncFileSystemWrapperr3   Z   s    * *r   r:   AsyncWrapper)r6   )clsr5   r:   s    ` r   
wrap_classz!AsyncFileSystemWrapper.wrap_classI   s4    "	*c 	* M**+73 	(0 /.r   )r6   r7   r8   __doc__r   r(   r    r   classmethodr>   r9   )r   s   @r   r   r       s:    
& , ,?" / /r   r   r   )r   r   r%   fsspec.asynr   r   r    r   r   <module>rC      s$       '0B/_ B/r   