
    7Th)                        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                v   [        U[        5      (       a6  [        U[        5      (       a  [        R                  " U5      $ [        U5      nUR                  S5      (       a  U[        S5      S  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   
startswithlenrstriplstrip)clspaths     U/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/implementations/memory.pyr    MemoryFileSystem._strip_protocol   s    dH%%$00&66t<<%d+??;''K(*+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tupler   r   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   r2   FileExistsError_parentstripisfileNotADirectoryErrormkdirr/   )r5   r   create_parentsr7   s       r   rF   MemoryFileSystem.mkdirl   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)rG   )rF   rA   )r5   r   exist_oks      r   makedirsMemoryFileSystem.makedirsz   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)r5   r   valuerQ   r7   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   r2   r>   removeOSErrorr   r3   r5   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   r2   anylistr   r&   getattrr3   )r5   r   r7   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US:X  a  UR                  SS5        U$ UR                  S5        U$ [        U5      eUS;   a`  US:X  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+brn   r      >   rP   rO   rO   rR   zunsupported file mode for z: )r   existsrA   r2   IsADirectoryErrorr   rB   rD   r   seekr3   
MemoryFileget_intranscommit	__class____name__
ValueError)r5   r   rQ   
block_size
autocommitcache_optionsr7   parentr=   mr%   s              r   _openMemoryFileSystem._open   s[    ##D)$;4;;t,,!!####D))&kAo\\&)F{{6""%f-- &kAo &&zz!JJt$4<FF1aL  FF1I'--\!t|D 1 1%%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   rD   rs   r   getvalueisdirr2   r/   r3   )r5   path1path2r7   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)rc   rd   r   bytesr   	getbufferKeyErrorr3   )r5   r   startendr7   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   r3   r5   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   r3   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   r3   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   rZ   s     r   rD   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reversedrD   rm_filerp   r[   )r5   r   r   r   r`   r8   s         r   rmMemoryFileSystem.rm  s    dC  ''-D59:T((+TD:  X N%A{{1~~Q
 [[^^

1 ! ;s   B= )T)F)	overwrite)rm   NTN)NN)FN)rx   
__module____qualname____firstlineno____doc__r   __annotations__r2   protocolroot_markerclassmethodr   r>   rF   rK   rU   r[   ri   r   r   r   r   r   r(   rD   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$ )rs   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   )rc   rd   fsr   r   nowr   utcr(   r   super__init__rr   )r5   r   r   rR   rw   s       r   r   MemoryFile.__init__  sc    ^T*	||x||4 5GT"IIaL r!   c                6    U R                  5       R                  $ r   )r   nbytesr5   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.close0      r!   c                    g r   r   r   s    r   discardMemoryFile.discard3  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   rv   MemoryFile.commit6  s*    #'dii  5r!   )r(   r   r   r   )NNN)rx   r   r   r   r   r   propertyr&   r   r   r   rv   r   __classcell__)rw   s   @r   rs   rs     s:     ' '6 6r!   rs   )
__future__r   loggingr   r   errnor   ior   pathlibr   r	   typingr
   r   fsspecr   fsspec.implementations.localr   fsspec.utilsr   	getLoggerrc   r   rs   r   r!   r   <module>r      sP    "  '   -   % 8 '			,	-C) CL!6 !6r!   