
    9i)                        S SK Jr  S SK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  S SKJrJr  S SKJr  S S	KJr  S S
KJr  \R*                  " S5      r " S S\5      r " S S\5      rg)    )annotationsN)datetimetimezone)	ENOTEMPTY)BytesIO)PurePathPureWindowsPath)AnyClassVar)AbstractFileSystem)LocalFileSystem)stringify_pathzfsspec.memoryfsc                      \ rS rSr% Sr0 rS\S'   S/rSrSr	\
S 5       rSS	 jrSS
 jrSS jrSS jrS rS r    SS jrS rSS jrS rS rS rS rSS jrSrg)MemoryFileSystem   zA filesystem based on a dict of BytesIO objects

This is a global filesystem so instances of this class all point to the same
in memory filesystem.
zClassVar[dict[str, Any]]store memory/c                P   [        U[        5      (       a6  [        U[        5      (       a  [        R                  " U5      $ [        U5      nUR                  S5      nSU;   d  SU;   a  UR                  S5      $ UR                  S5      R                  S5      nU(       a  SU-   $ S$ )Nz	memory://z::z://r   r   )	
isinstancer   r	   r   _strip_protocolr   removeprefixrstriplstrip)clspaths     ]/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/fsspec/implementations/memory.pyr    MemoryFileSystem._strip_protocol   s    dH%%$00&66t<<%d+  -4<5D=;;s##{{3&&s+!sTz)r)    c                4   U R                  U5      nXR                  ;   aN  U(       d  U/$ UU R                  U   R                  SU R                  U   R                  R	                  5       S./$ [        5       nUS-   n/ n[        U R                  5       H  nUR                  U5      (       d  M  SU[        U5      S  ;  aT  UR                  UU R                  U   R                  SU R                  U   R                  R	                  5       S.5        M  [        U5      [        U5      :  d  M  XW[        U5      S  R                  SS5      S   -   nX;  d  M  U=(       d    / nUR                  USSS.5        UR                  U5        M     U R                   H  nUR                  U5      (       d  M  SU[        U5      S  ;  a/  Xt;  a(  UR                  USSS.5        UR                  U5        MZ  M\  XW[        U5      S  R                  SS5      S   -   nX;  d  M  UR                  USSS.5        UR                  U5        M     U(       d  XR                  ;   a  / $ [        U5      eU(       a  U$ [        U V	s/ s H  oS   PM	     sn	5      $ s  sn	f )	Nfilenamesizetypecreatedr      r   	directoryr$   r%   r&   r$   )r   r   r%   r'   	timestampsettuple
startswithlenappendsplitaddpseudo_dirsFileNotFoundErrorsorted)
selfr   detailkwargspathsstarteroutp2ppathfs
             r   lsMemoryFileSystem.ls+   sV   ##D)::v ! JJt,11"#zz$/77AAC	  *

#B}}W%%bW00JJ$&$(JJrN$7$7$*'+zz"~'='='G'G'I	 Ws7|+#W&8&>&>sA&Fq&IIE)!iR

(-()(3 		%(1 $2 ""B}}W%%bW00

B;#OP		" '
 $W&8&>&>sA&Fq&IIE)

E1k#RS		%( # '''	#D))J#.#Qy#.//.s    Jc                f   U R                  U5      nXR                  ;   d  XR                  ;   a  [        U5      eU R	                  U5      R                  S5      (       a?  U R                  U R	                  U5      5      (       a  [        U R	                  U5      5      eU(       aI  U R	                  U5      R                  S5      (       a$   U R                  " U R	                  U5      U40 UD6  U(       a,  XR                  ;  a  U R                  R                  U5        g g g ! [         a     N@f = f)Nr   )
r   r   r3   FileExistsError_parentstripisfileNotADirectoryErrormkdirr0   )r6   r   create_parentsr8   s       r   rG   MemoryFileSystem.mkdirk   s    ##D)::)9)9!9!$''<<##C((T[[d9K-L-L$T\\$%788dll4066s;;

4<<-~HH D 0 00##D) 14 # s   #D# #
D0/D0c                V     U R                  USS9  g ! [         a    U(       d  e  g f = f)NT)rH   )rG   rB   )r6   r   exist_oks      r   makedirsMemoryFileSystem.makedirsy   s1    	JJtDJ1 	 	s    ((c                8    US:X  a  SOSnU R                  XUS9  g)zCSet the bytes of given file

Avoids copies of the data if possible
createxbwb)modedataN)open)r6   r   valuerR   r8   s        r   	pipe_fileMemoryFileSystem.pipe_file   s"    
 x'tT		$	.r    c                    U R                  U5      nUS:X  a  g XR                  ;   aC  U R                  U5      (       d  U R                  R                  U5        g [	        [
        SU5      e[        U5      e)Nr   zDirectory not empty)r   r3   r?   removeOSErrorr   r4   r6   r   s     r   rmdirMemoryFileSystem.rmdir   sd    ##D)2:###774==  ''-i)>EE#D))r    c                ~  ^ [         R                  ST5        U R                  T5      mTU R                  ;   d:  [	        U4S j[        U R                  5      U R                  -    5       5      (       a  TSSS.$ TU R                  ;   a+  U R                  T   nTUR                  S[        USS 5      S.$ [        T5      e)	Nzinfo: %sc              3  J   >#    U  H  oR                  TS -   5      v   M     g7f)r   N)r.   ).0pr   s     r   	<genexpr>(MemoryFileSystem.info.<locals>.<genexpr>   s#      +
.QLL$$.Qs    #r   r)   r*   r"   r'   r#   )
loggerdebugr   r3   anylistr   r%   getattrr4   )r6   r   r8   filelikes    `  r   infoMemoryFileSystem.info   s    Z&##D)4###s +
.24::.>AQAQ.Q+
 (
 (
 # 
 TZZzz$'H "8Y=	  $D))r    Nc                   U R                  U5      nSU;   a  U R                  U5      (       a  [        eXR                  ;   a  [	        U5      eUn[        U5      S:  aC  U R                  U5      nU R                  U5      (       a  [        U5      e[        U5      S:  a  MC  US;   aV  XR                  ;   a<  U R                  U   nSU;   a  UR                  SS5        U$ UR                  S5        U$ [        U5      eUS;   a`  SU;   a  U R                  U5      (       a  [        e[        XUR                  S5      5      n	U R                  (       d  U	R                  5         U	$ U R                  R                   n
[#        S	U
 S
U< 35      e)Nxr(   )rbabzr+bza+bar      >   rQ   rP   w+bx+brS   zunsupported file mode for z: )r   existsrB   r3   IsADirectoryErrorr/   rC   rE   r   seekr4   
MemoryFileget_intranscommit	__class____name__
ValueError)r6   r   rR   
block_size
autocommitcache_optionsr8   parentr>   mr$   s              r   _openMemoryFileSystem._open   s\    ##D)$;4;;t,,!!####D))&kAo\\&)F{{6""%f-- &kAo --zz!JJt$$;FF1aL  FF1I'--//d{t{{400%%4vzz&'9:A==
H>>**D9$r$JKKr    c                v   U R                  U5      nU R                  U5      nU R                  U5      (       a5  [        XU R                  U   R	                  5       5      U R                  U'   g U R                  U5      (       a,  X R                  ;  a  U R                  R                  U5        g g [        U5      eN)	r   rE   rw   r   getvalueisdirr3   r0   r4   )r6   path1path2r8   s       r   cp_fileMemoryFileSystem.cp_file   s    $$U+$$U+;;u *TZZ.779!DJJu ZZ,,,  ''. - $E**r    c                    [         R                  SU5        U R                  U5      n [        U R                  U   R                  5       X# 5      $ ! [         a  n[        U5      UeS nAff = f)Nzcat: %s)rd   re   r   bytesr   	getbufferKeyErrorr4   )r6   r   startendr8   es         r   cat_fileMemoryFileSystem.cat_file   sd    Y%##D)	1D)335e@AA 	1#D)q0	1s   'A 
A,A''A,c                ~    U R                  U5      n U R                  U	 g ! [         a  n[        U5      UeS nAff = fr   )r   r   r   r4   r6   r   r   s      r   _rmMemoryFileSystem._rm   s@    ##D)	1

4  	1#D)q0	1s   ! 
<7<c                    U R                  U5      n U R                  U   R                  $ ! [         a  n[	        U5      UeS nAff = fr   )r   r   modifiedr   r4   r   s      r   r   MemoryFileSystem.modified   sI    ##D)	1::d#,,, 	1#D)q0	1   , 
AAAc                    U R                  U5      n U R                  U   R                  $ ! [         a  n[	        U5      UeS nAff = fr   )r   r   r'   r   r4   r   s      r   r'   MemoryFileSystem.created   sI    ##D)	1::d#+++ 	1#D)q0	1r   c                @    U R                  U5      nXR                  ;   $ r   )r   r   r[   s     r   rE   MemoryFileSystem.isfile   s    ##D)zz!!r    c                   [        U[        5      (       a  U R                  U5      nO U Vs/ s H  o@R                  U5      PM     nnU R                  XUS9n[	        U5       HU  nU R                  U5      (       a  U R                  U5        M,  U R                  U5      (       d  MD  U R                  U5        MW     g s  snf )N)	recursivemaxdepth)	r   strr   expand_pathreversedrE   rm_filert   r\   )r6   r   r   r   ra   r9   s         r   rmMemoryFileSystem.rm  s    dC  ''-D59:T((+TD:  X N%A{{1~~Q
 [[^^

1 ! ;s   B= )T)F)	overwrite)rn   NTN)NN)FN)r|   
__module____qualname____firstlineno____doc__r   __annotations__r3   protocolroot_markerclassmethodr   r?   rG   rL   rV   r\   rj   r   r   r   r   r   r'   rE   r   __static_attributes__r   r    r   r   r      s     ')E#($KHK* *>0@*/**2 (LT+1111"r    r   c                  X   ^  \ rS rSrSrS
U 4S jjr\S 5       rS rS r	S r
S rS	rU =r$ )rw   i  zA BytesIO which can't close and works as a context manager

Can initialise with data. Each path should only be active once at any moment.

No need to provide fs, path if auto-committing (default)
c                6  > [         R                  SU5        Xl        X l        [        R
                  " [        R                  S9U l        [        R
                  " [        R                  S9U l	        U(       a!  [        TU ]-  U5        U R                  S5        g g )Nzopen file %stzr   )rd   re   fsr   r   nowr   utcr'   r   super__init__rv   )r6   r   r   rS   r{   s       r   r   MemoryFile.__init__  sc    ^T*	||x||4 5GT"IIaL r    c                6    U R                  5       R                  $ r   )r   nbytesr6   s    r   r%   MemoryFile.size(  s    ~~&&&r    c                    U $ r   r   r   s    r   	__enter__MemoryFile.__enter__,  s    r    c                    g r   r   r   s    r   closeMemoryFile.close/      r    c                    g r   r   r   s    r   discardMemoryFile.discard2  r   r    c                    X R                   R                  U R                  '   [        R                  " [
        R                  S9U l        g )Nr   )r   r   r   r   r   r   r   r   r   s    r   rz   MemoryFile.commit5  s*    #'dii  5r    )r'   r   r   r   )NNN)r|   r   r   r   r   r   propertyr%   r   r   r   rz   r   __classcell__)r{   s   @r   rw   rw     s:     ' '6 6r    rw   )
__future__r   loggingr   r   errnor   ior   pathlibr   r	   typingr
   r   fsspecr   fsspec.implementations.localr   fsspec.utilsr   	getLoggerrd   r   rw   r   r    r   <module>r      sP    "  '   -   % 8 '			,	-B) BJ!6 !6r    