
    wg /                     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                 b   t        |   di | |t        dd|i|xs i }|du|duz  du rt        d      |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protocolFzProvide path or fo, not bothz(can't use asynchronous with non-async fsz7both dirfs and fs should be in the same sync/async mode )	super__init__r   
ValueErrorasynchronous
async_impl_strip_protocolpathfs)selfr   r   fotarget_protocoltarget_optionsstorage_options	__class__s          a/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/fsspec/implementations/dirfs.pyr   zDirFileSystem.__init__   s    * 	+?+:O_O9M2OB40E9;<<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._join4   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.sepR   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_sessionV   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_fileY   s1     %TWW%%djj&6A&AAAA   0979c                 Z     | j                   j                  | j                  |      fi |S r   )r   rm_filer#   r5   s      r   r8   zDirFileSystem.rm_file\   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   r:   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.rmb   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_filee   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#   rA   s       r   rE   zDirFileSystem.cp_fileh   s0    twwtzz%0$**U2CNvNNr   c                    K    | j                   j                  | j                  |      | j                  |      g|i | d {   S 7 wr   )r   _copyr#   r   rB   rC   r1   r2   s        r   rG   zDirFileSystem._copyk   sU      #TWW]]JJuJJu
 
 	
 
 	
 
s   AAA
Ac                      | j                   j                  | j                  |      | j                  |      g|i |S r   )r   copyr#   rH   s        r   rJ   zDirFileSystem.copyy   sE    tww||JJuJJu
 
 	
 	
r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   _piper#   r;   s       r   rL   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   rN   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   rQ   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   rS   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   rU   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   rX   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   r[   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   rb   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#   rc   s       r   rh   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   rd   re   r1   r2   s        r   rj   zDirFileSystem._put   sL      "TWW\\JJu
 
 	
 
 	
 
s   4=;=c                 b     | j                   j                  || j                  |      g|i |S r   )r   putr#   rk   s        r   rm   zDirFileSystem.put   s<    tww{{JJu
 
 	
 	
r   c                 x   K    | j                   j                  | j                  |      |fi | d {   S 7 wr   )r   	_get_filer#   r   re   rd   r2   s       r   ro   zDirFileSystem._get_file   s3     &TWW&&tzz%'8%J6JJJJrf   c                 \     | j                   j                  | j                  |      |fi |S r   )r   get_filer#   rp   s       r   rr   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   re   r1   r2   s       r   rt   zDirFileSystem._get   s4     !TWW\\$**U"3EdEfEEEEr<   c                 `     | j                   j                  | j                  |      g|i |S r   )r   getr#   ru   s       r   rw   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   ry   zDirFileSystem._isfile   (     WW__TZZ%56666   .757c                 V    | j                   j                  | j                  |            S r   )r   isfiler#   rz   s     r   r~   zDirFileSystem.isfile       ww~~djj.//r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _isdirr#   rz   s     r   r   zDirFileSystem._isdir   s(     WW^^DJJt$45555r|   c                 V    | j                   j                  | j                  |            S r   )r   isdirr#   rz   s     r   r   zDirFileSystem.isdir       ww}}TZZ-..r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _sizer#   rz   s     r   r   zDirFileSystem._size   s(     WW]]4::d#34444r|   c                 V    | j                   j                  | j                  |            S r   )r   sizer#   rz   s     r   r   zDirFileSystem.size   s    ww||DJJt,--r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _existsr#   rz   s     r   r   zDirFileSystem._exists   r{   r|   c                 V    | j                   j                  | j                  |            S r   )r   existsr#   rz   s     r   r   zDirFileSystem.exists   r   r   c                 v   K    | j                   j                  | j                  |      fi | d {   S 7 wr   )r   _infor#   r5   s      r   r   zDirFileSystem._info   s/     "TWW]]4::d#3>v>>>>r6   c                 Z     | j                   j                  | j                  |      fi |S r   )r   infor#   r5   s      r   r   zDirFileSystem.info   s%    tww||DJJt,777r   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detailname)r   _lsr#   rJ   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#   rJ   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)rw   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   )rw   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)rw   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   )rw   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   )rw   r   _findr#   r"   r+   r   r   r1   r2   r   r]   r   s          r   r   zDirFileSystem._find/  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   )rw   r   findr#   r"   r+   r   s          r   r   zDirFileSystem.find6  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_path=  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_pathB  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._mkdirE  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.mkdirH  s*    tww}}TZZ-????r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   	_makedirsr#   r;   s       r   r   zDirFileSystem._makedirsK  rV   r<   c                 `     | j                   j                  | j                  |      g|i |S r   )r   makedirsr#   r;   s       r   r   zDirFileSystem.makedirsN  rY   r   c                 V    | j                   j                  | j                  |            S r   )r   rmdirr#   rz   s     r   r   zDirFileSystem.rmdirQ  r   r   c                 z     | j                   j                  | j                  |      | j                  |      fi |S r   )r   mvr#   rA   s       r   r   zDirFileSystem.mvT  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#   rz   s     r   r   zDirFileSystem.created^  s    wwtzz$/00r   c                 V    | j                   j                  | j                  |            S r   )r   modifiedr#   rz   s     r   r   zDirFileSystem.modifieda  s     ww

4 011r   c                 `     | j                   j                  | j                  |      g|i |S r   )r   signr#   r;   s       r   r   zDirFileSystem.signd  rO   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__g  s.    ..--.gdii[twwiqQQr   c                 `     | j                   j                  | j                  |      g|i |S r   )r   openr#   r;   s       r   r   zDirFileSystem.openj  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_asyncv  sI      (TWW''JJt

 
 
 	
 
r<   )NNNNN)T)G__name__
__module__r   __doc__r	   r   r#   r+   propertyr   r0   r4   r8   r:   r>   r@   rE   rG   rJ   rL   rN   rQ   rS   rU   rX   r[   r`   rb   rh   rj   rm   ro   rr   rt   rw   ry   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 #J	58&  :B;D=VO

F?KDJC

KD

KDF?706/5.70?8
"
"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   