
    7Th                        S SK r S SKr S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
  S SKJr  S SKJrJr  SSKJr  SSKJr  SSKJrJrJr  SS	KJrJr  SS
KJrJrJr  \R>                  " S5      r S/r!S/r"Sq#\ RH                  r$S r%S r&S)S jr'SS.S jr(S)S jr)\
S 5       r*S r+S r,\-" \S5      (       a  \R\                  " \,S9  \(       a  S SK/r/\/R`                  r1O S SK/r/\2" \/S\35      r1Sr5Sr6S*S jr7S\84S jr9S\SSS4S jr:/ SQr; " S  S!\5      r<S" r= " S# S$\>5      r?S%S%\?S4S& jr@ " S' S(\5      rAg! \4 a    Sr/\3r1 NXf = f)+    N)contextmanager)	has_magic)TYPE_CHECKINGIterable   )DEFAULT_CALLBACK)FSTimeoutError)LocalFileSystemmake_path_posixtrailing_sep)AbstractBufferedFileAbstractFileSystem)glob_translateis_exceptionother_pathsz_[^_]c                  N    [         (       d  [        R                  " 5       q [         $ )zwAllocate or return a threading lock.

The lock is allocated on first use to allow setting one lock per forked process.
)_lock	threadingLock     C/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/asyn.pyget_lockr      s     5 Lr   c                  ,    S[         S'   S[        S'   Sqg)zReset 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loopr   r   r   r   
reset_lockr   &   s     HQKDGEr   c                    #    U(       a  UOS nUb  [         R                  " XS9n UI S h  vN US'   U R                  5         g  N! [         a  nXBS'    S nAN&S nAff = f! U R                  5         f = f7f)Ntimeoutr   )asynciowait_for	Exceptionset)eventcororesultr    exs        r   _runnerr)   3   sf      gdG6Jq	 				  q	 			sI   #A6A AA A6A 
AAA! AA! !A33A6r   c                V   U(       a  UOSnU b  U R                  5       (       a  [        S5      e [        R                  R	                  5       nXPL a  [        S5      e U" U0 UD6nS/n[        R                  " 5       n[        R                  " [        XXr5      U 5         UR                  S5      (       a  OUb  US-  nUS:  a  [        eM-  US   n	[        U	[        R                  5      (       a  [        U	e[        U	[        5      (       a  U	eU	$ ! [
         a    e [         a     Nf = f)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)
NzLoop is not runningz)Calling sync() from within a running loopr   r   )	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&    !gdG |t~~''011//1=%&QRR    DVFOOE$$WU&%JDQ
::a==qLG{$$  1IM-!5!566-/	M=	1	11   s   -D D('D(c                 J   ^ ^ [         R                  " T 5      U U4S j5       nU$ )zGiven 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                  T   > T=(       d    U S   n[        UR                  T/U Q70 UD6$ Nr   )r;   r   )r7   r8   selfr6   objs      r   wrappersync_wrapper.<locals>.wrappers   s+    ~d1gDIIt5d5f55r   )	functoolswraps)r6   r@   rA   s   `` r   sync_wrapperrE   l   s'     __T6 6 Nr   c               #   F  #    [         R                  " 5       n  [        R                  S:X  a>  [	        [         S5      (       a)  [         R
                  " [         R                  " 5       5        S v   [         R
                  " U 5        g ! [         R
                  " U 5        f = f7f)NntWindowsSelectorEventLoopPolicy)r!   get_event_loop_policyosnamehasattrset_event_loop_policyrH   )original_policys    r   _selector_policyrO   {   sf     335O777d?ww0PQQ))'*P*P*RS%%o6%%o6s   B!AB /B!BB!c                     [         S   c  [        5          [         S   cu  [        5          [        R                  " 5       [         S'   SSS5        [
        R                  " [         S   R                  SS9n SU l        U R                  5         U [        S'   SSS5        [         S   $ [         S   $ ! , (       d  f       Nn= f! , (       d  f       [         S   $ = f)z\Create or return the default fsspec IO loop

The loop will be running on a separate thread.
r   NfsspecIO)targetrK   T)r   r   rO   r!   new_event_loopr   Threadrun_foreverdaemonstartr   )ths    r   get_looprY      s    
 AwZ Aw%'%446DG (%%T!W-@-@zR 	
   7N47N ('	 Z 7Ns#   C B/AC /
B=	9C  
Cc                  ,    S [         S'   S [        S'   S qg r>   )r   r   lockr   r   r   reset_after_forkr\      s    DGHQKDr   register_at_fork)after_in_childerror   i   Fc                 B   SSK Jn  U (       a  SU;   a  US   $ OSU;   a  US   $ U (       a  [        $ [        c  [        $  [        R
                  " [        R                  5      u  p#U[        R                  :X  a  gUS-  $ ! [        [        [        4 a	    [        s $ f = f)Nr   )confnofiles_gather_batch_sizegather_batch_size   )fsspec.configrb   _NOFILES_DEFAULT_BATCH_SIZEresource_DEFAULT_BATCH_SIZE	getrlimitRLIMIT_NOFILEImportError
ValueErrorResourceErrorRLIM_INFINITY)nofilesrb   
soft_limit_s       r   _get_batch_sizert      s    "&$.344 / $&+,,**""# **8+A+AB
 X+++Q ]3 #""#s    &B   BBreturnc                  P     [         R                  " 5         g! [         a     gf = f)z Being executed by an event loop?TF)r!   r.   r,   r   r   r   running_asyncrw      s(      " s    
%%c                 l  ^^^#    Uc	  [        US9nUS:X  a  [        U 5      nUS:  d   eUUU4S jnSn[        U 5      nS/U-  n	[        5       n
U
(       d  Xx:  a  [        U
5      U:  aN  Xx:  aI  U
R                  [        R
                  " U" X   U5      5      5        US-  n[        U
5      U:  a  Xx:  a  MI  U
(       d   U	$ [        R                  " U
[        R                  S9I Sh  vN u  pU(       a'  UR                  5       I Sh  vN u  pXU'   U(       a  M'  U
(       a  M  Xx:  a  M  U	$  NF N'7f)a  Run 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)rq   re   r   c                   >#     [         R                  " U TS9I S h  vN U4TR                  S5        $  N! [         a&  nT(       d  e X!4s S nATR                  S5        $ S nAff = f! TR                  S5        f = f7f)Nr   r   )r!   r"   relative_updater#   )r&   iecallbackreturn_exceptionsr    s      r   	_run_coro'_run_coros_in_chunks.<locals>._run_coro   st     	( ))$@@!C $$Q' A 	$4K$$Q'	
 $$Q'sO   B 7 57 B 7 
A'
A"A'A* B "A''A* *A==B r   )return_when)	rt   lenr$   addr!   ensure_futurer2   FIRST_COMPLETEDpop)coros
batch_sizer}   r    r~   rq   r   r{   nresultspendingdoner'   ks     ```         r   _run_coros_in_chunksr      s    < $W5
RZ
>>( 	
AE
AfqjGeG
QU'lZ'AEKK--i!.DEFFA 'lZ'AE  N &ll7@W@WXX"hhj(IFAJ d 'QU N Y(s<   B2D490D4)D0* D4
D2D4D4'D4.D42D4)_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                   v  ^  \ rS rSrSrSrSrSrSSSS.U 4S jjr\	S 5       r
S	 rS(S
 jrS rS r    S)S jrS*S jrS+S jrS rS+S jr S,S jr   S-S jrS*S jrS\SS4S jrS rS\S4S jrS rS rS rS.S jrS rS r S/S jr!S0S jr"S.S  jr#S1S! jr$S2S" jr%S(S# jr&S/S$ jr'S3S% jr(S4S& jr)S'r*U =r+$ )5AsyncFileSystemi6  aW  Async 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)asynchronousr   r   c                   > Xl         [        R                  " 5       U l        U(       d  U=(       d
    [	        5       U l        OS U l        X0l        [        TU ]   " U0 UD6  g N)	r   rJ   getpid_pidrY   _loopr   super__init__)r?   r   r   r   r7   r8   	__class__s         r   r   AsyncFileSystem.__init__G  sE    (IIK	+DJDJ$$)&)r   c                 v    U R                   [        R                  " 5       :w  a  [        S5      eU R                  $ )NzThis class is not fork-safe)r   rJ   r   r,   r   r?   s    r   r   AsyncFileSystem.loopQ  s*    99		#<==zzr   c                    #    [         e7fr   r/   r?   pathr8   s      r   r   AsyncFileSystem._rm_fileW       !!   	c           
         #    U=(       d    U R                   nU R                  XS9I S h  vN n[        [        U5       Vs/ s H  oPR                  " U40 UD6PM     snUSS9I S h  vN $  NAs  snf  N7f)N	recursiveTr   rq   )r   r   r   reversedr   )r?   r   r   r   r8   ps         r   _rmAsyncFileSystem._rmZ  sq     24??
&&t&AA)19$@A]]1''@!
 
 	
 B@
s-   (A5A,A5A.
A5'A3(A5.A5c                    #    [         e7fr   r   )r?   path1path2r8   s       r   r   AsyncFileSystem._cp_filed  r   r   c                 x   #    U R                  X5      I S h  vN   U R                  U5      I S h  vN   g  N N7fr   )r   r   )r?   r   r   s      r   _mv_fileAsyncFileSystem._mv_fileg  s1     mmE)))mmE""" 	*"s   :6:8::c           	      N  #    Uc
  U(       a  SnOUc  Sn[        U[        5      (       a  [        U[        5      (       a  UnUn	GO:[        U[        5      n
U R                  XUS9I S h  vN nU
(       aV  U(       a  UbL  U Vs/ s H7  n[	        U5      (       a  M  U R                  U5      I S h  vN (       a  M5  UPM9     nnU(       d  g [        U5      S:H  n[        U[        5      =(       a+    [	        U5      =(       d    U R                  U5      I S h  vN nU
=(       aK    [        U5      =(       a    U=(       d0    [        U5      (       + =(       a    U=(       a    [	        U5      (       + n[        UUUU
(       + S9n	U=(       d    U R                  n[        X5       VVs/ s H  u  nnU R                  " UU40 UD6PM     nnn[        UUSSS9I S h  vN n[        [        U5       H   nUS:X  a  [        U[        5      (       a  M   Ue   g  GN GNds  snf  GNs  snnf  NM7f)Nignoreraise)maxdepthr   r   existsflattenT)r   r~   rq   )r3   liststrr   r   r   r   r   r   r   zipr   r   filterr   FileNotFoundError)r?   r   r   r   on_errorr   r   r8   paths1paths2source_is_strr   source_is_filedest_is_dirr   p1p2r   r'   r(   s                       r   _copyAsyncFileSystem._copyk  s     	HHeT""z%'>'> FF&uc2M,,I -  F i83G  &%!l1oAt{{ST~AUAUAv    [A-N$UC0 U#?T[[-?'?  # 5!4n V!%((T[TeAT=T  !))	F  24??
?B6?RS?RVRr200?RS+jD$
 
 v.B8#
27H(I(IH /C BV (@ T
sn   A&H%(H)H%HH.H
/H:H AH%HBH%"!HH%H#:H%HH%H%c                    #    [         e7fr   r   )r?   r   valuemoder8   s        r   r   AsyncFileSystem._pipe_file  r   r   c                   #    [        U[        5      (       a  X0nU=(       d    U R                  n[        UR	                  5        VVs/ s H  u  pVU R
                  " XV40 UD6PM     snnUSS9I S h  vN $ s  snnf  N
7f)NTr   )r3   r   r   r   itemsr   )r?   r   r   r   r8   r   vs          r   _pipeAsyncFileSystem._pipe  so     dC  =D24??
)9=FT__Q,V,F!
 
 	
F
s   AA?A7
'A?2A=3A?c                 |  #    SnSnUb;  US:  a5  Uc  U* nSnSnO/U=(       d    U R                  U5      I Sh  vN S   nXB-   nOUc  SnU(       d_  Ub3  US:  a-  Ub)  U=(       d    U R                  U5      I Sh  vN S   nXC-   nOUc  Sn[        U[        R                  5      (       a  US-  nSU S	U 3$  N N?7f)
z"Helper for "Range"-based _cat_fileNFr    Tsizer   zbytes=-)r   r3   numbersIntegral)r?   urlrW   endr   suffs         r   _process_limitsAsyncFileSystem._process_limits  s     {f>djjo 5v>]E37$B$**S/$96#BD*C#w//00qwau%% !6 %:s"   6B<B8AB<:B:;>B<:B<c                    #    [         e7fr   r   )r?   r   rW   r   r8   s        r   r   AsyncFileSystem._cat_file  r   r   c                 .  #    U R                  XS9I S h  vN nU Vs/ s H  oR                  " U40 UD6PM     nnU=(       d    U R                  n[        XtSSS9I S h  vN nUS:X  a#  [	        [        [        U5      S5      n	U	(       a  U	e[        U5      S:  d-  [        W[        5      (       d  US   U R                  U5      :w  a8  [        Xh5       V
Vs0 s H  u  pUS:w  d  [        U5      (       a  M  X_M!     snn
$ US   $  Ns  snf  Ns  snn
f 7f)	Nr   Tr   rq   r~   r   Fr   r   omit)r   r   r   r   nextr   r   r   r3   r   _strip_protocolr   )r?   r   r   r   r   r8   pathsr   outr(   r   r   s               r   _catAsyncFileSystem._cat  s     '''BB<ABED//EB24??
($$
 
 wf\3/7BJN$%%Qx4//55  O+DAv%\!_ +  q6M+ CB
sD   DDDD%DD A7DD7D=
DDDc                   #    Ub  [         e[        U[        5      (       d  [        e[        U[        5      (       d  U/[        U5      -  n[        U[        5      (       d  U/[        U5      -  n[        U5      [        U5      :w  d  [        U5      [        U5      :w  a  [        e[        XU5       VV	V
s/ s H  u  pn
U R                  " U4XS.UD6PM     nn	nn
U=(       d    U R                  n[        XSSS9I Sh  vN $ s  sn
n	nf  N7f)a  Get 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.
N)rW   r   Tr   )r/   r3   r   	TypeErrorr   r   rn   r   r   r   r   )r?   r   startsendsmax_gapr   r   r8   r   sr|   r   s               r   _cat_rangesAsyncFileSystem._cat_ranges  s     * %%%&&O&(++XE
*F$))6CJ&Dv;#e*$D	SZ(? ud3
3a NN17A773 	 
  24??
)$$
 
 	



s   B3D5"D'D>D
?Dc                    #    [         e7fr   r   )r?   lpathrpathr   r8   s        r   r   AsyncFileSystem._put_file  r   r   c           
        #    [        U[        5      (       a  [        U[        5      (       a  UnUn	GOW[        U[        5      n
U
(       a  [        U5      n[	        5       nUR                  XUS9n	U
(       aN  U(       a  UbD  U	 Vs/ s H/  n[        U5      (       a  M  UR                  U5      (       a  M-  UPM1     n	nU	(       d  g[        U	5      S:H  n[        U[        5      =(       a+    [        U5      =(       d    U R                  U5      I Sh  vN nU R                  U5      nU
=(       aK    [        U5      =(       a    U=(       d0    [        U5      (       + =(       a    U=(       a    [        U5      (       + n[        U	UUU
(       + S9nU	 Vs0 s H#  nU[        R                  R                  U5      _M%     nn[        X5       VVs/ s H  u  nnUU   (       d  M  UPM     nnn[        X5       VVs/ s H  u  nnUU   (       a  M  UU4PM     nnn[         R"                  " U Vs/ s H  nU R%                  USS9PM     sn6 I Sh  vN   U=(       d    U R&                  n/ nUR)                  [        U5      5        U H:  u  nnUR+                  U R,                  5      nUR/                  U" UU40 UD65        M<     [1        UXTS9I Sh  vN $ s  snf  GNs  snf s  snnf s  snnf s  snf  N N$7f)av  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   Nr   r   Texist_okr   r}   )r3   r   r   r   r
   expand_pathr   isdirr   r   r   r   r   rJ   r   r   r!   gatherr   r   set_sizebranch_coror   appendr   )r?   r  r  r   r}   r   r   r8   rpathslpathsr   fsr   r   r   r   lis_dirrrdirs
file_pairsdr   lfilerfileput_files                             r   _putAsyncFileSystem._put  s|    . eT""z%'>'> FF&uc2M'. "B^^E^RFi83G%+TVLO!rxxPQ{!VT [A-N$UC0 U#?T[[-?'?  ((/E" 5!4n V!%((T[TeAT=T  !))	F 066v!!RWW]]1%%v6"62@2tq!fQi2@),V)<N)<AF1Ifq!f)<
NnnOAt~~a$~?OPPP24??
#j/*&LE5++DNN;HLL%9&9: ' *j
 
 	
E U (@ 7@NOP
s   BK3KK4K:AK3KA>K3*K8K3KK#K34K$	K$K3(K*K3	K/
BK3K1
K3K31K3c                    #    [         e7fr   r   )r?   r  r  r8   s       r   r   AsyncFileSystem._get_filea  r   r   c                   #    [        U[        5      (       a  [        U[        5      (       a  UnUnGOa[        U[        5      n	U	=(       a    [        U5      (       + n
U R	                  U5      nU R                  XUS9I Sh  vN nU	(       aV  U(       a  UbL  U Vs/ s H7  n[        U5      (       a  M  U R                  U5      I Sh  vN (       a  M5  UPM9     nnU(       d  g[        U5      n[        U5      S:H  n[        U[        5      =(       a+    [        U5      =(       d    [        5       R                  U5      nU	=(       a=    [        U5      =(       a    U=(       d"    [        U5      (       + =(       a    U=(       a    U
n[        UUUU	(       + S9nU Vs/ s H5  n[        R                  " [        R                  R!                  U5      SS9PM7       nUR#                  SU R$                  5      n/ nUR'                  [        U5      5        [)        X5       H8  u  p!UR+                  U R,                  5      nUR/                  U" X40 UD65        M:     [1        UUUS9I Sh  vN $  GN GNs  snf s  snf  N7f)	a  Copy 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 .
r	  Nr   r   Tr
  r   r  )r3   r   r   r   r   r   r   r   r   r
   r  r   r   rJ   makedirsr   dirnamer   r   r  r   r  r   r  r   )r?   r  r  r   r}   r   r8   r  r  r   source_not_trailing_sepr   r   r   r   lpr   r   get_files                      r   _getAsyncFileSystem._getd  s+    . eT""z%'>'> FF&uc2M&3&OL<O8O#((/E,,X -  F i83G  &%!l1oAt{{ST~AUAUAv   #E*E [A-N$UC0 U#E'8'>'>u'E  # 5!4n V!%((T[T=T  !))	F DJJ6RRWW__R(4	86JZZdoo>
#f+&/LE++DNN;HLL%9&9: 0 *j8
 
 	
I BV. 	K
s\   A>I: I(I:I.2I.I+
I.I.C I:<I3BI:#I8$I:+I..I:c                 \   #     U R                  U5      I S h  vN S   S:H  $  N
!    g= f7f)NtypefileF)r   r?   r   s     r   r   AsyncFileSystem._isfile  s2     	**T**F3v==*	s    ,% #	% ,% ),c                 n   #     U R                  U5      I S h  vN S   S:H  $  N
! [         a     gf = f7f)Nr,  	directoryF)r   OSErrorr.  s     r   r   AsyncFileSystem._isdir  s:     	**T**F3{BB* 		s(   5% #	% 5% 
2525c                 `   #    U R                  U5      I S h  vN R                  SS 5      $  N7f)Nr   )r   getr.  s     r   r   AsyncFileSystem._size  s'     jj&&++FD99&s   .,.c                    #    U=(       d    U R                   n[        U Vs/ s H  o0R                  U5      PM     snUS9I S h  vN $ s  snf  N	7f)N)r   )r   r   r   )r?   r   r   r   s       r   _sizesAsyncFileSystem._sizes  sG     24??
)$)*EqZZ]E*z
 
 	
*
s   AA		AA
Ac                 h   #     U R                   " U40 UD6I S h  vN   g N! [         a     gf = f7f)NTF)r   r   r   s      r   r   AsyncFileSystem._exists  s:     	**T,V,,, -  		s(   2"  " 2" 
/2/2c                    #    [         e7fr   r   r   s      r   r   AsyncFileSystem._info  r   r   c                    #    [         e7fr   r   )r?   r   detailr8   s       r   r   AsyncFileSystem._ls  r   r   c                  #    Ub  US:  a  [        S5      eU R                  U5      n0 n0 n0 nUR                  SS5      n U R                  " U4SS0UD6I S h  vN n	U	 HS  nUS   R                  S5      nUR                  SS5      S	   nUS
   S:X  a  X:w  a
  XU'   XU'   MD  X:X  a  XS'   MO  XU'   MU     U(       a  XU47v   OU[        U5      [        U5      47v   Ub  US-  nUS:  a  g U H(  nU R                  " X^   4X(S.UD6  S h  vN nU7v   M     g  N! [        [
        4 aA  n
US:X  a  e [        U5      (       a  U" U
5        U(       a	  U0 0 47v   OU/ / 47v    S n
A
g S n
A
ff = f Nd
 M  7f)Nr   maxdepth must be at least 1r?  FTr   rK   /re   r,  r1  r   )r   r?  )rn   r   r   r   r   r2  callablerstriprsplitr   r   )r?   r   r   r   r8   	full_dirsdirsfilesr?  listingr|   infopathnamerK   r  rs   s                   r   r   AsyncFileSystem._walk  s    HqL:;;##D)	He,	 HHTA$A&AAG D F|**3/H??3*2.DF|{*x/?"*$!T
! b	"d  e##T
DK//MH!|A::'/BH a 	 K B!7+ 		7"(##Bl"Bl"		J sf   >E9D  DD  B-E9E6E4E6E9D   E107E,'E9,E11E94E66E9c                   #    Ub  US:  a  [        S5      eSS Kn[        R                  R                  (       a4  [        R                  R
                  [        R                  R                  4O[        R                  R
                  4nUR                  U5      nU R                  U5      nU=(       d!    UR                  [        S U 5       5      5      nUR                  S5      S:  a  UR                  S5      O
[        U5      nUR                  S5      S:  a  UR                  S5      O
[        U5      n	UR                  S5      S:  a  UR                  S5      O
[        U5      n
[        XU
5      nUR                  SS	5      n[        U5      (       dQ  U R                  " U40 UD6I S h  vN (       a&  U(       d  U/$ XR                  " U40 UD6I S h  vN 0$ U(       d  / $ 0 $ S
US U ;   a6  US U R!                  S
5      nUS US-    nXS-   S  R#                  S
5      S-   nOSnXS-   S  R#                  S
5      S-   nSU;   a5  Ub0  UR                  S5      nXS  R#                  S
5      S-   nUU-
  U-   nOS nU R$                  " U4USSS.UD6I S h  vN n['        X(       a  S
OS-   5      nUR(                  " U5      n[+        UR-                  5       5       VVs0 s H6  u  nnUR/                  U(       a  US   S:X  a  US
-   OU5      (       d  M3  UU_M8     nnnU(       a  U$ [1        U5      $  GN GN` Ns  snnf 7f)Nr   rB  r   c              3   *   #    U  H	  oS -   v   M     g7f)**Nr   ).0seps     r   	<genexpr>(AsyncFileSystem._glob.<locals>.<genexpr>  s     -*s   *?[r?  FrC  r   rP  T)r   withdirsr?  r,  r1  )rn   rerJ   r   altseprR  endswithr   tuplefindr   minr   r   r   r   rindexcountr   r   compilesortedr   matchr   )r?   r   r   r8   rY  sepsends_with_sepappend_slash_to_dirnameidx_star	idx_qmark	idx_bracemin_idxr?  rootdepthidx_double_starsdepth_double_starsallpathspatternr   rK  r   s                         r   r   AsyncFileSystem._glob  s    HqL:;;02RWW^^,RWW[[Nd+##D)"/ #
4==---4
 &*YYs^q%8499S>c$i&*iin&9DIIcNs4y	&*iin&9DIIcNs4y	h95He,\\$1&111 6M 

4(B6(B"BCCIID'N"8Gn++C0G'A+&D1'--c2Q6ED1'--c2Q6E4<##'99T? %)*;%<%B%B3%G!%K" 22X=
 4
@F
 
 !2!FG**W% "(.."23
34}}*tF|{/J C AtG3 	 
 J9] 2 #C,

sP   F*M,L3-)ML6B?ML9AM2L;L;M6M9M;Mc                    #    0 nU R                   " U4SU0UD6I S h  vN  H&  nU R                  U5      I S h  vN nUS   XWS   '   M(     U(       a  [        UR                  5       5      $ U$  NP N67f)Nr   r   rK   )r   r   sumvalues)r?   r   totalr   r8   sizesfrK  s           r   r   AsyncFileSystem._duJ  sr     zz$DDVDDDAA&D"&v,Ev, E u||~&&L E&s   A2A.A2A05A20A2c           	        #    U R                  U5      n0 nUR                  SS5      nU(       a?  US:w  a9  U R                  U5      I S h  vN (       a  U R                  U5      I S h  vN XQ'   U R                  " X4SS0UD6  S h  vN u  pxn	U(       a  U	R                  U5        UR                  U	R                  5        V
Vs0 s H  u  pUS   U_M     snn
5        M^   N N{ N]s  snn
f 
 U(       d#  U R                  U5      I S h  vN  (       a  0 XQ'   [        U5      nU(       d  U$ U V
s0 s H  oXZ   _M	     sn
$ s  sn
f 7f)Nr?  Fr   TrK   )	r   r   r   r   r   updater   r   rb  )r?   r   r   rX  r8   r   r?  rs   rH  rI  rK   rK  namess                r   r   AsyncFileSystem._findU  s    ##D)He, 
T[[->'>'>"jj..CI %)JJt$Ud$Uf$U 	M.!5T"JJU[[]K]ztVd*]KL (?.	M L %V dll4000 CIsL056#)O666sl   AE	C!
E'C#(EC-C%C-:EC'E#E%C-'"E	D
&E0E>Ec           
      $  #    Ub  US:  a  [        S5      e[        U[        5      (       a  U R                  U/X#5      I S h  vN nGO[	        5       nU Vs/ s H  oPR                  U5      PM     nnU H  n[        U5      (       an  [	        U R                  XSS9I S h  vN 5      nXF-  nU(       aA  Ub  US::  a  MI  U[	        U R                  [        U5      UUb  US-
  OS S9I S h  vN 5      -  nM  U(       a%  [	        U R                  XSSS9I S h  vN 5      nXG-  nXT;  d  M  USL d   U R                  U5      I S h  vN (       d  M  UR                  U5        M     U(       d  [        U5      e[        U5      $  GN>s  snf  N N Nv NK7f)Nr   rB  )r   r	  T)r   rX  F)rn   r3   r   r   r$   r   r   r   r   r   r   r   r   rb  )r?   r   r   r   r   r   bitrecs           r   r   AsyncFileSystem._expand_pathn  sv    HqL:;;dC  ))4&)FFC%C59:T((+TD:Q<<DJJqJ$DDECJC  $/HM$s"&"3"3 $S	*39A9MASW #4 #    DJJqdJ$SSTCJC<Y%%7$,,q/<Q<QGGAJ/ 0 #D))c{= G ; E T<Qss   A FF FF1.FF
 A	F)F
*+FF
F)FFF3FF
FFFc                    #    g 7fr   r   )r?   r   create_parentsr8   s       r   r   AsyncFileSystem._mkdir          c                    #    g 7fr   r   )r?   r   r  s      r   r   AsyncFileSystem._makedirs  r  r  c                 Z   #    SU;  d  UR                  S5      (       a  [        e[        e7f)Nbcompression)r5  rn   r/   )r?   r   r   r8   s       r   
open_asyncAsyncFileSystem.open_async  s&     d?fjj77!!s   )+)r   r   r   r   )FN)FNNN)	overwrite)NN)Fr   N)NNru   r   )T)Nr   )TN)NFF)rb),__name__
__module____qualname____firstlineno____doc__
async_implmirror_sync_methodsdisable_throttlingr   propertyr   r   r   r   r   r   r   r   r   r   r   r  r   r   r  r   r)  r   r   r   r8  r   r   r   r   r   r   r   r   r   r   r  __static_attributes____classcell__)r   s   @r   r   r   6  s    J+0t * *  
"
"# :x"
&4" CG> '
R" !H
T" !G
R:
""4lCJ	72#J" "r   r   c                    SSK Jn  [        [        [        5      -    H  nUR                  S5      (       d  M  USS n[        R                  U5      (       d  M<  [        R                  " [        XS5      5      n[        [        XS5      SS5      nU[        XS5      L nU(       d  M  U(       d  M  [        [        X5      U S	9n[        XU5        UR                  (       a  M  [        [        XS5      S
S5      Ul        M     g)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   rs   r   NF__func__r   )r@   r  )fsspecr   async_methodsdirr   
startswithprivaterc  inspectiscoroutinefunctiongetattrrE   setattrr  )r@   r   methodsmethodiscounsync
is_defaultmths           r   r  r    s     *#o"66  %%*==  ..wsD/IJDWS59:tLF7+=#KKJt

"73#7SAc*{{{") 2TBIr#CK 7r   c                       \ rS rSrSrg)FSSpecCoroutineCanceli  r   N)r  r  r  r  r  r   r   r   r  r    s    r   r  Tc           
      >   SS K n[        R                  R                  [        S   5       Vs/ s H  oUR                  5       (       a  M  UPM     nnU (       a  U Vs/ s H  owR                  5       PM       nU Vs/ s H  nUR                  R                  R                  UR                  R                  R                  R                  UR                  R                  R                  R                  UR                  R                  R                  UR                  UR                  R                  5      U(       a  UOS S.PM     nnU(       a  U H  nUR                  n	UR!                  5         [        R"                  R$                  R'                  XR5        [        R"                  R$                  R!                  U5        U	 V
s/ s H  oS   " U5      PM       n
 UR                  R)                  U5        M     U$ s  snf s  snf s  snf s  sn
f ! U a     M  f = f)Nr   )localsr-  	firstlinelinelostacktask)	tracebackr!   tasks	all_tasksr   r   print_stack_corocr_framef_localsf_codeco_filenameco_firstlinenof_linenoformat_stack
_callbackscancelfuturesFutureset_exceptionthrow)printoutr  exc	with_taskr  tr  r  r   cbscbs              r   _dump_running_tasksr    s    //Q8I81Q8EI(-.			. 
 D jj))22JJ''..::,,33BBjj))22++DJJ,?,?@%D4	
   
 A,,CHHJOO""008OO""))!, #$"U1X$c"  J3 J.
" %  s0   G>	G>H;CHHHHHc                   V    \ rS rSrSS jrS rS rSS jrS rS r	S r
S	 rSS
 jrSrg)AbstractAsyncStreamedFilei  c                   #    Uc  SO
[        U5      nU R                  S:w  a  [        S5      eUS:  a  U R                  U R                  -
  nU R
                  (       a  [        S5      eUS:X  a  gU R                  U R                  U R                  U-   5      I Sh  vN nU =R                  [        U5      -  sl        U$  N$7f)z
Return data from cache, or fetch pieces as necessary

Parameters
----------
length: int (-1)
    Number of bytes to read; if <0, all remaining bytes.
Nre   r  zFile not in read moder   I/O operation on closed file.r   )intr   rn   r   locclosed_fetch_ranger   )r?   lengthr   s      r   readAbstractAsyncStreamedFile.read  s      ~3v;99455A:YY)F;;<==Q;%%dhh60ABBCH
 Cs   BCC%Cc                   #    U R                   S;  a  [        S5      eU R                  (       a  [        S5      eU R                  (       a  [        S5      eU R                  R                  U5      nU =R                  U-  sl        U R                  R                  5       U R                  :  a  U R                  5       I Sh  vN   U$  N7f)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wbzFile not in write moder  z0This file has been force-flushed, can only closeN)
r   rn   r  forcedbufferwriter  tell	blocksizeflush)r?   datar   s      r   r  AbstractAsyncStreamedFile.write  s      99L(566;;<==;;OPPkk%C;;/**,
 s   B?C
CC
c                   #    [        U SS5      (       a  gU R                  (       a  gU R                  S:X  a  SU l        OU R                  (       d  U R                  SS9I Sh  vN   U R                  bc  U R                  R                  U R                  5        U R                  R                  U R                  R                  U R                  5      5        SU l        g N|7f)z-Close file

Finalizes writes, discards cache
_unclosableFNr  T)force)
r  r  r   cacher  r  r  invalidate_cacher   _parentr   s    r   closeAbstractAsyncStreamedFile.close  s     
 4..;;99DJ;;jjtj,,,ww"((3(()CD -s   A!C"#C $A=C"c                 l  #    U R                   (       a  [        S5      eU(       a  U R                  (       a  [        S5      eU(       a  SU l        U R                  S;  a  g U(       d)  U R                  R                  5       U R                  :  a  g U R                  c   SU l         U R                  5       I S h  vN   U R                  US9I S h  vN SLaJ  U =R                  U R                  R                  SS5      -  sl        [        R                  " 5       U l        g g  Ni!   SU l         e = f Na7f)	NzFlush on closed filez+Force flush cannot be called more than onceT>   r  r  r   )finalF   )r  rn   r  r   r  r  r  offset_initiate_upload_upload_chunkseekioBytesIO)r?   r  s     r   r  AbstractAsyncStreamedFile.flush,  s     ;;344T[[JKKDK99L())+dnn<;;DK++---
 ##%#00=KK4;;++Aq11K**,DK > ."0s=   B#D4&D% 9D#:D% >D4D2AD4#D% %
D//D4c                    #    U $ 7fr   r   r   s    r   
__aenter__$AbstractAsyncStreamedFile.__aenter__I  s
     s   c                 @   #    U R                  5       I S h  vN   g  N7fr   )r  )r?   exc_typeexc_valexc_tbs       r   	__aexit__#AbstractAsyncStreamedFile.__aexit__L  s     jjls   c                    #    [         e7fr   r   )r?   rW   r   s      r   r  &AbstractAsyncStreamedFile._fetch_rangeO  r   r   c                    #    g 7fr   r   r   s    r   r  *AbstractAsyncStreamedFile._initiate_uploadR  r  r  c                    #    [         e7fr   r   )r?   r  s     r   r  'AbstractAsyncStreamedFile._upload_chunkU  r   r   )r  r  r  r  r  N)re   r  )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r  r    s/    .0*':""r   r  r   r  )Br!   asyncio.eventsrC   r  r  r   rJ   rY  r   
contextlibr   globr   typingr   r   	callbacksr   
exceptionsr	   implementations.localr
   r   r   specr   r   utilsr   r   r   ra  r  r   r   r   r.   r   r   r)   r;   rE   rO   rY   r\   rL   r]   ri   r_   ro   r  r2  rm   rj   rh   rt   boolrw   r   r  r   r  r#   r  r  r  r   r   r   <module>r     s       	  	 	  %  * ' & Q Q : < <
**W
6v++ 
	 %) *Z 7 7& 2!""'78 NNM<
  '7; " 2t  BL.f	"( f	"R@	I 	
 $$9UBr" 4 r"o    s   #D= =
E
	E
