Ë
    #täiš  ã                   ó`   — 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lmZ dd„Z	 G d„ dee«      Z
y)	é    N)ÚAsyncFileSystemÚrunning_asyncé   )ÚChainedFileSystemc                 ó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     €€úr/Volumes/fast/ai/experiments/MLX_z-image/.venv/lib/python3.12/site-packages/fsspec/implementations/asyn_wrapper.pyÚwrapperzasync_wrapper.<locals>.wrapper   sk   øè ø€ áß ’yÜ$×.Ñ.¨tÐE°dÒE¸fÑE×E÷ !—y‘yä×&Ñ& tÐ=¨dÒ=°fÑ=×=Ð=ð !øØEøð !ø—y—y‘yúà=ú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__8   sn   ø€ ð ÐÜ(›?ˆLÜ‰ÑÑ= lÐ=°fÒ=Øˆ>ØˆD�Lä!×,Ñ,¨_ÑOÀÑOˆDŒLØŸ™×-Ñ-ˆŒØ"ˆŒØ×#Ñ#Õ%r   c                 ó4   — d| j                   j                  › �S )NÚasync_)r   Úfsid)r$   s    r   r,   zAsyncFileSystemWrapper.fsidM   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_methodsQ   s¥   € ð #˜8ÐÜ˜tŸ|™|Ö,ˆKØ×%Ñ% cÔ*¨kÐ=MÑ.MØä×)Ñ)¨$¯,©,¸ÓDˆDÜ˜$¤Ô)Øä˜TŸ\™\¨;Ó7ˆFÜ˜Õ¬×(CÑ(CÀFÕ(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__u   s   ø€ Ù'¨Ð8°Ñ8�Ü‘Ñ  Õ)r   )Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__)r)   rC   s   @€r   ÚGeneratedAsyncFileSystemWrapperrA   t   s   ù„ ÷*ñ *r   rH   ÚAsyncÚWrapper)rD   )ÚclsrC   rH   s    ` r   Ú
wrap_classz!AsyncFileSystemWrapper.wrap_classc   s4   ø€ ö"	*¨cô 	*ð �M×*Ñ*Ð+¨7Ð3ð 	(Ô0ð /Ð.r   )NNNNNN)rD   rE   rF   Ú__doc__r"   Úcachabler   r5   r,   r#   ÚclassmethodrL   rG   )r)   s   @r   r   r   (   sZ   ø„ ñ
ð /€HØ€Hð ØØØØØ!õ&ð* ñ,ó ð,ò?ð$ ñ/ó ô/r   r   )NN)r
   r   r2   r    Úfsspec.asynr   r   Úchainedr   r   r   r   r   r   Ú<module>rR      s-   ðÛ Û Û ã ß 6å &óô:T/˜_Ð.?õ T/r   