
    h_                     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                 F     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   r=4 d {    t        j                  g| i | d {   cd d d       d {    S t        j                  g| i | d {   S 7 W7 87 *# 1 d {  7  sw Y   9xY w7 wN)asyncio	to_thread)argskwargsfunc	semaphores     a/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/fsspec/implementations/asyn_wrapper.pywrapperzasync_wrapper.<locals>.wrapper   s       F F$..tEdEfEEF F F&&t=d=f===FEF F F F=s]   	BA$BA*A&A*BA(!BA? B&A*(B*A<0A31A<8B)	functoolswraps)r   objr   r   s   ` ` r   async_wrapperr   	   s'    & __T> > N    c                   ^     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protocolr   _wrap_all_sync_methods)	selffsr   target_protocoltarget_optionsr   max_concurrent_tasksr   	__class__s	           r   r   zAsyncFileSystemWrapper.__init__6   sn     (?L=l=f=>DL!,,_OODL--"##%r   c                 4    d| j                   j                   S )Nasync_)r   fsid)r"   s    r   r*   zAsyncFileSystemWrapper.fsidK   s    ))*++r   c                    dh}t        | j                        D ]  }|j                  d      s||v rt        j                  | j                  |      }t        |t              rJt        | j                  |      }t        |      slt        j                  |      rt        || | j                        }t        | d| |        y)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))$,,DD$)T\\;7F(C(CF(K,VX+/>	?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   s    '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   s4    "	*c 	* M**+73 	(0 /.r   )NNNNNN)rB   rC   rD   __doc__r    cachabler   r3   r*   r!   classmethodrJ   rE   )r'   s   @r   r   r   &   sZ    
 /HH !&* , ,?$ / /r   r   )NN)	r   r   r0   r   fsspec.asynr   r   r   r   r   r   r   <module>rO      s'        6:T/_ T/r   