
    |;3hL/                     2    d dl mZ d dlmZ  G d de      Zy)   )
filesystem)AsyncFileSystemc                       e Zd ZdZdZ	 	 	 	 	 dC fd	Zd Zd Zed        Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*d( Z+d) Z,dDd*Z-dDd+Z.d, Z/d- Z0d. Z1d/ Z2d0 Z3d1 Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z>d< Z?d= Z@d> ZAd? ZBd@ ZCdA ZDdB ZE xZFS )EDirFileSystemzDirectory prefix filesystem

    The DirFileSystem is a filesystem-wrapper. It assumes every path it is dealing with
    is relative to the `path`. After performing the necessary paths operation it
    delegates everything to the wrapped filesystem.
    dirc                 6   t        |   di | |t        dd|i|xs i }|xs |}| j                  r|j                  st        d      |j                  r$| j                  |j                  k7  rt        d      |j                  |      | _        || _        y)aS  
        Parameters
        ----------
        path: str
            Path to the directory.
        fs: AbstractFileSystem
            An instantiated filesystem to wrap.
        target_protocol, target_options:
            if fs is none, construct it from these
        fo: str
            Alternate for path; do not provide both
        Nprotocolz(can't use asynchronous with non-async fsz7both dirfs and fs should be in the same sync/async mode )	super__init__r   asynchronous
async_impl
ValueError_strip_protocolpathfs)selfr   r   fotarget_protocoltarget_optionsstorage_options	__class__s          \/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/fsspec/implementations/dirfs.pyr   zDirFileSystem.__init__   s    * 	+?+:O_O9M2OBzrR]]GHH==T.."//AVWW&&t,	    c                    t        |t              r\| j                  s|S |s| j                  S | j                  j                  j                  | j                  | j                  |      f      S t        |t              r3|j                         D ci c]  \  }}| j                  |      | c}}S |D cg c]  }| j                  |       c}S c c}}w c c}w N)

isinstancestrr   r   sepjoinr   dictitems_join)r   r   _pathvalues       r   r#   zDirFileSystem._join2   s    dC 99yy 77;;##TYY0D0DT0J$KLLdD!AENDJJu%u,NN/34e

5!44 O4s   C4Cc                 b   t        |t              r| j                  s|S || j                  k(  sA| j                  j                  | j                  j
                        r|| j                  dd  k(  ry| j                  | j                  j
                  z   }| j                  j                  | j                  j
                        r*|j                  | j                  j
                        s|dd  }|j                  |      sJ |t        |      d  S |D cg c]  }| j                  |       c}S c c}w )N    )r   r   r   
startswithr   r   len_relpath)r   r   prefixr$   s       r   r+   zDirFileSystem._relpath=   s    dC 99 tyy 		$$TWW[[1ddiim6KYY,Fyy##DGGKK09U??6***F&&267e$777s   D,c                 .    | j                   j                  S r   )r   r   r   s    r   r   zDirFileSystem.sepP   s    ww{{r   c                 V   K    | j                   j                  |i | d {   S 7 wr   )r   set_session)r   argskwargss      r   r0   zDirFileSystem.set_sessionT   s(     (TWW(($9&9999s    )')c                 v   K    | j                   j                  | j                  |      fi | d {   S 7 wr   )r   _rm_filer#   r   r   r2   s      r   r4   zDirFileSystem._rm_fileW   s1     %TWW%%djj&6A&AAAAs   0979c                 Z     | j                   j                  | j                  |      fi |S r   )r   rm_filer#   r5   s      r   r7   zDirFileSystem.rm_fileZ   s%    twwtzz$/:6::r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   _rmr#   r   r   r1   r2   s       r   r9   zDirFileSystem._rm]   s4      TWW[[D!1CDCFCCCC   3<:<c                 `     | j                   j                  | j                  |      g|i |S r   )r   rmr#   r:   s       r   r=   zDirFileSystem.rm`   s*    twwzz$**T*<T<V<<r   c                    K    | j                   j                  | j                  |      | j                  |      fi | d {   S 7 wr   )r   _cp_filer#   r   path1path2r2   s       r   r?   zDirFileSystem._cp_filec   s<     %TWW%%djj&7E9JUfUUUUs   A A	AA	c                 z     | j                   j                  | j                  |      | j                  |      fi |S r   )r   cp_filer#   r@   s       r   rD   zDirFileSystem.cp_filef   s0    twwtzz%0$**U2CNvNNr   c                    K    | j                   j                  | j                  |      | j                  |      g|i | d {   S 7 wr   )r   _copyr#   r   rA   rB   r1   r2   s        r   rF   zDirFileSystem._copyi   sU      #TWW]]JJuJJu
 
 	
 
 	
 
s   AAA
Ac                      | j                   j                  | j                  |      | j                  |      g|i |S r   )r   copyr#   rG   s        r   rI   zDirFileSystem.copyw   sE    tww||JJuJJu
 
 	
 	
r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   _piper#   r:   s       r   rK   zDirFileSystem._pipe   s4     "TWW]]4::d#3EdEfEEEEr;   c                 `     | j                   j                  | j                  |      g|i |S r   )r   piper#   r:   s       r   rM   zDirFileSystem.pipe   *    tww||DJJt,>t>v>>r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   
_pipe_filer#   r:   s       r   rP   zDirFileSystem._pipe_file   s6     'TWW''

4(8J4J6JJJJr;   c                 `     | j                   j                  | j                  |      g|i |S r   )r   	pipe_filer#   r:   s       r   rR   zDirFileSystem.pipe_file   s,     tww  D!1CDCFCCr   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   	_cat_filer#   r:   s       r   rT   zDirFileSystem._cat_file   6     &TWW&&tzz$'7I$I&IIIIr;   c                 `     | j                   j                  | j                  |      g|i |S r   )r   cat_filer#   r:   s       r   rW   zDirFileSystem.cat_file   ,    tww

4 0B4B6BBr   c                   K    | j                   j                  | j                  |      g|i | d {   }t        |t              r3|j                         D ci c]  \  }}| j                  |      | c}}S |S 7 Ic c}}w wr   )r   _catr#   r   r!   r"   r+   r   r   r1   r2   retkeyr%   s          r   rZ   zDirFileSystem._cat   s      DGGLLJJt

 
 
 c4 @C		L*#uDMM#&-LL

 Ms!   3BA?'BB9BBc                      | j                   j                  | j                  |      g|i |}t        |t              r3|j                         D ci c]  \  }}| j                  |      | c}}S |S c c}}w r   )r   catr#   r   r!   r"   r+   r[   s          r   r_   zDirFileSystem.cat   st    dggkkJJt

 
 c4 @C		L*#uDMM#&-LL
 Ms   A5c                 x   K    | j                   j                  || j                  |      fi | d {   S 7 wr   )r   	_put_filer#   r   lpathrpathr2   s       r   ra   zDirFileSystem._put_file   s3     &TWW&&udjj.?J6JJJJ   1:8:c                 \     | j                   j                  || j                  |      fi |S r   )r   put_filer#   rb   s       r   rg   zDirFileSystem.put_file   s)    twwtzz%'8CFCCr   c                 ~   K    | j                   j                  || j                  |      g|i | d {   S 7 wr   )r   _putr#   r   rc   rd   r1   r2   s        r   ri   zDirFileSystem._put   sL      "TWW\\JJu
 
 	
 
 	
 
s   4=;=c                 b     | j                   j                  || j                  |      g|i |S r   )r   putr#   rj   s        r   rl   zDirFileSystem.put   s<    tww{{JJu
 
 	
 	
r   c                 x   K    | j                   j                  | j                  |      |fi | d {   S 7 wr   )r   	_get_filer#   r   rd   rc   r2   s       r   rn   zDirFileSystem._get_file   s3     &TWW&&tzz%'8%J6JJJJre   c                 \     | j                   j                  | j                  |      |fi |S r   )r   get_filer#   ro   s       r   rq   zDirFileSystem.get_file   s)    tww

5 15CFCCr   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   _getr#   r   rd   r1   r2   s       r   rs   zDirFileSystem._get   s4     !TWW\\$**U"3EdEfEEEEr;   c                 `     | j                   j                  | j                  |      g|i |S r   )r   getr#   rt   s       r   rv   zDirFileSystem.get   s*    tww{{4::e,>t>v>>r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _isfiler#   r   r   s     r   rx   zDirFileSystem._isfile   (     WW__TZZ%56666   .757c                 V    | j                   j                  | j                  |            S r   )r   isfiler#   ry   s     r   r}   zDirFileSystem.isfile       ww~~djj.//r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _isdirr#   ry   s     r   r   zDirFileSystem._isdir   s(     WW^^DJJt$45555r{   c                 V    | j                   j                  | j                  |            S r   )r   isdirr#   ry   s     r   r   zDirFileSystem.isdir       ww}}TZZ-..r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _sizer#   ry   s     r   r   zDirFileSystem._size   s(     WW]]4::d#34444r{   c                 V    | j                   j                  | j                  |            S r   )r   sizer#   ry   s     r   r   zDirFileSystem.size   s    ww||DJJt,--r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _existsr#   ry   s     r   r   zDirFileSystem._exists   rz   r{   c                 V    | j                   j                  | j                  |            S r   )r   existsr#   ry   s     r   r   zDirFileSystem.exists   r~   r   c                    K    | j                   j                  | j                  |      fi | d {   }|j                         }| j	                  |d         |d<   |S 7 -wNname)r   _infor#   rI   r+   r   r   r2   infos       r   r   zDirFileSystem._info   sV     "TWW]]4::d#3>v>>yy{}}T&\2V ?s   0A"A .A"c                      | j                   j                  | j                  |      fi |}|j                         }| j	                  |d         |d<   |S r   )r   r   r#   rI   r+   r   s       r   r   zDirFileSystem.info   sJ    tww||DJJt,77yy{}}T&\2Vr   c                 B  K    | j                   j                  | j                  |      fd|i| d {   j                         }|rCg }|D ]:  }|j                         }| j	                  |d         |d<   |j                  |       < |S | j	                  |      S 7 hwNdetailr   )r   _lsr#   rI   r+   appendr   r   r   r2   r\   outentrys          r   r   zDirFileSystem._ls   s      TWW[[D!1K&KFKKQQSC "

 $eFm <f

5!" J}}S!! Ls   2BBA)Bc                 &    | j                   j                  | j                  |      fd|i|j                         }|rCg }|D ]:  }|j                         }| j	                  |d         |d<   |j                  |       < |S | j	                  |      S r   )r   lsr#   rI   r+   r   r   s          r   r   zDirFileSystem.ls  s    dggjjD)C&CFCHHJC "

 $eFm <f

5!" J}}S!!r   c                   K    | j                   j                  | j                  |      g|i |2 3 d {   \  }}}| j                  |      ||f %7  6 y wr   )r   _walkr#   r+   r   r   r1   r2   rootdirsfiless          r   r   zDirFileSystem._walk  s^     '4tww}}TZZ5E'W'WPV'W 	3 	3#$e--%tU22	3'Ws%   0AAAAAAAc              /      K    | j                   j                  | j                  |      g|i |D ]  \  }}}| j                  |      ||f  y wr   )r   walkr#   r+   r   s          r   r   zDirFileSystem.walk  sT     !-djj.>!P!P!P 	3D$--%tU22	3s   AAc                 2  K   |j                  dd      } | j                  j                  | j                  |      fi | d {   }|r3|j	                         D ci c]  \  }}| j                  |      | c}}S | j                  |      S 7 Jc c}}w wNr   F)rv   r   _globr#   r"   r+   r   r   r2   r   r\   r   s         r   r   zDirFileSystem._glob  s~     He,!DGGMM$**T"2=f==@C		L*$DMM$'-LL}}S!! >Ls$   ABBBB:BBc                    |j                  dd      } | j                  j                  | j                  |      fi |}|r3|j	                         D ci c]  \  }}| j                  |      | c}}S | j                  |      S c c}}w r   )rv   r   globr#   r"   r+   r   s         r   r   zDirFileSystem.glob  su    He,dggll4::d+6v6@C		L*$DMM$'-LL}}S!! Ms   Bc                   K   |j                  dd      } | j                  j                  | j                  |      g|i | d {   }|r|S |j	                         D ci c]  \  }}| j                  |      | c}}S 7 ;c c}}w wNtotalT)rv   r   _dur#   r"   r+   r   r   r1   r2   r   r\   r   s          r   r   zDirFileSystem._du#  s}     

7D)DGGKK

4 0B4B6BBJ<?IIKHjdDd#T)HH	 C Is$   ABBB#B?BBc                     |j                  dd      } | j                  j                  | j                  |      g|i |}|r|S |j	                         D ci c]  \  }}| j                  |      | c}}S c c}}w r   )rv   r   dur#   r"   r+   r   s          r   r   zDirFileSystem.du+  sm    

7D)dggjjD);D;F;J<?IIKHjdDd#T)HHHs   A9c                 8  K   |j                  dd      } | j                  j                  | j                  |      g|i | d {   }|r3|j	                         D ci c]  \  }}| j                  |      | c}}S | j                  |      S 7 Jc c}}w wr   )rv   r   _findr#   r"   r+   r   r   r1   r2   r   r\   r   s          r   r   zDirFileSystem._find3  s     He,!DGGMM$**T"2DTDVDD@C		L*$DMM$'-LL}}S!! ELs$   ABBB!B=BBc                    |j                  dd      } | j                  j                  | j                  |      g|i |}|r3|j	                         D ci c]  \  }}| j                  |      | c}}S | j                  |      S c c}}w r   )rv   r   findr#   r"   r+   r   s          r   r   zDirFileSystem.find:  sz    He,dggll4::d+=d=f=@C		L*$DMM$'-LL}}S!! Ms   Bc                    K   | j                   | j                  j                  | j                  |      g|i | d {         S 7 wr   )r+   r   _expand_pathr#   r:   s       r   r   zDirFileSystem._expand_pathA  sD     }}&$''&&tzz$'7I$I&II
 	
Is   >A A		Ac                 ~    | j                   | j                  j                  | j                  |      g|i |      S r   )r+   r   expand_pathr#   r:   s       r   r   zDirFileSystem.expand_pathF  s6    }}0TWW00D1ASDSFSTTr   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   _mkdirr#   r:   s       r   r   zDirFileSystem._mkdirI  s4     #TWW^^DJJt$4FtFvFFFFr;   c                 `     | j                   j                  | j                  |      g|i |S r   )r   mkdirr#   r:   s       r   r   zDirFileSystem.mkdirL  s*    tww}}TZZ-????r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   	_makedirsr#   r:   s       r   r   zDirFileSystem._makedirsO  rU   r;   c                 `     | j                   j                  | j                  |      g|i |S r   )r   makedirsr#   r:   s       r   r   zDirFileSystem.makedirsR  rX   r   c                 V    | j                   j                  | j                  |            S r   )r   rmdirr#   ry   s     r   r   zDirFileSystem.rmdirU  r   r   c                 z     | j                   j                  | j                  |      | j                  |      fi |S r   )r   mvr#   r@   s       r   r   zDirFileSystem.mvX  s;    twwzzJJuJJu
 
 	
r   c                 Z     | j                   j                  | j                  |      fi |S r   )r   touchr#   r5   s      r   r   zDirFileSystem.touch_  s%    tww}}TZZ-888r   c                 V    | j                   j                  | j                  |            S r   )r   createdr#   ry   s     r   r   zDirFileSystem.createdb  s    wwtzz$/00r   c                 V    | j                   j                  | j                  |            S r   )r   modifiedr#   ry   s     r   r   zDirFileSystem.modifiede  s     ww

4 011r   c                 `     | j                   j                  | j                  |      g|i |S r   )r   signr#   r:   s       r   r   zDirFileSystem.signh  rN   r   c                 h    | j                   j                   d| j                   d| j                   dS )Nz(path='z', fs=))r   __qualname__r   r   r.   s    r   __repr__zDirFileSystem.__repr__k  s.    ..--.gdii[twwiqQQr   c                 `     | j                   j                  | j                  |      g|i |S r   )r   openr#   r:   s       r   r   zDirFileSystem.openn  s9     tww||JJt

 
 	
r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   
open_asyncr#   r:   s       r   r   zDirFileSystem.open_asyncz  sI      (TWW''JJt

 
 
 	
 
r;   )NNNNN)T)G__name__
__module__r   __doc__r	   r   r#   r+   propertyr   r0   r4   r7   r9   r=   r?   rD   rF   rI   rK   rM   rP   rR   rT   rW   rZ   r_   ra   rg   ri   rl   rn   rq   rs   rv   rx   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r      s    H !F	58&  :B;D=VO

F?KDJC

KD

KDF?706/5.70
"
"33""II""

UG@JC/
912?R



r   r   N)r(   r   asynr   r   r
   r   r   <module>r      s     "
O 
r   