
    9jP1                     @    d dl mZ d dlmZ ddlmZ  G d dee      Zy)   )
filesystem)AsyncFileSystem   )ChainedFileSystemc                       e Zd ZdZdZ	 	 	 	 	 dE fd	Zd Zd Zed        Z	d Z
d Zd	 Zd
 Zd ZdFdZd Zd Zd Zd Zd Zd Zd Zd Z	 dGd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.dHd,Z/dHd-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 ZEdC ZFdD ZG xZHS )I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          \/media/conek/DATA/Code/OCR/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._join3   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 )Nr    )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.sepQ   s    ww{{r   c                 V   K    | j                   j                  |i | d {   S 7 wr   )r   set_session)r   argskwargss      r   r1   zDirFileSystem.set_sessionU   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   r3   s      r   r5   zDirFileSystem._rm_fileX   s1     %TWW%%djj&6A&AAAAs   0979c                 Z     | j                   j                  | j                  |      fi |S r   )r   rm_filer%   r6   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   r2   r3   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.rma   s*    twwzz$**T*<T<V<<r   c                 \    | j                   j                  | j                  |      ||      S )N)	recursivemaxdepth)r   deleter%   )r   r   r@   rA   s       r   rB   zDirFileSystem.deleted   s$    ww~~djj.)h~WWr   c                    K    | j                   j                  | j                  |      | j                  |      fi | d {   S 7 wr   )r   _cp_filer%   r   path1path2r3   s       r   rD   zDirFileSystem._cp_fileg   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%   rE   s       r   rI   zDirFileSystem.cp_filej   s0    twwtzz%0$**U2CNvNNr   c                    K    | j                   j                  | j                  |      | j                  |      g|i | d {   S 7 wr   )r   _copyr%   r   rF   rG   r2   r3   s        r   rK   zDirFileSystem._copym   sU      #TWW]]JJuJJu
 
 	
 
 	
 
s   AAA
Ac                      | j                   j                  | j                  |      | j                  |      g|i |S r   )r   copyr%   rL   s        r   rN   zDirFileSystem.copy{   sE    tww||JJuJJu
 
 	
 	
r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   _piper%   r;   s       r   rP   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   rR   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   rU   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   rW   zDirFileSystem.pipe_file   s,     tww  D!1CDCFCCr   c                 d     | j                   j                  | j                  |      |f|||d|S )N)encodingerrorsnewline)r   
write_textr%   )r   r   r'   rY   rZ   r[   r3   s          r   r\   zDirFileSystem.write_text   sF     "tww!!JJt
 
 
 	
r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   	_cat_filer%   r;   s       r   r^   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   ra   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   r2   r3   retkeyr'   s          r   rd   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,   re   s          r   ri   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rpathr3   s       r   rk   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%   rl   s       r   rq   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   rm   rn   r2   r3   s        r   rs   zDirFileSystem._put   sL      "TWW\\JJu
 
 	
 
 	
 
s   4=;=c                 b     | j                   j                  || j                  |      g|i |S r   )r   putr%   rt   s        r   rv   zDirFileSystem.put   s<    tww{{JJu
 
 	
 	
r   c                 x   K    | j                   j                  | j                  |      |fi | d {   S 7 wr   )r   	_get_filer%   r   rn   rm   r3   s       r   rx   zDirFileSystem._get_file   s3     &TWW&&tzz%'8%J6JJJJro   c                 \     | j                   j                  | j                  |      |fi |S r   )r   get_filer%   ry   s       r   r{   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   rn   r2   r3   s       r   r}   zDirFileSystem._get   s4     !TWW\\$**U"3EdEfEEEEr<   c                 `     | j                   j                  | j                  |      g|i |S r   )r   getr%   r~   s       r   r   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   r   zDirFileSystem._isfile   (     WW__TZZ%56666   .757c                 V    | j                   j                  | j                  |            S r   )r   isfiler%   r   s     r   r   zDirFileSystem.isfile       ww~~djj.//r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _isdirr%   r   s     r   r   zDirFileSystem._isdir   s(     WW^^DJJt$45555r   c                 V    | j                   j                  | j                  |            S r   )r   isdirr%   r   s     r   r   zDirFileSystem.isdir       ww}}TZZ-..r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _sizer%   r   s     r   r   zDirFileSystem._size   s(     WW]]4::d#34444r   c                 V    | j                   j                  | j                  |            S r   )r   sizer%   r   s     r   r   zDirFileSystem.size   s    ww||DJJt,--r   c                 r   K   | j                   j                  | j                  |             d {   S 7 wr   )r   _existsr%   r   s     r   r   zDirFileSystem._exists   r   r   c                 V    | j                   j                  | j                  |            S r   )r   existsr%   r   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%   rN   r,   r   r   r3   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%   rN   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%   rN   r,   appendr   r   r   r3   rf   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%   rN   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   r2   r3   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)r   r   _globr%   r$   r,   r   r   r3   r   rf   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   )r   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)r   r   _dur%   r$   r,   r   r   r2   r3   r   rf   r   s          r   r   zDirFileSystem._du3  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   )r   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   )r   r   _findr%   r$   r,   r   r   r2   r3   r   rf   r   s          r   r   zDirFileSystem._findC  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   )r   r   findr%   r$   r,   r   s          r   r   zDirFileSystem.findJ  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_pathQ  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_pathV  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._mkdirY  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.mkdir\  s*    tww}}TZZ-????r   c                 |   K    | j                   j                  | j                  |      g|i | d {   S 7 wr   )r   	_makedirsr%   r;   s       r   r   zDirFileSystem._makedirs_  r_   r<   c                 `     | j                   j                  | j                  |      g|i |S r   )r   makedirsr%   r;   s       r   r   zDirFileSystem.makedirsb  rb   r   c                 V    | j                   j                  | j                  |            S r   )r   rmdirr%   r   s     r   r   zDirFileSystem.rmdire  r   r   c                 z     | j                   j                  | j                  |      | j                  |      fi |S r   )r   mvr%   rE   s       r   r   zDirFileSystem.mvh  s;    twwzzJJuJJu
 
 	
r   c                 Z     | j                   j                  | j                  |      fi |S r   )r   touchr%   r6   s      r   r   zDirFileSystem.toucho  s%    tww}}TZZ-888r   c                 V    | j                   j                  | j                  |            S r   )r   createdr%   r   s     r   r   zDirFileSystem.createdr  s    wwtzz$/00r   c                 V    | j                   j                  | j                  |            S r   )r   modifiedr%   r   s     r   r   zDirFileSystem.modifiedu  s     ww

4 011r   c                 `     | j                   j                  | j                  |      g|i |S r   )r   signr%   r;   s       r   r   zDirFileSystem.signx  rS   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__{  s.    ..--.gdii[twwiqQQr   c                 `     | j                   j                  | j                  |      g|i |S r   )r   openr%   r;   s       r   r   zDirFileSystem.open~  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_async  sI      (TWW''JJt

 
 
 	
 
r<   )NNNNN)FN)NNN)T)I__name__
__module__r   __doc__r   r   r%   r,   propertyr!   r1   r5   r8   r:   r>   rB   rD   rI   rK   rN   rP   rR   rU   rW   r\   r^   ra   rd   ri   rk   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   r   r   r   r   __classcell__)r   s   @r   r   r      s    H !F	58&  :B;D=XVO

F?KD @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   chainedr   r   r   r   r   <module>r      s     " &N
O%6 N
r   