← back to Atmos Game

assets/gen/.venv/lib/python3.12/site-packages/fsspec/__pycache__/asyn.cpython-312.pyc

346 lines

�

c�bjM���p�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZddl
mZddlmZddlmZddlmZmZmZdd	lmZmZdd
lmZmZmZej<d�ZdgZ dgZ!da"ejFZ#d�Z$d
�Z%d)d�Z&dd�d�Z'd)d�Z(d)d�Z)d�Z*d�Z+e,ed�rejZe+��erddl.Z.e.j^Z0n	ddl.Z.e1e.de2�Z0dZ4dZ5d*d�Z6de7fd�Z8dedddfd�Z9gd�Z:Gd �d!e�Z;d"�Z<Gd#�d$e=�Z>d%d%e>dfd&�Z?Gd'�d(e�Z@y#e3$rdZ.e2Z0Y�SwxYw)+�N)�Iterable)�	has_magic)�
TYPE_CHECKING�)�DEFAULT_CALLBACK)�FSTimeoutError)�LocalFileSystem�make_path_posix�trailing_sep)�AbstractBufferedFile�AbstractFileSystem)�glob_translate�is_exception�other_pathsz_[^_]c�B�tstj�atS)zAllocate or return a threading lock.

    The lock is allocated on first use to allow setting one lock per forked process.
    )�_lock�	threading�Lock���b/Users/macstudio3/Projects/atmos-game/assets/gen/.venv/lib/python3.12/site-packages/fsspec/asyn.py�get_lockrs������ ���Lrc�,�dtd<dtd<day)z�Reset the global lock.

    This should be called only on the init of a forked process to reset the lock to
    None, enabling the new forked process to get a new lock.
    Nr)�iothread�looprrrr�
reset_lockr&s���H�Q�K��D��G��Erc���K�|r|nd}|�tj||��}	|�d{���|d<|j�y7�#t$r}||d<Yd}~�&d}~wwxYw#|j�wxYw�w)N��timeoutr)�asyncio�wait_for�	Exception�set)�event�coro�resultr�exs     r�_runnerr(3sk���� �g�d�G�������g�6����J��q�	�	�	�	��	������q�	����	�	�	��sI� A3�A�A�A�A3�A�	A�A�A�A�A�A0�0A3rc��|r|nd}|�|j�rtd��	tjj	�}||urtd��	||i|��}dg}t
j�}tjt||||�|�	|jd�rn|�|dz}|dkrt��%|d}	t|	tj�rt|	�t|	t�r|	�|	S#t
$r�t$rY��wxYw)z�
    Make loop run coroutine until it returns. Runs in other thread

    Examples
    --------
    >>> fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args,
                         timeout=timeout, **kwargs)
    NzLoop is not runningz)Calling sync() from within a running looprr)�	is_closed�RuntimeErrorr �events�get_running_loop�NotImplementedErrorr�Event�run_coroutine_threadsafer(�waitr�
isinstance�TimeoutError�
BaseException)
r�funcr�args�kwargs�loop0r%r&r$�
return_results
          r�syncr:?s!��!�g�d�G��|�t�~�~�'��0�1�1�
����/�/�1���D�=�%�&Q�R�R���� �� �D��V�F��O�O��E��$�$�W�U�D�&�'�%J�D�Q�
��:�:�a�=�����q�L�G���{�$�$���1�I�M��-��!5�!5�6��-�/�	�M�=�	1������1��
��
��
�s�-C4�4D	�D	c�F���tj����fd��}|S)z�Given a function, make so can be called in blocking contexts

    Leave obj=None if defining within a class. Pass the instance if attaching
    as an attribute of the instance.
    c�J���xs|d}t|j�g|��i|��S�Nr)r:r)r6r7�selfr5�objs   ��r�wrapperzsync_wrapper.<locals>.wrapperss+����~�d�1�g���D�I�I�t�5�d�5�f�5�5r��	functools�wraps�r5r?r@s`` r�sync_wrapperrEls'����_�_�T��6��6��Nrc�F���tj����fd��}|S)zCGiven a async generator, make so can be called in blocking contextsc?��K��xs|d}�|i|��}		t|j|j����$#t$rYywxYw�wr=)r:r�	__anext__�StopAsyncIteration)r6r7r>�genr5r?s    ��rr@z"async_gen_wrapper.<locals>.wrapper~sX������~�d�1�g���D�#�F�#���
��4�9�9�c�m�m�4�4���&�
��
�s%�A	�":�A	�	A�A	�A�A	rArDs`` r�async_gen_wrapperrK{s'����_�_�T������Nrc�^�td��t�5td�ctj�td<t	j
tdjd��}d|_|j�|td<ddd�tdStdS#1swYtdSxYw)zdCreate or return the default fsspec IO loop

    The loop will be running on a separate thread.
    rN�fsspecIO)�target�nameT)
rrr �new_event_loopr�Thread�run_forever�daemon�startr)�ths r�get_looprV�s���
�A�w��
�Z��A�w��!�0�0�2��Q���%�%�T�!�W�-@�-@�z�R�� ��	����
� �������7�N�4��7�N����7�N�s�A-B�B,c�,�dtd<dtd<dayr=)rr�lockrrr�reset_after_forkrY�s���D��G��H�Q�K��Dr�register_at_fork)�after_in_child�error�iFc��ddlm}|r	d|vr|dSd|vr|dS|rtSt�tS	tj
tj�\}}|tjk(ry|dzS#tttf$r	tcYSwxYw)Nr)�conf�nofiles_gather_batch_size�gather_batch_size������)�
fsspec.configr_�_NOFILES_DEFAULT_BATCH_SIZE�resource�_DEFAULT_BATCH_SIZE�	getrlimit�
RLIMIT_NOFILE�ImportError�
ValueError�
ResourceError�
RLIM_INFINITY)�nofilesr_�
soft_limit�_s    r�_get_batch_sizerq�s���"��&�$�.��3�4�4��$�&��+�,�,��*�*���"�"�#� �*�*�8�+A�+A�B�
�
�A��X�+�+�+���Q����

��]�3�#�"�"�#�s�&A/�/B�B�returnc�L�	tj�y#t$rYywxYw)z Being executed by an event loop?TF)r r-r+rrr�
running_asyncrt�s(���� � �"�������s��	#�#c������K�|�t|��}|dk(rt|�}n|dkrt����fd�}d}t|�}dg|z}	t�}
|
s||kr�t|
�|krL||krG|
j	tj||||���|dz
}t|
�|kr||kr�G|
s	|	Stj|
t
j���d{���\}}
d}|r&|j�}
	|
�d{���\}}||	|<|r�&|�8|
D]}
|
j��|
rtj|
dd	i��d{���|�|
r��||kr��|	S7�v7�V#t$r}|�|}Yd}~�^d}~wwxYw7�/�w)
aSRun the given coroutines in  chunks.

    Parameters
    ----------
    coros: list of coroutines to run
    batch_size: int or None
        Number of coroutines to submit/wait on simultaneously.
        If -1, then it will not be any throttling. If
        None, it will be inferred from _get_batch_size()
    callback: fsspec.callbacks.Callback instance
        Gets a relative_update when each coroutine completes
    timeout: number or None
        If given, each coroutine times out after this time. Note that, since
        there are multiple batches, the total run time of this function will in
        general be longer
    return_exceptions: bool
        Same meaning as in asyncio.gather
    nofiles: bool
        If inferring the batch_size, does this operation involve local files?
        If yes, you normally expect smaller batches.
    N)rnrbrc����K�	tj|����d{���|f�jd�S7�#t$r"}�s�||fcYd}~�jd�Sd}~wwxYw#�jd�wxYw�w)Nrr)r r!�relative_updater")r%�i�e�callback�return_exceptionsrs   ���r�	_run_coroz'_run_coros_in_chunks.<locals>._run_corosw�����	(� �)�)�$��@�@�!�C�
�$�$�Q�'�
A���	�$���a�4�K��$�$�Q�'��	��

�$�$�Q�'�sO�A=�9�7�9�A=�9�	A$�A�A$�	A'�
A=�A$�$A'�'A:�:A=r)�return_whenr{T)
rq�lenrkr#�addr �
ensure_futurer1�FIRST_COMPLETED�popr"�cancel�gather)�coros�
batch_sizerzrr{rnr|rx�n�results�pending�done�	first_exc�taskr&�k�excs  ```            r�_run_coros_in_chunksr��s������<��$�W�5�
��R����Z�
�	�q����(�	
�A��E�
�A��f�q�j�G��e�G�
�Q��U��'�l�Z�'�A��E��K�K��-�-�i��a��!�.D�E�F�
��F�A��'�l�Z�'�A��E���(�N�%&�l�l�7��@W�@W�X�X�
��g��	���8�8�:�D�
$�"&�J�	���#���
�	�� ������
� ���n�n�g�F��F�F�F��O�1�Q��U�4�N�%Y��
'���
$��$� #�I���
$��G�sr�B/E9�5-E9�"E�#E9�?E�E�E�E9�3E9�E7�E9�E9�E9�E�	E4�&E/�*E9�/E4�4E9)�_ls�	_cat_file�	_get_file�	_put_file�_rm_file�_cp_file�
_pipe_file�_expand_path�_info�_isfile�_isdir�_exists�_walk�_glob�_find�_du�_size�_mkdir�	_makedirsc�D��eZdZdZdZdZdZdddd��fd�
Zed��Z	d�Z
d&d	�Zd
�Zd�Z
				d'd�Zd(d
�Zd)d�Zd�Zd)d�Z	d*d�Z			d+d�Zd(d�Zdeddfd�Zd�Zdedfd�Zd�Zd�Zd�Zd,d�Zd�Zd�Zd-d�Z d.d�Z!d,d�Z"d/d �Z#d0d!�Z$	d1d"�Z%d-d#�Z&d2d$�Z'd3d%�Z(�xZ)S)4�AsyncFileSystemakAsync file operations, default implementations

    Passes bulk operations to asyncio.gather for concurrent operation.

    Implementations that have concurrent batch operations and/or async methods
    should inherit from this class instead of AbstractFileSystem. Docstrings are
    copied from the un-underscored method in AbstractFileSystem, if not given.
    TFN)�asynchronousrr�c���||_tj�|_|s|xs
t	�|_nd|_||_t�|� |i|��y�N)	r��os�getpid�_pidrV�_loopr��super�__init__)r>r�rr�r6r7�	__class__s      �rr�zAsyncFileSystem.__init__WsI���(����I�I�K��	���+���D�J��D�J�$���
���$�)�&�)rc�r�|jtj�k7rtd��|jS)NzThis class is not fork-safe)r�r�r�r+r��r>s rrzAsyncFileSystem.loopas*���9�9��	�	��#��<�=�=��z�z�rc���K�tj|j�rCt|�jtjur|j|fddd�|���d{���St
�7�
�w)NFr)�	recursiver�)�inspect�iscoroutinefunction�_rm�typer�r.�r>�pathr7s   rr�zAsyncFileSystem._rm_filegsZ�����'�'����1��T�
���o�&9�&9�9�!����$�P�%�A�P��P�P�P�!�!�Q�s�AA-� A+�!A-c
���K�|xs|j}|j||���d{���}tt|�D�cgc]}|j|fi|����c}|d���d{���S7�Bcc}w7��w)N�r�T�r�rn)r�r�r��reversedr�)r>r�r�r�r7�ps      rr�zAsyncFileSystem._rmosx�����2�4�?�?�
��&�&�t�y�&�A�A��)�19�$��@��A�]�T�]�]�1�
'��
'��@�!��
�
�	
�B��@�
�s-�'A5�A,�A5�A.�
A5�'A3�(A5�.A5c��K�t��wr��r.)r>�path1�path2r7s    rr�zAsyncFileSystem._cp_filey�����!�!���	c��zK�|j||��d{���|j|��d{���y7�7��wr�)r�r�)r>r�r�s   r�_mv_filezAsyncFileSystem._mv_file|s5�����m�m�E�5�)�)�)��m�m�E�"�"�"�	*��"�s�;�7�;�9�;�;c	��K�|�|rd}n|�d}t|t�rt|t�r|}|}	n�t|t�}
|j|||���d{���}|
r<|r|�8|D�cgc]*}t	|�r�|j|��d{���r�)|��,}}|syt
|�dk(}t|t�xr&t	|�xs|j|��d{���}
|
xr/t|�xr|xst|�xr|
xrt	|�}t||||
��}	|xs|j}t||	�D��cgc]\}}|j||fi|����}}}t||dd���d{���}tt|�D]}|dk(rt|t�r�|�y7��P7��cc}w7��cc}}w7�D�w)N�ignore�raise)�maxdepthr�r��exists�flattenT)r�r{rn)r2�list�strr�rr�r~rrr��zipr�r��filterr�FileNotFoundError)r>r�r�r��on_errorr�r�r7�paths1�paths2�
source_is_strr��source_is_file�dest_is_dirr��p1�p2r�r&r's                    r�_copyzAsyncFileSystem._copy�s�������	��H�
�
��H��e�T�"�z�%��'>��F��F�&�u�c�2�M��,�,���I�-���F��i�8�3G� &��%�!�l�1�o�t�{�{�ST�~�AU�AU�A�v����� ��[�A�-�N�$�U�C�0���U�#�?�T�[�[��-?�'?�
�#���5�!�4�n�V�!�%�(�(�T�[�T��e�AT�=T�
�!����)�)�	�F� �2�4�?�?�
�?B�6�6�?R�S�?R�V�R������r�2�0��0�?R��S�+��j�D�$�
�
����v�.�B��8�#�
�2�7H�(I���H�/�C��BV���(@��T�
�sn�AF?�F*�F?�)F0�:F0�F-
�F0�F0�AF?�F5�A&F?�F7�#F?�8F=�92F?�-F0�0F?�7F?c��K�t��wr�r�)r>r��value�moder7s     rr�zAsyncFileSystem._pipe_file�r�r�c���K�t|t�r||i}|xs|j}t|j	�D��cgc]\}}|j
||fi|����c}}|d���d{���Scc}}w7�
�w)NTr�)r2r�r�r��itemsr�)r>r�r�r�r7r��vs       r�_pipezAsyncFileSystem._pipe�su�����d�C� ��%�=�D��2�4�?�?�
�)�9=����F����A�_�T�_�_�Q��
,�V�
,��F�!��
�
�	
��F�
�s�=A8�A0
�A8�+A6�,A8c��HK�d}d}|�5|dkr0|�|}d}d}n*|xs|j|��d{���d}||z}n|�d}|sR|�-|dkr(|�*|xs|j|��d{���d}||z}n|�d}t|tj�r|dz}d|�d	|��S7�m7�:�w)
z"Helper for "Range"-based _cat_fileNFr�T�sizerzbytes=�-)r�r2�numbers�Integral)r>�urlrT�endr��suffs      r�_process_limitszAsyncFileSystem._process_limits�s���������������{��f�������>�d�j�j��o� 5�v�>���u���
�]��E����3��7��$��B�$�*�*�S�/�$9�6�#B�D���*�C������#�w�/�/�0��q�����w�a��u�%�%�!6��%:�s!�.B"�B�4B"�%B �&9B"� B"c��K�t��wr�r�)r>r�rTr�r7s     rr�zAsyncFileSystem._cat_file�r�r�c��K�|j||���d{���}|D�cgc]}|j|fi|����}}|xs|j}t||dd���d{���}|dk(rt	tt|�d�}	|	r|	�t|�dkDs'tt�s|d|j|�k7r0t||�D�
�cic]\}
}|dk7st
|�s|
|��c}}
S|dS7��cc}w7��cc}}
w�w)	Nr�T�r�rnr{r�Frr�omit)r�r�r�r��nextr�rr~r2r��_strip_protocolr�)r>r�r�r�r�r7�pathsr��outr'r�r�s            r�_catzAsyncFileSystem._cat�s�����'�'��	�'�B�B��<A�B�E�D������/��/�E��B��2�4�?�?�
�(��j�$�$�
�
���w���f�\�3�/��7�B������J��N��$��%��Q�x�4�/�/��5�5� ��s�O��+�D�A�q��v�%�\�!�_��1��+��
��q�6�M�+C��B�
���s>�D�C2�D�C4�$D� C9�!A+D�C;�)
D�4D�;Dc��@K�|�t�t|t�st�t|t�s|gt|�z}t|t�s|gt|�z}t|�t|�k7st|�t|�k7rt�t|||�D��	�
cgc]\}}	}
|j|f|	|
d�|����}}	}}
|xs|j}t||dd���d{���}|dk7rttt|�d�}
|
�|
�|Scc}
}	}w7�0�w)agGet the contents of byte ranges from one or more files

        Parameters
        ----------
        paths: list
            A list of of filepaths on this filesystems
        starts, ends: int or list
            Bytes limits of the read. If using a single int, the same value will be
            used to read all the specified files.
        on_error: "return" or "raise"
            If "return" (default), any per-range exception is placed in the output
            list at the corresponding position. Otherwise the first such exception
            is raised. Matches ``AbstractFileSystem.cat_ranges``.
        N)rTr�Tr�rr)r.r2r��	TypeErrorrr~rkr�r�r�r�r�r�r)r>r��starts�ends�max_gapr�r�r7r��sryr�r�r's              r�_cat_rangeszAsyncFileSystem._cat_rangess"����0��%�%��%��&��O��&�(�+��X��E�
�*�F��$��)��6�C��J�&�D��v�;�#�e�*�$��D�	�S��Z�(?����u�f�d�3�
�3���1�a�
�D�N�N�1�7�A�1�7��7�3�	�
� �2�4�?�?�
�(��j�$�$�
�
���x���f�\�3�/��6�B��~����
��
�

�s�B"D�$!D�&D�+D�,1Dc��K�t��wr�r�)r>�lpath�rpathr�r7s     rr�zAsyncFileSystem._put_file1r�r�c	��K�t|t�rt|t�r|}|}	�nt|t�}
|
rt|�}t	�}|j|||��}	|
r4|r|�0|	D�cgc]"}t
|�r�|j|�r�!|��$}	}|	syt|	�dk(}
t|t�xr&t
|�xs|j|��d{���}|j|�}|
xr/t|�xr|
xst|�xr|xrt
|�}t|	|||
��}|	D�cic]"}|tjj|���$}}t|	|�D��cgc]
\}}||s�|��}}}t|	|�D��cgc]\}}||r�||f��}}}t!j"|D�cgc]}|j%|d����c}��d{���|xs|j&}g}|j)t|��|D]9\}}|j+|j,�}|j/|||fi|����;t1|||���d{���Scc}w7���cc}wcc}}wcc}}wcc}w7��7�$�w)a�Copy file(s) from local.

        Copies a specific file or tree of files (if recursive=True). If rpath
        ends with a "/", it will be assumed to be a directory, and target files
        will go within.

        The put_file method will be called concurrently on a batch of files. The
        batch_size option can configure the amount of futures that can be executed
        at the same time. If it is -1, then all the files will be uploaded concurrently.
        The default can be set for this instance by passing "batch_size" in the
        constructor, or for all instances by setting the "gather_batch_size" key
        in ``fsspec.config.conf``, falling back to 1/8th of the system limit .
        �r�r�Nrr�T��exist_ok�r�rz)r2r�r�r
r	�expand_pathr�isdirr~r�r�rrr�r�r�r r�r�r��set_size�branch_coror��appendr�)r>r�r�r�rzr�r�r7�rpaths�lpathsr��fsr�r�r�r��l�is_dir�r�rdirs�
file_pairs�dr��lfile�rfile�put_files                          r�_putzAsyncFileSystem._put4s|����.�e�T�"�z�%��'>��F��F�&�u�c�2�M��'��.�� �"�B��^�^�E�Y��^�R�F��i�8�3G�%+�T�V��L��O�r�x�x�PQ�{�!�V��T��� ��[�A�-�N�$�U�C�0���U�#�?�T�[�[��-?�'?�
��(�(��/�E�"���5�!�4�n�V�!�%�(�(�T�[�T��e�AT�=T�
�!����)�)�	�F�06�6�v�!�!�R�W�W�]�]�1�%�%�v��6�"�6�6�2�@�2�t�q�!�f�Q�i��2��@�),�V�V�)<�N�)<���A�F�1�I�q�!�f�)<�
�N��n�n��O��A�t�~�~�a�$�~�?��O�P�P�P��2�4�?�?�
������#�j�/�*�&�L�E�5��+�+�D�N�N�;�H��L�L��%��9�&�9�:�'�*��j�8�
�
�	
��EU�(@��7��@��N��O�P��
�s��A,J�.I$�?I$�I$�AJ�I)�AJ�8'I,�J�0
I1�>I1�J�
I7�"I7�(J�>I=�J�J� A?J�J� 
J�,J�Jc��K�t��wr�r�)r>r�r�r7s    rr�zAsyncFileSystem._get_file~r�r�c��TK�t|t�rt|t�r|}|}�nt|t�}	|	xrt|�}
|j	|�}|j|||���d{���}|	r<|r|�8|D�cgc]*}t|�r�|j
|��d{���r�)|��,}}|syt|�}t|�dk(}t|t�xr&t|�xst�j|�}
|	xr%t|�xr|xst|�xr|
xr|
}t||||	��}|D�cgc]6}tjtjj!|�d����8c}|j#d|j$�}g}|j't|��t)||�D]9\}}|j+|j,�}|j/|||fi|����;t1|||���d{���S7���7��tcc}wcc}w7��w)	aCopy file(s) to local.

        Copies a specific file or tree of files (if recursive=True). If lpath
        ends with a "/", it will be assumed to be a directory, and target files
        will go within. Can submit a list of paths, which may be glob-patterns
        and will be expanded.

        The get_file method will be called concurrently on a batch of files. The
        batch_size option can configure the amount of futures that can be executed
        at the same time. If it is -1, then all the files will be uploaded concurrently.
        The default can be set for this instance by passing "batch_size" in the
        constructor, or for all instances by setting the "gather_batch_size" key
        in ``fsspec.config.conf``, falling back to 1/8th of the system limit .
        rNrr�Trr�r)r2r�r�rr�r�r�r
r~r	rrrr��makedirsr��dirnamer�r�rr�rr�rr�)r>r�r�r�rzr�r7r	r
r��source_not_trailing_sepr�r�r�r��lpr�r��get_files                   r�_getzAsyncFileSystem._get�s-����.�e�T�"�z�%��'>��F��F�&�u�c�2�M�&3�&O�L��<O�8O�#��(�(��/�E��,�,���X�-���F��i�8�3G� &��%�!�l�1�o�t�{�{�ST�~�AU�AU�A�v�����#�E�*�E� ��[�A�-�N�$�U�C�0���U�#�E��'8�'>�'>�u�'E�
�#���5�!�4�n�V�!�%�(�(�T�[�T�=T�
�!����)�)�	�F�DJ�J�6�R����R�W�W�_�_�R�(�4�	8�6�J��Z�Z��d�o�o�>�
������#�f�+�&����/�L�E�5��+�+�D�N�N�;�H��L�L��%��9�&�9�:�0�*��j�8�
�
�	
�I��BV����.	K�
�s\�A/H(�1H�2H(�H�H�%H
�&H�+H�/BH(�;H!�=BH(�H&�H(�H�H(c��\K�	|j|��d{���ddk(S7�
#YyxYw�w)Nr��fileF)r��r>r�s  rr�zAsyncFileSystem._isfile�s3����	��*�*�T�*�*�F�3�v�=�=�*��	��s �,�%�#�	%�,�%�)�,c��lK�	|j|��d{���ddk(S7�
#t$rYywxYw�w)Nr��	directoryF)r��OSErrorr s  rr�zAsyncFileSystem._isdir�s;����	��*�*�T�*�*�F�3�{�B�B�*���	��	�s(�4�%�#�	%�4�%�	1�4�1�4c��`K�|j|��d{���jdd�S7��w)Nr�)r��getr s  rr�zAsyncFileSystem._size�s(�����j�j��&�&�+�+�F�D�9�9�&�s�.�,�.c��K�|xs|j}t|D�cgc]}|j|���c}|���d{���Scc}w7�	�w)N)r�)r�r�r�)r>r�r�r�s    r�_sizeszAsyncFileSystem._sizes�sJ�����2�4�?�?�
�)�$)�*�E�q�T�Z�Z��]�E�*�z�
�
�	
��*�
�s�A�A�A�A
�
Ac��fK�	|j|fi|���d{���y7�#t$rYywxYw�w)NTF)r�r�r�s   rr�zAsyncFileSystem._exists�s=����	��$�*�*�T�,�V�,�,�,��
-�� �	��	�s(�1�"� �"�1�"�	.�1�.�1c��K�t��wr�r�r�s   rr�zAsyncFileSystem._info�r�r�c��K�t��wr�r�)r>r��detailr7s    rr�zAsyncFileSystem._ls�r�r�c��K�|�|dkrtd��|j|�}i}i}i}|jdd�}	|j|fddi|���d{���}	|	D]S}|djd�}|jdd�d	}
|d
dk(r||k7r|||
<|||
<�D||k(r||d<�O|||
<�U|r	|||f���n|t|�t|�f���|�|dz}|dkry|D])}|j||f||d
�|��23d{���}|����y7��#tt
f$r6}
|dk(r�t
|�r||
�|r	|iif���n|ggf���Yd}
~
yd}
~
wwxYw7�V6�{�w)Nr�maxdepth must be at least 1r+FTr�rO�/rbr�r"r�)r�r+)rkr�r�r�r�r#�callable�rstrip�rsplitr�r�)r>r�r�r�r7�	full_dirs�dirs�filesr+�listingry�info�pathnamerOrrps                rr�zAsyncFileSystem._walk�s�������H�q�L��:�;�;��#�#�D�)���	��������H�e�,��	�$�D�H�H�T�A�$�A�&�A�A�G��D��F�|�*�*�3�/�H��?�?�3��*�2�.�D��F�|�{�*�x�4�/?�"*�	�$��!��T�
��T�!� ��b�	�"��d������e�#�#���T�
�D��K�/�/�����M�H��!�|���A�%�4�:�:��!���'/���BH��
�a���	�KB��!�7�+�		��7�"���(�#������B��l�"��B��l�"���		��J
���se�<E#�D�D�D�B(E#�E!�E�	E!�	E#�D�E�&,E�E#�E�E#�E!�!E#c��^K�|�|dkrtd��ddl}tjjr4tjj
tjjfntjj
f}|j
|�}|j|�}|xs!|j
td�|D���}|jd�dk\r|jd�n
t|�}|jd�dk\r|jd�n
t|�}	|jd�dk\r|jd�n
t|�}
t||	|
�}|jdd	�}|jd
d�}
t|�sC|j|fi|���d{���r"|s|gS||j|fi|���d{���iS|sgSiSd|d|vrA|}|d|j!d�}|d|dz}||dz|}||dzdj#d�dz}n!d
}|d|}||dzdj#d�dz}d|vr5|�1|jd�}||dj#d�dz}||z
|z}nd}|r||d<|j$|f||
dd�|���d{���}t'||rdnd
z�}|j(|�}t+|j-��D��cic](\}}|j/|r
|ddk(r|dzn|�r||��*}}}|r|St1|�S7��t7��V7��cc}}w�w)Nrr-rc3�&K�|]	}|dz���y�w)�**Nr)�.0�seps  r�	<genexpr>z(AsyncFileSystem._glob.<locals>.<genexpr>,s����-���#��*��s��*�?�[r+F�withdirsTr.r�r:�prefix)r�rAr+r�r")rk�rer�r��altsepr<�endswithr��tuple�findr~�minr�rr�r��rindex�countr�r�compile�sortedr��matchr�)r>r�r�r7rC�seps�
ends_with_sep�append_slash_to_dirname�idx_star�	idx_qmark�	idx_brace�min_idxr+rA�first_wildcard_idx�rootrB�depth�idx_double_stars�depth_double_stars�allpaths�patternr�r6r�s                         rr�zAsyncFileSystem._glob"s[������H�q�L��:�;�;��02����������R�W�W�^�^�,�R�W�W�[�[�N���
�
�d�+�
��#�#�D�)��"/�#
�4�=�=��-��-�-�4
��&*�Y�Y�s�^�q�%8�4�9�9�S�>�c�$�i��&*�i�i��n��&9�D�I�I�c�N�s�4�y�	�&*�i�i��n��&9�D�I�I�c�N�s�4�y�	��h�	�9�5�����H�e�,���:�:�j�$�/�����!�T�\�\�$�1�&�1�1�1�� �6�M� �
��
�
�4�(B�6�(B�"B�C�C���I��I�
�D��'�N�
"�!(���8�G�n�+�+�C�0�G���'�A�+��D���!��0��F���1���'�-�-�c�2�Q�6�E��D��(�7�^�F���1���'�-�-�c�2�Q�6�E��4�<��#�#'�9�9�T�?� �%)�*:�*;�%<�%B�%B�3�%G�!�%K�"�� 2�2�X�=�����%�F�8��#�����
� �8�D�
�DJ�
�
��!��
��2�!F�G���"�*�*�W�%��"�(�.�.�"2�3�
�3���4��}�}�*�t�F�|�{�/J��C����
�t�G�3�	�
���J���9��s2��#C��B
��
�sJ�F)L-�+L�, L-�L"�
CL-�L%�AL-� -L'�
L-�"L-�%L-�'L-c���K�i}|j|fd|i|���d{���D]&}|j|��d{���}|d||d<�(|rt|j��S|S7�J7�0�w)Nr�r�rO)r�r��sum�values)r>r��totalr�r7�sizes�fr6s        rr�zAsyncFileSystem._dussx������!�t�z�z�$�D��D�V�D�D�D�A����A��&�D�"&�v�,�E�$�v�,��E���u�|�|�~�&�&��L�
E��&�s�A,�A(�A,�A*�/A,�*A,c	��RK�|j|�}i}|jdd�}|r:|dk7r5|j|��d{���r|j|��d{���||<|j||fddi|��23d{���\}}}	|r|	j|�|j|	j
�D�
�cic]\}
}|d|��
c}}
��W7��7�v7�Vcc}}
w6|s|j|��d{���7ri||<t|�}|s|S|D�
cic]}
|
||
��
c}
Scc}
w�w)Nr+Fr�TrO)	r�r�r�r�r��updater�r�rL)
r>r�r�rAr7r�r+rpr3r4rOr6�namess
             rr�zAsyncFileSystem._find~s1�����#�#�D�)�������H�e�,�����
�T�[�[��->�'>�'>�"�j�j��.�.�C��I�%/�D�J�J�t�X�$U�d�$U�f�$U�	M�.�!�T�5�����T�"��J�J�U�[�[�]�K�]�z�t�T��V��d�*�]�K�L�(?��.��	M��L�%V��d�l�l�4�0�0�0��C��I��s�����L�05�6���D�#�d�)�O��6�6��6�sl�AD'�C�D'�C�D'�:C�>C�?C�6D'�8C�
D'�D'�C�D'�4C7�5D'�
D"�D'c
���K�|�|dkrtd��t|t�r|j|g||��d{���}�n	t	�}|D�cgc]}|j|���}}|D]�}|sxt
|�rmt	|j||���d{����}||z}|rA|�|dkr�C|t	|jt|�||�|dz
ndd���d{����z}�}|r*t	|j||d���d{����}||z}||vs��|dus|j|��d{���s��|j|���|st|��t|�S7��(cc}w7��7��7�g7�>�w)Nrr-)r�T)r�r��assume_literal)r�rAF)rkr2r�r�r#r�rr�r�r�r�rr�rL)	r>r�r�r�rfr�r��bit�recs	         rr�zAsyncFileSystem._expand_path�s�������H�q�L��:�;�;��d�C� ��)�)�4�&�)�X�F�F�C��%�C�59�:�T��D�(�(��+�T�D�:���%�)�A�,��D�J�J�q�8�J�$D�D�E�C��3�J�C� �$�/�H��M�$��s�"&�"3�"3� $�S�	�*3�9A�9M��A��SW�/3�	#4�#�� ������D�J�J�q�8�d�J�$S�S�T�C��3�J�C��C�<�Y�%�%7�$�,�,�q�/�<Q�<Q��G�G�A�J�1�2�#�D�)�)��c�{��?G��;�E����T��<Q�sp�:E4�E$�E4�E'�)/E4�E,
�AE4�E.�)E4�E0
�	E4�E4�3E2�4E4�9,E4�'E4�.E4�0E4�2E4c��K�y�wr�r)r>r��create_parentsr7s    rr�zAsyncFileSystem._mkdir��	�������c��K�y�wr�r)r>r�rs   rr�zAsyncFileSystem._makedirs�rkrlc��LK�d|vs|jd�rt�t��w)N�b�compression)r%rkr.)r>r�r�r7s    r�
open_asynczAsyncFileSystem.open_async�s$�����d�?�f�j�j��7���!�!�s�"$)FN)FNNN)�	overwrite)NN)Fr�N)NNrrr�)T)Nr�)TN)NF)FNF�F)�rb)*�__name__�
__module__�__qualname__�__doc__�
async_impl�mirror_sync_methods�disable_throttlingr��propertyrr�r�r�r�r�r�r�r�r�r�r�r�rrr�rr�r�r�r'r�r�r�r�r�r�r�r�r�r�rq�
__classcell__)r�s@rr�r�Fs�����J�����+0�t��*�����
"�
�"�#�����:�x"�
�&�4"�CG��>���/�b"��!���H
�T"��!��
G
�R��:�
��"�"�4�lO�b	�7�4DI�&�P
�
�"rr�c�`�ddlm}ttt	t
�z�D�]}|j
d�s�|dd}tj|�s�1tjt||d��}tt||d�dd�}|t||d�u}|r|rtt||�|�	�}n;tjt||d��r|rtt||�|�	�}n��t|||�|j r��tt||d�d
d�|_��y)a,Populate sync and async methods for obj

    For each method will create a sync version if the name refers to an async method
    (coroutine) and there is no override in the child class; will create an async
    method for the corresponding sync method if there is no implementation.

    Uses the methods specified in
    - async_methods: the set that an implementation is expected to provide
    - default_async_methods: that can be derived from their sync version in
      AbstractFileSystem
    - AsyncFileSystem: async-specific default coroutines
    r)r
rprNF�__func__r�)r?rx)�fsspecr
r#�
async_methods�dirr��
startswith�privaterMr�r��getattrrE�isasyncgenfunctionrK�setattrrx)r?r
�method�smethod�isco�unsync�
is_default�mths        rrzrz�s��*��m�c�/�&:�:�;��� � ��%�����*���=�=�� ��.�.�w�s�F�D�/I�J�D��W�S�'�5�9�:�t�L�F��7�+=�w��#K�K�J��
�"�7�3��#7�S�A���+�+�G�C���,F�G�J�'���V�(<�#�F����C��#�&��;�;�%��.���>�	�2����!<rc��eZdZy)�FSSpecCoroutineCancelN)rurvrwrrrr�r��s��rr�Tc
��ddl}tjjtd�D�cgc]}|j�r�|��}}|r|D�cgc]}|j
���c}|D�cgc]�}|jjj|jjjj|jjjj|jjj|j|jj�|r|ndd����}}|r�|D]�}|j}	|j!�tj"j$j'||�tj"j$j!|�|	D�
cgc]
}
|
d|���c}
	|jj)|���|Scc}wcc}wcc}wcc}
w#|$rY��wxYw)Nr)�localsr�	firstline�linelo�stackr�)�	tracebackr �tasks�	all_tasksrr��print_stack�_coro�cr_frame�f_locals�f_code�co_filename�co_firstlineno�f_lineno�format_stack�
_callbacksr��futures�Future�
set_exception�throw)�printoutr�r��	with_taskr��tr�r�r��cbs�cbs           r�_dump_running_tasksr��s�����
�
�/�/��Q��8�I�8�1�����Q�8�E�I��(-�.����	�	�	��.��
��D��j�j�)�)�2�2��J�J�'�'�.�.�:�:����,�,�3�3�B�B��j�j�)�)�2�2��+�+�D�J�J�,?�,?�@�%�D�4�
	
���
���A��,�,�C�
�H�H�J��O�O�"�"�0�0��C�8��O�O�"�"�)�)�!�,� #�$��"�U�R��U�1�X��$�
����
�
�c�"���J��3
J��.��
��"
%���
��
�s0�G!�G!�G&�-CG+�,G0�G5�5G=�<G=c�H�eZdZdd�Zd�Zd�Zdd�Zd�Zd�Zd�Z	d�Z
dd	�Zy
)
�AbstractAsyncStreamedFilec��xK�|�dn
t|�}|jdk7rtd��|dkr|j|jz
}|j
rtd��|dk(ry|j
|j|j|z��d{���}|xjt|�z
c_|S7�$�w)z�
        Return data from cache, or fetch pieces as necessary

        Parameters
        ----------
        length: int (-1)
            Number of bytes to read; if <0, all remaining bytes.
        NrbrtzFile not in read moder�I/O operation on closed file.r)�intr�rkr��loc�closed�_fetch_ranger~)r>�lengthr�s   r�readzAbstractAsyncStreamedFile.reads������~��3�v�;���9�9����4�5�5��A�:��Y�Y����)�F��;�;��<�=�=��Q�;���%�%�d�h�h����6�0A�B�B�����C��H����
�C�s�BB:�B8�%B:c��~K�|jdvrtd��|jrtd��|jrtd��|jj|�}|xj|z
c_|jj�|jk\r|j��d{���|S7��w)z�
        Write data to buffer.

        Buffer only sent on flush() or if buffer is greater than
        or equal to blocksize.

        Parameters
        ----------
        data: bytes
            Set of bytes to be written.
        >�ab�wbzFile not in write moder�z0This file has been force-flushed, can only closeN)
r�rkr��forced�buffer�writer��tell�	blocksize�flush)r>�datar�s   rr�zAbstractAsyncStreamedFile.write/s������9�9�L�(��5�6�6��;�;��<�=�=��;�;��O�P�P��k�k����%�����C����;�;�������/��*�*�,����
�
�s�B2B=�4B;�5B=c��K�t|dd�ry|jry|jdk(rd|_d|_y|js|jd���d{���|j�c|jj|j�|jj|jj|j��d|_y7�{�w)z=Close file

        Finalizes writes, discards cache
        �_unclosableFNrtT)�force)
r�r�r��cacher�r�r�invalidate_cacher��_parentr�s r�closezAbstractAsyncStreamedFile.closeGs�����
�4���.���;�;���9�9����D�J�����;�;��j�j�t�j�,�,�,��w�w�"����(�(����3����(�(���������)C�D����
-�s�AC�C�A<Cc��4K�|jrtd��|r|jrtd��|rd|_|jdvry|s(|jj�|jkry|j� d|_	|j��d{���|j|���d{���durI|xj|jjdd�z
c_tj�|_yy7�j#d|_�xYw7�_�w)	NzFlush on closed filez+Force flush cannot be called more than onceT>r�r�r)�finalF�)
r�rkr�r�r�r�r��offset�_initiate_upload�
_upload_chunk�seek�io�BytesIO)r>r�s  rr�zAbstractAsyncStreamedFile.flush\s������;�;��3�4�4��T�[�[��J�K�K���D�K��9�9�L�(������)�)�+�d�n�n�<���;�;���D�K�
��+�+�-�-�-�
�#�#�%�#�0�0��=��K�K�4�;�;�+�+�A�q�1�1�K��*�*�,�D�K�>�.��
�"�����0�s=�BD�	D	�D�D	�!D�6D�7AD�D	�	
D�Dc��K�|S�wr�rr�s r�
__aenter__z$AbstractAsyncStreamedFile.__aenter__ys������s�c��@K�|j��d{���y7��wr�)r�)r>�exc_type�exc_val�exc_tbs    r�	__aexit__z#AbstractAsyncStreamedFile.__aexit__|s�����j�j�l���s���c��K�t��wr�r�)r>rTr�s   rr�z&AbstractAsyncStreamedFile._fetch_ranger�r�c��K�y�wr�rr�s rr�z*AbstractAsyncStreamedFile._initiate_upload�rkrlc��K�t��wr�r�)r>r�s  rr�z'AbstractAsyncStreamedFile._upload_chunk�r�r�N)rbrs)rurvrwr�r�r�r�r�r�r�r�r�rrrr�r�s/���.�0�*'�:��"�
�"rr�r�rs)Ar �asyncio.eventsrBr�r�r�r�rCr�collections.abcr�globr�typingr�	callbacksr�
exceptionsr�implementations.localr	r
r�specrr
�utilsrrrrKr�rrrr-rrr(r:rErKrVrY�hasattrrZrfr\rlr�r#rjrgrerq�boolrtr�r�r�rzr"r�r�r�rrr�<module>r�s}������	��	�	��$�� �'�&�Q�Q�:�<�<�
�"�*�*�W�
���6���v�����+�+���
�	�%)�*�Z�
� �$��2�!�"��B���'7�8����N�N�M�<��
 ��'�7�;�
���"���2�t���
����
O�f�
�.B
"�(�B
"�J!�H	�I�	�
�$�$9�U��Br"� 4�r"��I� ����
� �s�D)�)	D5�4D5