
    Loj4                     R    S SK Jr  S SKJr  SSKJr  SSKJr  S r " S S\\5      r	g	)
   )
filesystem)AsyncFileSystem   )ChainedFileSystem)LocalFileSystemc                     SnU R                  S5       H.  nUS:X  a  US-  nUS:  a    gM  U(       d  M!  US:w  d  M)  US-  nM0     g)zGWhether a relative path would resolve above its root via ".." segments.    /z..r   T.F)split)pathdepthparts      V/mnt/workspace/venv-train/lib/python3.13/site-packages/fsspec/implementations/dirfs.py_escapes_rootr      sQ    E

34<QJEqy TdckQJE       c                     ^  \ rS rSrSrSr     SGU 4S jjrS rS r\	S 5       r
S rS	 rS
 rS rS rSHS jrS rS rS rS rS rS rS rS r SIS jrS rS rS rS rS rS rS r S r!S r"S  r#S! r$S" r%S# r&S$ r'S% r(S& r)S' r*S( r+S) r,S* r-S+ r.S, r/SJS- jr0SJS. jr1S/ r2S0 r3S1 r4S2 r5S3 r6S4 r7S5 r8S6 r9S7 r:S8 r;S9 r<S: r=S; r>S< r?S= r@S> rAS? rBS@ rCSA rDSB rESC rFSD rGSE rHSFrIU =rJ$ )KDirFileSystem   zDirectory 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                 l  > [         TU ]  " S0 UD6  Uc  [        SSU0U=(       d    0 D6nU=(       d    UnU R                  (       a  UR                  (       d  [        S5      eUR                  (       a%  U R                  UR                  :w  a  [        S5      eUR                  U5      U l        X l        g)z
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_protocolr   fs)selfr   r    fotarget_protocoltarget_optionsstorage_options	__class__s          r   r   DirFileSystem.__init__   s    * 	+?+:O_O9M2OBzrR]]GHH==T.."//AVWW&&t,	r   c                    [        U[        5      (       a  U R                  (       d  U$ U(       d  U R                  $ U R                  U5      n[        U R                  [
        5      (       a.  [        U5      (       a  [        SU< SU R                  < S35      eU R                  R                  R                  U R                  U45      $ [        U[        5      (       a5  UR                  5        VVs0 s H  u  p#U R                  U5      U_M     snn$ U Vs/ s H  o R                  U5      PM     sn$ s  snnf s  snf )Nzpath z escapes the z root of the filesystem)
isinstancestrr   r   r    r   r   r   sepjoindictitems_join)r!   r   _pathvalues       r   r/   DirFileSystem._joinA   s    dC  99yy ''-D $''?33d8K8K D8==TU  77;;##TYY$566dD!!AENDJJu%u,NN/34te

5!t44 O4s   3D6D<c                    [        U[        5      (       Ga  U R                  (       d  U$ XR                  :X  dF  U R                  R                  U R                  R
                  5      (       a  XR                  SS  :X  a  gU R                  U R                  R
                  -   nU R                  R                  U R                  R
                  5      (       a/  UR                  U R                  R
                  5      (       d  USS  nUR                  U5      (       d   eU[        U5      S  $ U Vs/ s H  o0R                  U5      PM     sn$ s  snf )Nr    )r)   r*   r   
startswithr    r+   len_relpath)r!   r   prefixr0   s       r   r7   DirFileSystem._relpathT   s    dC  99 yy 		$$TWW[[11diim6KYY,Fyy##DGGKK009U9U??6****F&&267$e$$777s   0Ec                 .    U R                   R                  $ N)r    r+   r!   s    r   r+   DirFileSystem.sepg   s    ww{{r   c                 V   #    U R                   R                  " U0 UD6I S h  vN $  N7fr;   )r    set_session)r!   argskwargss      r   r?   DirFileSystem.set_sessionk   s%     WW(($9&9999s    )')c                 v   #    U R                   R                  " U R                  U5      40 UD6I S h  vN $  N7fr;   )r    _rm_filer/   r!   r   rA   s      r   rD   DirFileSystem._rm_filen   s.     WW%%djj&6A&AAAA   0979c                 Z    U R                   R                  " U R                  U5      40 UD6$ r;   )r    rm_filer/   rE   s      r   rI   DirFileSystem.rm_fileq   s#    wwtzz$/:6::r   c                 |   #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    _rmr/   r!   r   r@   rA   s       r   rL   DirFileSystem._rmt   s1     WW[[D!1CDCFCCCC   3<:<c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    rmr/   rM   s       r   rQ   DirFileSystem.rmw   s(    wwzz$**T*<T<V<<r   c                 T    U R                   R                  U R                  U5      X#S9$ )N)	recursivemaxdepth)r    deleter/   )r!   r   rT   rU   s       r   rV   DirFileSystem.deletez   s"    ww~~djj.)~WWr   c                    #    U R                   R                  " U R                  U5      U R                  U5      40 UD6I S h  vN $  N7fr;   )r    _cp_filer/   r!   path1path2rA   s       r   rY   DirFileSystem._cp_file}   s9     WW%%djj&7E9JUfUUUUs   A A	AA	c                 z    U R                   R                  " U R                  U5      U R                  U5      40 UD6$ r;   )r    cp_filer/   rZ   s       r   r_   DirFileSystem.cp_file   s.    wwtzz%0$**U2CNvNNr   c                    #    U R                   R                  " U R                  U5      U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    _copyr/   r!   r[   r\   r@   rA   s        r   rb   DirFileSystem._copy   sR      WW]]JJuJJu
 
 	
 
 	
 
s   AAA
Ac                     U R                   R                  " U R                  U5      U R                  U5      /UQ70 UD6$ r;   )r    copyr/   rc   s        r   rf   DirFileSystem.copy   sC    ww||JJuJJu
 
 	
 	
r   c                 |   #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    _piper/   rM   s       r   ri   DirFileSystem._pipe   s1     WW]]4::d#3EdEfEEEErO   c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    piper/   rM   s       r   rl   DirFileSystem.pipe   (    ww||DJJt,>t>v>>r   c                 |   #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    
_pipe_filer/   rM   s       r   rp   DirFileSystem._pipe_file   s3     WW''

4(8J4J6JJJJrO   c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    	pipe_filer/   rM   s       r   rs   DirFileSystem.pipe_file   s*    ww  D!1CDCFCCr   c                 d    U R                   R                  " U R                  U5      U4UUUS.UD6$ )N)encodingerrorsnewline)r    
write_textr/   )r!   r   r1   rv   rw   rx   rA   s          r   ry   DirFileSystem.write_text   sD     ww!!JJt
 
 
 	
r   c                 |   #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    	_cat_filer/   rM   s       r   r|   DirFileSystem._cat_file   3     WW&&tzz$'7I$I&IIIIrO   c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    cat_filer/   rM   s       r   r   DirFileSystem.cat_file   *    ww

4 0B4B6BBr   c                    #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN n[        U[        5      (       a5  UR                  5        VVs0 s H  u  pVU R                  U5      U_M     snn$ U$  NPs  snnf 7fr;   )r    _catr/   r)   r-   r.   r7   r!   r   r@   rA   retkeyr1   s          r   r   DirFileSystem._cat   s     GGLLJJt

 
 
 c4  @C		L*#DMM#&-LL

 Ms!   3BB,B"B BBc                    U R                   R                  " U R                  U5      /UQ70 UD6n[        U[        5      (       a5  UR                  5        VVs0 s H  u  pVU R                  U5      U_M     snn$ U$ s  snnf r;   )r    catr/   r)   r-   r.   r7   r   s          r   r   DirFileSystem.cat   sw    ggkkJJt

 
 c4  @C		L*#DMM#&-LL
 Ms   A<c                 v   #    U R                   R                  " XR                  U5      40 UD6I S h  vN $  N7fr;   )r    	_put_filer/   r!   lpathrpathrA   s       r   r   DirFileSystem._put_file   s.     WW&&ujj.?J6JJJJrG   c                 Z    U R                   R                  " XR                  U5      40 UD6$ r;   )r    put_filer/   r   s       r   r   DirFileSystem.put_file   s%    wwzz%'8CFCCr   c                 ~   #    U R                   R                  " UU R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    _putr/   r!   r   r   r@   rA   s        r   r   DirFileSystem._put   sI      WW\\JJu
 
 	
 
 	
 
s   4=;=c                 b    U R                   R                  " UU R                  U5      /UQ70 UD6$ r;   )r    putr/   r   s        r   r   DirFileSystem.put   s:    ww{{JJu
 
 	
 	
r   c                 x   #    U R                   R                  " U R                  U5      U40 UD6I S h  vN $  N7fr;   )r    	_get_filer/   r!   r   r   rA   s       r   r   DirFileSystem._get_file   s0     WW&&tzz%'8%J6JJJJs   1:8:c                 \    U R                   R                  " U R                  U5      U40 UD6$ r;   )r    get_filer/   r   s       r   r   DirFileSystem.get_file   s'    ww

5 15CFCCr   c                 |   #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    _getr/   r!   r   r@   rA   s       r   r   DirFileSystem._get   s1     WW\\$**U"3EdEfEEEErO   c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    getr/   r   s       r   r   DirFileSystem.get   s(    ww{{4::e,>t>v>>r   c                 r   #    U R                   R                  U R                  U5      5      I S h  vN $  N7fr;   )r    _isfiler/   r!   r   s     r   r   DirFileSystem._isfile   '     WW__TZZ%56666   .757c                 V    U R                   R                  U R                  U5      5      $ r;   )r    isfiler/   r   s     r   r   DirFileSystem.isfile       ww~~djj.//r   c                 r   #    U R                   R                  U R                  U5      5      I S h  vN $  N7fr;   )r    _isdirr/   r   s     r   r   DirFileSystem._isdir   s'     WW^^DJJt$45555r   c                 V    U R                   R                  U R                  U5      5      $ r;   )r    isdirr/   r   s     r   r   DirFileSystem.isdir       ww}}TZZ-..r   c                 r   #    U R                   R                  U R                  U5      5      I S h  vN $  N7fr;   )r    _sizer/   r   s     r   r   DirFileSystem._size  s'     WW]]4::d#34444r   c                 V    U R                   R                  U R                  U5      5      $ r;   )r    sizer/   r   s     r   r   DirFileSystem.size  s    ww||DJJt,--r   c                 r   #    U R                   R                  U R                  U5      5      I S h  vN $  N7fr;   )r    _existsr/   r   s     r   r   DirFileSystem._exists	  r   r   c                 V    U R                   R                  U R                  U5      5      $ r;   )r    existsr/   r   s     r   r   DirFileSystem.exists  r   r   c                    #    U R                   R                  " U R                  U5      40 UD6I S h  vN nUR                  5       nU R	                  US   5      US'   U$  N-7fNname)r    _infor/   rf   r7   r!   r   rA   infos       r   r   DirFileSystem._info  sS     WW]]4::d#3>v>>yy{}}T&\2V ?s   0A"A .A"c                     U R                   R                  " U R                  U5      40 UD6nUR                  5       nU R	                  US   5      US'   U$ r   )r    r   r/   rf   r7   r   s       r   r   DirFileSystem.info  sH    ww||DJJt,77yy{}}T&\2Vr   c                 P  #    U R                   R                  " U R                  U5      4SU0UD6I S h  vN R                  5       nU(       aE  / nU H;  nUR                  5       nU R	                  US   5      US'   UR                  U5        M=     U$ U R	                  U5      $  No7fNdetailr   )r    _lsr/   rf   r7   appendr!   r   r   rA   r   outentrys          r   r   DirFileSystem._ls  s     WW[[D!1K&KFKKQQSC

 $eFm <f

5!  J}}S!! Ls   2B&B$A0B&c                 4   U R                   R                  " U R                  U5      4SU0UD6R                  5       nU(       aE  / nU H;  nUR                  5       nU R	                  US   5      US'   UR                  U5        M=     U$ U R	                  U5      $ r   )r    lsr/   rf   r7   r   r   s          r   r   DirFileSystem.ls'  s    ggjjD)C&CFCHHJC

 $eFm <f

5!  J}}S!!r   c                   #    U R                   R                  " U R                  U5      /UQ70 UD6  S h  vN u  pEnU R                  U5      XV47v   M$   N
 g 7fr;   )r    _walkr/   r7   r!   r   r@   rA   rootdirsfiless          r   r   DirFileSystem._walk3  sQ     '+ww}}TZZ5E'W'WPV'W 	3#$e--%t22	3'Ws%   0AAAAAAAc              /      #    U R                   R                  " U R                  U5      /UQ70 UD6 H  u  pEnU R                  U5      XV4v   M     g 7fr;   )r    walkr/   r7   r   s          r   r   DirFileSystem.walk7  sI     !%djj.>!P!P!PD--%t22 "Qs   AAc                 @  #    UR                  SS5      nU R                  R                  " U R                  U5      40 UD6I S h  vN nU(       a5  UR	                  5        VVs0 s H  u  pU R                  U5      U_M     snn$ U R                  U5      $  NQs  snnf 7fNr   F)r   r    _globr/   r.   r7   r!   r   rA   r   r   r   s         r   r   DirFileSystem._glob;  s}     He,GGMM$**T"2=f==@C		L*$DMM$'-LL}}S!! >Ls$   ABBB#BBBc                 $   UR                  SS5      nU R                  R                  " U R                  U5      40 UD6nU(       a5  UR	                  5        VVs0 s H  u  pU R                  U5      U_M     snn$ U R                  U5      $ s  snnf r   )r   r    globr/   r.   r7   r   s         r   r   DirFileSystem.globB  su    He,ggll4::d+6v6@C		L*$DMM$'-LL}}S!! Ms   Bc                 (  #    UR                  SS5      nU R                  R                  " U R                  U5      /UQ70 UD6I S h  vN nU(       a  U$ UR	                  5        VVs0 s H  u  pU R                  U5      U_M     snn$  NBs  snnf 7fNtotalT)r   r    _dur/   r.   r7   r!   r   r@   rA   r   r   r   s          r   r   DirFileSystem._duI  s|     

7D)GGKK

4 0B4B6BBJ<?IIKHKjdd#T)KHH	 C Is$   ABB
 B(BBBc                    UR                  SS5      nU R                  R                  " U R                  U5      /UQ70 UD6nU(       a  U$ UR	                  5        VVs0 s H  u  pU R                  U5      U_M     snn$ s  snnf r   )r   r    dur/   r.   r7   r   s          r   r   DirFileSystem.duQ  sm    

7D)ggjjD);D;F;J<?IIKHKjdd#T)KHHHs   B c                 F  #    UR                  SS5      nU R                  R                  " U R                  U5      /UQ70 UD6I S h  vN nU(       a5  UR	                  5        VVs0 s H  u  pU R                  U5      U_M     snn$ U R                  U5      $  NQs  snnf 7fr   )r   r    _findr/   r.   r7   r!   r   r@   rA   r   r   r   s          r   r   DirFileSystem._findY  s     He,GGMM$**T"2DTDVDD@C		L*$DMM$'-LL}}S!! ELs$   AB!BB!&BB!B!c                 *   UR                  SS5      nU R                  R                  " U R                  U5      /UQ70 UD6nU(       a5  UR	                  5        VVs0 s H  u  pU R                  U5      U_M     snn$ U R                  U5      $ s  snnf r   )r   r    findr/   r.   r7   r   s          r   r   DirFileSystem.find`  sz    He,ggll4::d+=d=f=@C		L*$DMM$'-LL}}S!! Ms   Bc                    #    U R                  U R                  R                  " U R                  U5      /UQ70 UD6I S h  vN 5      $  N7fr;   )r7   r    _expand_pathr/   rM   s       r   r   DirFileSystem._expand_pathg  sA     }}''&&tzz$'7I$I&II
 	
Is   >A A		Ac                 ~    U R                  U R                  R                  " U R                  U5      /UQ70 UD65      $ r;   )r7   r    expand_pathr/   rM   s       r   r  DirFileSystem.expand_pathl  s3    }}TWW00D1ASDSFSTTr   c                 |   #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    _mkdirr/   rM   s       r   r  DirFileSystem._mkdiro  s1     WW^^DJJt$4FtFvFFFFrO   c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    mkdirr/   rM   s       r   r  DirFileSystem.mkdirr  s(    ww}}TZZ-????r   c                 |   #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    	_makedirsr/   rM   s       r   r  DirFileSystem._makedirsu  r~   rO   c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    makedirsr/   rM   s       r   r  DirFileSystem.makedirsx  r   r   c                 V    U R                   R                  U R                  U5      5      $ r;   )r    rmdirr/   r   s     r   r  DirFileSystem.rmdir{  r   r   c                 z    U R                   R                  " U R                  U5      U R                  U5      40 UD6$ r;   )r    mvr/   rZ   s       r   r  DirFileSystem.mv~  s9    wwzzJJuJJu
 
 	
r   c                 Z    U R                   R                  " U R                  U5      40 UD6$ r;   )r    touchr/   rE   s      r   r  DirFileSystem.touch  s#    ww}}TZZ-888r   c                 V    U R                   R                  U R                  U5      5      $ r;   )r    createdr/   r   s     r   r  DirFileSystem.created  s    wwtzz$/00r   c                 V    U R                   R                  U R                  U5      5      $ r;   )r    modifiedr/   r   s     r   r  DirFileSystem.modified  s     ww

4 011r   c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    signr/   rM   s       r   r   DirFileSystem.sign  rn   r   c                 h    U R                   R                   SU R                   SU R                   S3$ )Nz(path='z', fs=))r&   __qualname__r   r    r<   s    r   __repr__DirFileSystem.__repr__  s.    ..--.gdii[twwiqQQr   c                 `    U R                   R                  " U R                  U5      /UQ70 UD6$ r;   )r    openr/   rM   s       r   r(  DirFileSystem.open  s7     ww||JJt

 
 	
r   c                 |   #    U R                   R                  " U R                  U5      /UQ70 UD6I S h  vN $  N7fr;   )r    
open_asyncr/   rM   s       r   r+  DirFileSystem.open_async  sF      WW''JJt

 
 
 	
 
rO   )r    r   )NNNNN)FN)NNN)T)K__name__
__module__r$  __firstlineno____doc__r   r   r/   r7   propertyr+   r?   rD   rI   rL   rQ   rV   rY   r_   rb   rf   ri   rl   rp   rs   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  r  r  r  r  r  r  r  r  r  r   r%  r(  r+  __static_attributes____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)
r4   r   asynr   chainedr   localr   r   r   r   r   r   <module>r7     s'     " & "
V
O%6 V
r   