
    *pj7                        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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     Y/var/www/html/pdf-tiff/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)    Nc                  ^^^^ Tb  TS:  a  [        S5      eU R                  T5      mTU R                  ;   aD  U(       d  T/$ U R                  T   nTTUR                  SUR                  R                  5       S.0$ T(       a  TS-   OSm0 n0 mUUUU4S jn[        U R                  R                  5       5       H  u  pU	R                  T5      (       d  M  U	[        T5      S  n
U(       a  U" U	5        Tb  U
R                  S5      S-   T:  a  MW  U	UR                  SUR                  R                  5       S.Xy'   M     U(       a  U R                   H/  nU(       d  M  UR                  T5      (       d  M$  U" US-   5        M1     UR                  T5        TS:w  a*  U R                  T5      (       a  U R                  T5      UT'   [        U5      nU(       a  U V	s0 s H  oXy   _M	     sn	$ U$ s  sn	f )N   zmaxdepth must be at least 1filenamesizetypecreatedr   c                  > U R                  S5      nU[        T5      :  aa  U S U nUT;   a  g U[        T5      S  nTb  UR                  S5      S-   T::  a	  USSS.TU'   UR                  S5      nU[        T5      :  a  M`  g g )Nr   r"   r   	directoryr%   r&   r'   )rfindlencount)r%   idxparentreldirsmaxdepthr   prefixs       r   add_ancestor_dirs0MemoryFileSystem.find.<locals>.add_ancestor_dirsG   s     **S/CD	/dsT>S[]+#syy~'9X'E,2A{#SDLll3' D	/r    r   )
ValueErrorr   r   r&   r(   	timestamptupleitems
startswithr-   r.   pseudo_dirsupdateisdirinfosorted)selfr   r3   withdirsdetailkwargsfilelikeoutr5   r%   r1   pdirnamesr2   r4   s    ``          @@r   findMemoryFileSystem.find+   s   
 HqL:;;##D)4::vzz$'H $MM"'//99;	   $	( 	(  $DJJ$4$4$67ND??6**s6{}%C!$'#		#(:X(E #++557	CI 8 ((4DOOF33%dSj1 ) JJt rzdjj.. IIdOD	s6<E2EDciE2G%G2s   G2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 )	Nr#   r$   r   r"   r   r*   r+   r%   )r   r   r&   r(   r8   setr9   r;   r-   appendsplitaddr<   FileNotFoundErrorr@   )
rA   r   rC   rD   pathsstarterrF   p2ppathfs
             r   lsMemoryFileSystem.lst   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   r<   FileExistsError_parentstripisfileNotADirectoryErrormkdirrM   )rA   r   create_parentsrD   s       r   r^   MemoryFileSystem.mkdir   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)r_   )r^   rY   )rA   r   exist_oks      r   makedirsMemoryFileSystem.makedirs   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)rA   r   valueri   rD   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   r<   rV   removeOSErrorr   rP   rA   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   r<   anylistr   r&   getattrrP   )rA   r   rD   rE   s    `  r   r?   MemoryFileSystem.info   s    Z&##D)4###s +
.24::.>AQAQ.Q+
 (
 (
 # 
 TZZzz$'H "8Y=	  $D))r    c                   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;   a  XR                  ;   a<  U R                  U   nSU;   a  UR                  SS5        U$ UR                  S5        U$ SU;   aP  [        XUR                  S5      5      n	U R                  (       d  U	R                  5         U	R                  S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      rj   >   rh   rg   w+bx+bzunsupported file mode for z: )r   existsrY   r<   IsADirectoryErrorr-   rZ   r\   r   seek
MemoryFileget_intranscommitrP   	__class____name__r7   )rA   r   ri   
block_size
autocommitcache_optionsrD   r0   rU   mr%   s              r   _openMemoryFileSystem._open   s    ##D)$;4;;t,,!!####D))&kAo\\&)F{{6""%f-- &kAo --zz!JJt$$;FF1aL  FF1I t6::f+=>}}HHJq!'--//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   r\   r   r   getvaluer>   r<   rM   rP   )rA   path1path2rD   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)r{   r|   r   bytesr   	getbufferKeyErrorrP   )rA   r   startendrD   es         r   cat_fileMemoryFileSystem.cat_file4  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   rP   rA   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   rP   r   s      r   r   MemoryFileSystem.modifiedC  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   rP   r   s      r   r(   MemoryFileSystem.createdJ  sI    ##D)	1::d#+++ 	1#D)q0	1r   c                @    U R                  U5      nXR                  ;   $ r   )r   r   rr   s     r   r\   MemoryFileSystem.isfileQ  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)	recursiver3   )	r   strr   expand_pathreversedr\   rm_filer   rs   )rA   r   r   r3   rx   rQ   s         r   rmMemoryFileSystem.rmU  s    dC  ''-D59:T((+TD:  X N%A{{1~~Q
 [[^^

1 ! ;s   B= )NFF)T)F)	overwrite)r   NTN)NN)FN)r   
__module____qualname____firstlineno____doc__r   __annotations__r<   protocolroot_markerclassmethodr   rI   rV   r^   rc   rm   rs   r?   r   r   r   r   r   r(   r\   r   __static_attributes__r   r    r   r   r      s     ')E#($KHK* *GHR>0@*/**2 1Lf+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$ )r   ih  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   )r{   r|   fsr   r   nowr   utcr(   r   super__init__r   )rA   r   r   rj   r   s       r   r   MemoryFile.__init__p  sc    ^T*	||x||4 5GT"IIaL r    c                6    U R                  5       R                  $ r   )r   nbytesrA   s    r   r&   MemoryFile.sizez  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.discard  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   r   MemoryFile.commit  s*    #'dii  5r    )r(   r   r   r   )NNN)r   r   r   r   r   r   propertyr&   r   r   r   r   r   __classcell__)r   s   @r   r   r   h  s:     ' '6 6r    r   )
__future__r   loggingr   r   errnor   ior   pathlibr   r	   typingr
   r   fsspecr   fsspec.implementations.localr   fsspec.utilsr   	getLoggerr{   r   r   r   r    r   <module>r      sP    "  '   -   % 8 '			,	-T) Tn
!6 !6r    