Ë
    •KêjT>  ã                  óÔ   — d dl mZ d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ  ej*                  d«      Z G d„ de«      Z G d„ de«      Zy)é    )ÚannotationsN)ÚdatetimeÚtimezone)Ú	ENOTEMPTY)ÚBytesIO)ÚPurePathÚPureWindowsPath)ÚAny)ÚAbstractFileSystem)ÚLocalFileSystem)Ústringify_pathÚtokenizezfsspec.memoryfsc                  óæ   ‡ — e Zd ZU dZi Zded<   dgZdZdZddœˆ fd	„
Z	e
ˆ fd
„«       Zˆ fd„Zed„ «       Zdd„Zdd„Zdd„Zdd„Zdd„Zd„ Zd„ Z	 	 	 	 d d„Zd„ Zd!d„Zd„ Zd„ Zd„ Zd„ Zd"d„Zˆ xZS )#ÚMemoryFileSystemzîA filesystem based on a dict of BytesIO objects

    By default, instances share a global in-memory filesystem. Pass
    ``global_store=False, skip_instance_cache=True`` to create a new instance
    with an independent store instead.
    zdict[str, Any]ÚstoreÚ Úmemoryú/T)Úglobal_storec               óV   •— t        ‰| �  |i |¤Ž || _        |si | _        dg| _        yy)a)  Create a memory filesystem.

        Parameters
        ----------
        global_store: bool
            Share files and directories with other default instances. If False,
            each instance starts with an empty, independent store. The normal
            instance cache still applies; pass ``skip_instance_cache=True``
            to create a new instance on every call. Pickling an
            independent filesystem copies its files and directories; pickling a
            global filesystem retains the reference to the global store.
        r   N)ÚsuperÚ__init__r   r   Úpseudo_dirs)Úselfr   ÚargsÚkwargsÚ	__class__s       €úb/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/fsspec/implementations/memory.pyr   zMemoryFileSystem.__init__   s8   ø€ ô 	‰Ñ˜$Ð) &Ò)Ø(ˆÔÙØˆDŒJØ "˜tˆDÕð ó    c                ój   •— | j                   r
t        ‰| �  S t        t        ‰| �  t	        | «      «      S ©N)r   r   Ú	_fs_tokenr   Úid)r   r   s    €r   r"   zMemoryFileSystem._fs_token1   s-   ø€ à×ÒÜ‘7Ñ$Ð$Üœ™Ñ)¬2¨d«8Ó4Ð4r   c                óœ   •— t         ‰| �  «       }| j                  r|S |\  }\  }}}i |¥ddi¥}||||f| j                  | j                  dœfS )NÚskip_instance_cacheT)r   r   )r   Ú
__reduce__r   r   r   )r   ÚreducedÚfactoryÚclsr   r   r   s         €r   r&   zMemoryFileSystem.__reduce__7   sl   ø€ Ü‘'Ñ$Ó&ˆØ×ÒØˆNØ'.Ñ$ˆÑ$�#�t˜Và8�FÐ8Ð1°4Ñ8ˆð Ø�$˜ÐØ—j‘j°×1AÑ1AÑBð
ð 	
r   c                ó(  — t        |t        «      r0t        |t        «      rt        j                  |«      S t        |«      }|j                  d«      }d|v sd|v r|j                  d«      S |j                  d«      j                  d«      }|rd|z   S dS )Nz	memory://z::z://r   r   )	Ú
isinstancer   r	   r   Ú_strip_protocolr   ÚremoveprefixÚrstripÚlstrip)r)   Úpaths     r   r,   z MemoryFileSystem._strip_protocolE   s‡   € ä�dœHÔ%Ü˜$¤Ô0Ü&×6Ñ6°tÓ<Ð<ä% dÓ+�à× Ñ  Ó-ˆØ�4‰<˜5 D™=Ø—;‘;˜sÓ#Ð#Ø�{‰{˜3Ó×&Ñ& sÓ+ˆÙ!ˆs�T‰zÐ) rÐ)r   c                óv  ‡‡‡‡— ‰�‰dk  rt        d«      ‚| j                  ‰«      Š‰| j                  v r?|s‰gS | j                  ‰   }‰‰|j                  d|j                  j                  «       dœiS ‰r‰dz   ndŠi }i Šˆˆˆˆfd„}t        | j                  j                  «       «      D ]u  \  }	}|	j                  ‰«      sŒ|	t        ‰«      d  }
|r ||	«       ‰�|
j                  d«      dz   ‰kD  rŒJ|	|j                  d|j                  j                  «       dœ||	<   Œw |rl| j                  D ]"  }|sŒ|j                  ‰«      sŒ ||dz   «       Œ$ |j                  ‰«       ‰dk7  r%| j                  ‰«      r| j                  ‰«      |‰<   t        |«      }|r|D �	ci c]  }	|	||	   “Œ
 c}	S |S c c}	w )Né   zmaxdepth must be at least 1Úfile©ÚnameÚsizeÚtypeÚcreatedr   c                óú   •— | j                  d«      }|t        ‰«      kD  r[| d | }|‰v ry |t        ‰«      d  }‰�|j                  d«      dz   ‰k  r	|dddœ‰|<   |j                  d«      }|t        ‰«      kD  rŒZy y )Nr   r2   r   Ú	directory©r5   r6   r7   )ÚrfindÚlenÚcount)r5   ÚidxÚparentÚrelÚdirsÚmaxdepthr0   Úprefixs       €€€€r   Úadd_ancestor_dirsz0MemoryFileSystem.find.<locals>.add_ancestor_dirso   s‡   ø€ ð —*‘*˜S“/ˆCØœ˜D›	’/Ø˜d˜s˜�Ø˜T‘>ØØœS ›[˜]Ð+�ØÐ# s§y¡y°£~¸Ñ'9¸XÒ'EØ,2¸AÀ{Ñ#S�D˜‘LØ—l‘l 3Ó'�ð œ˜D›	•/r   r   )Ú
ValueErrorr,   r   r6   r8   Ú	timestampÚtupleÚitemsÚ
startswithr=   r>   r   ÚupdateÚisdirÚinfoÚsorted)r   r0   rC   ÚwithdirsÚdetailr   ÚfilelikeÚoutrE   r5   rA   ÚpdirÚnamesrB   rD   s    ``          @@r   ÚfindzMemoryFileSystem.findS   sË  û€ ð
 Ð H¨q¢LÜÐ:Ó;Ð;Ø×#Ñ# DÓ)ˆØ�4—:‘:ÑáØ�v�Ø—z‘z $Ñ'ˆHàØ Ø$ŸM™MØ"Ø'×/Ñ/×9Ñ9Ó;ñ	ðð ñ  $�˜’¨ˆØˆØˆ÷	(ô  $ D§J¡J×$4Ñ$4Ó$6Ó7ò 	‰NˆD�(Ø—?‘? 6Ô*ØØ”s˜6“{�}Ð%ˆCÙÙ! $Ô'ØÐ#¨¯	©	°#«¸Ñ(:¸XÒ(EØàØ Ÿ™ØØ#×+Ñ+×5Ñ5Ó7ñ	ˆC�ŠIð	ñ à×(Ñ(ò 2�Ú˜DŸO™O¨FÕ3Ù% d¨S¡jÕ1ð2ð �J‰J�tÔð �rŠz˜dŸj™j¨Ô.Ø ŸI™I d›O��D‘	ä�s“ˆÙ6<¨EÖ2 D��c˜$‘i‘Ò2ÐGÀ%ÐGùÒ2s   Æ$F6c                óÌ  — | j                  |«      }|| j                  v rI|s|gS || j                  |   j                  d| j                  |   j                  j	                  «       dœgS t        «       }|dz   }g }t        | j                  «      D ]ä  }|j                  |«      sŒd|t        |«      d  vrS|j                  || j                  |   j                  d| j                  |   j                  j	                  «       dœ«       Œxt        |«      t        |«      kD  sŒ�||t        |«      d  j                  dd«      d   z   }||vsŒ¹|xs g }|j                  |dddœ«       |j                  |«       Œæ | j                  D ]Ÿ  }|j                  |«      sŒd|t        |«      d  vr,||vsŒ*|j                  |dddœ«       |j                  |«       ŒQ||t        |«      d  j                  dd«      d   z   }||vsŒz|j                  |dddœ«       |j                  |«       Œ¡ |s|| j                  v rg S t        |«      ‚|r|S t        |D �	cg c]  }	|	d   ‘Œ	 c}	«      S c c}	w )	Nr3   r4   r   r2   r   r:   r;   r5   )r,   r   r6   r8   rG   ÚsetrH   rJ   r=   ÚappendÚsplitÚaddr   ÚFileNotFoundErrorrN   )
r   r0   rP   r   ÚpathsÚstarterrR   Úp2ÚppathÚfs
             r   ÚlszMemoryFileSystem.lsœ   sa  € Ø×#Ñ# DÓ)ˆØ�4—:‘:ÑáØ�v�ð !Ø ŸJ™J tÑ,×1Ñ1Ø"Ø#Ÿz™z¨$Ñ/×7Ñ7×AÑAÓCñ	ðð ô “ˆØ˜‘*ˆØˆÜ˜Ÿ
™
Ó#ò 	)ˆBØ�}‰}˜WÕ%Ø˜b¤ W£ Ð0Ñ0à—J‘Jà$&Ø$(§J¡J¨r¡N×$7Ñ$7Ø$*Ø'+§z¡z°"¡~×'=Ñ'=×'GÑ'GÓ'Iñ	õô ˜“Wœs 7›|Ó+à# b¬¨W«¨Ð&8×&>Ñ&>¸sÀAÓ&FÀqÑ&IÑI�EØ EÒ)Ø!ši R˜ØŸ
™
à(-Ø()Ø(3ñôð Ÿ	™	 %Õ(ð1	)ð2 ×"Ñ"ò 	)ˆBØ�}‰}˜WÕ%Ø˜b¤ W£ Ð0Ñ0à ’ØŸ
™
¨B¸À;Ñ#OÔPØŸ	™	 "�ð $ b¬¨W«¨Ð&8×&>Ñ&>¸sÀAÓ&FÀqÑ&IÑI�EØ EÒ)ØŸ
™
¨E¸1ÀkÑ#RÔSØŸ	™	 %Õ(ð	)ñ Ø�t×'Ñ'Ñ'à�	Ü# DÓ)Ð)ÙØˆJÜ¨#Ö. Q�q˜“yÒ.Ó/Ð/ùÒ.s   ÉI!c                ó,  — | j                  |«      }|| j                  v s|| j                  v rt        |«      ‚| j	                  |«      j                  d«      r:| j                  | j	                  |«      «      rt        | j	                  |«      «      ‚|rD| j	                  |«      j                  d«      r$	  | j                  | j	                  |«      |fi |¤Ž |r+|| j                  vr| j                  j                  |«       y y y # t        $ r Y Œ9w xY w)Nr   )
r,   r   r   ÚFileExistsErrorÚ_parentÚstripÚisfileÚNotADirectoryErrorÚmkdirrX   )r   r0   Úcreate_parentsr   s       r   rh   zMemoryFileSystem.mkdirÜ   sò   € Ø×#Ñ# DÓ)ˆØ�4—:‘:Ñ ¨×)9Ñ)9Ñ!9Ü! $Ó'Ð'Ø�<‰<˜Ó×#Ñ# CÔ(¨T¯[©[¸¿¹ÀdÓ9KÔ-LÜ$ T§\¡\°$Ó%7Ó8Ð8Ù˜dŸl™l¨4Ó0×6Ñ6°sÔ;ðØ�—
‘
˜4Ÿ<™<¨Ó-¨~ÑHÀÒHñ �D × 0Ñ 0Ñ0Ø×Ñ×#Ñ# DÕ)ð 1ˆ4øô #ò Ùðús   Â6#D Ä	DÄDc                óP   — 	 | j                  |d¬«       y # t        $ r |s‚ Y y w xY w)NT)ri   )rh   rc   )r   r0   Úexist_oks      r   ÚmakedirszMemoryFileSystem.makedirsê   s1   € ð	Ø�J‰J�t¨DˆJÕ1øÜò 	ÙØñ ð	ús   ‚ –%¤%c                ó>   — |dk(  rdnd}| j                  |||¬«       y)zSSet the bytes of given file

        Avoids copies of the data if possible
        ÚcreateÚxbÚwb)ÚmodeÚdataN)Úopen)r   r0   Úvaluerq   r   s        r   Ú	pipe_filezMemoryFileSystem.pipe_fileñ   s$   € ð
 ˜xÒ'‰t¨TˆØ�	‰	�$˜T¨ˆ	Õ.r   c                óÞ   — | j                  |«      }|dk(  ry || j                  v r>| j                  |«      s| j                  j                  |«       y t	        t
        d|«      ‚t        |«      ‚)Nr   zDirectory not empty)r,   r   ra   ÚremoveÚOSErrorr   r[   ©r   r0   s     r   ÚrmdirzMemoryFileSystem.rmdirù   sd   € Ø×#Ñ# DÓ)ˆØ�2Š:àØ�4×#Ñ#Ñ#Ø—7‘7˜4”=Ø× Ñ ×'Ñ'¨Õ-äœiÐ)>ÀÓEÐEä# DÓ)Ð)r   c                ój  ‡— t         j                  d‰«       | j                  ‰«      Š‰| j                  v s4t	        ˆfd„t        | j                  «      | j                  z   D «       «      r‰dddœS ‰| j                  v r+| j                  ‰   }‰|j                  dt        |dd «      dœS t        ‰«      ‚)	Nzinfo: %sc              3  óF   •K  — | ]  }|j                  ‰d z   «      –— Œ y­w)r   N)rJ   )Ú.0Úpr0   s     €r   ú	<genexpr>z(MemoryFileSystem.info.<locals>.<genexpr>	  s#   øè ø€ ò +
Ø)*ˆA�L‰L˜ ™×$ñ+
ùs   ƒ!r   r:   r;   r3   r8   r4   )
ÚloggerÚdebugr,   r   ÚanyÚlistr   r6   Úgetattrr[   )r   r0   r   rQ   s    `  r   rM   zMemoryFileSystem.info  s¸   ø€ Ü�‰�Z Ô&Ø×#Ñ# DÓ)ˆØ�4×#Ñ#Ñ#¤só +
Ü.2°4·:±:Ó.>À×AQÑAQÑ.Qô+
ô (
ð ØØ#ñð ð
 �T—Z‘ZÑØ—z‘z $Ñ'ˆHàØ Ÿ™ØÜ" 8¨Y¸Ó=ñ	ð ô $ DÓ)Ð)r   c                ór  — | j                  |«      }d|v r| j                  |«      rt        ‚|| j                  v rt	        |«      ‚|}t        |«      dkD  r<| j                  |«      }| j                  |«      rt        |«      ‚t        |«      dkD  rŒ<|dv r£|| j                  v r:| j                  |   }d|v r|j                  dd«       |S |j                  d«       |S d|v rLt        | ||j                  d«      «      }	| j                  s|	j                  «        |	j                  dd«       |	S t        |«      ‚|dv rUd|v r| j                  |«      rt        ‚t        | ||j                  d«      «      }	| j                  s|	j                  «        |	S | j                  j                   }
t#        d	|
› d
|›�«      ‚)NÚxr2   )ÚrbÚabzr+bza+bÚar   é   rr   >   úw+búx+brp   ro   zunsupported file mode for z: )r,   Úexistsrc   r   ÚIsADirectoryErrorr=   rd   rf   r   ÚseekÚ
MemoryFileÚgetÚ_intransÚcommitr[   r   Ú__name__rF   )r   r0   rq   Ú
block_sizeÚ
autocommitÚcache_optionsr   r@   r`   Úmr5   s              r   Ú_openzMemoryFileSystem._open  s›  € ð ×#Ñ# DÓ)ˆØ�$‰;˜4Ÿ;™; tÔ,Ü!Ð!Ø�4×#Ñ#Ñ#Ü# DÓ)Ð)ØˆÜ�&‹k˜AŠoØ—\‘\ &Ó)ˆFØ�{‰{˜6Ô"Ü% fÓ-Ð-ô �&‹k˜A‹oð Ð-Ñ-Ø�t—z‘zÑ!Ø—J‘J˜tÑ$�Ø˜$‘;à—F‘F˜1˜a”Lð �ð —F‘F˜1”IØ�Ø˜‘ô ˜t T¨6¯:©:°fÓ+=Ó>�Ø—}’}Ø—H‘H”Jà—‘�q˜!”Ø�ä'¨Ó-Ð-ØÐ/Ñ/Ø�d‰{˜tŸ{™{¨4Ô0Ü%Ð%Ü˜4  v§z¡z°&Ó'9Ó:ˆAØ—=’=Ø—‘”
ØˆHà—>‘>×*Ñ*ˆDÜÐ9¸$¸¸rÀ$ÀÐJÓKÐKr   c                ób  — | j                  |«      }| j                  |«      }| j                  |«      r6t        | || j                  |   j	                  «       «      | j                  |<   y | j                  |«      r+|| j                  vr| j                  j                  |«       y y t        |«      ‚r!   )	r,   rf   r�   r   ÚgetvaluerL   r   rX   r[   )r   Úpath1Úpath2r   s       r   Úcp_filezMemoryFileSystem.cp_fileO  sœ   € Ø×$Ñ$ UÓ+ˆØ×$Ñ$ UÓ+ˆØ�;‰;�uÔÜ *Ø�e˜TŸZ™Z¨Ñ.×7Ñ7Ó9ó!ˆD�J‰J�uÒð �Z‰Z˜ÔØ˜D×,Ñ,Ñ,Ø× Ñ ×'Ñ'¨Õ.ð -ô $ EÓ*Ð*r   c                óÞ   — t         j                  d|«       | j                  |«      }	 t        | j                  |   j                  «       || «      S # t        $ r}t        |«      |‚d }~ww xY w)Nzcat: %s)r€   r�   r,   Úbytesr   Ú	getbufferÚKeyErrorr[   )r   r0   ÚstartÚendr   Úes         r   Úcat_filezMemoryFileSystem.cat_file\  sf   € Ü�‰�Y Ô%Ø×#Ñ# DÓ)ˆð	1Ü˜Ÿ™ DÑ)×3Ñ3Ó5°e¸CÐ@ÓAÐAøÜò 	1Ü# DÓ)¨qÐ0ûð	1ús   ©(A Á	A,ÁA'Á'A,c                ó|   — | j                  |«      }	 | j                  |= y # t        $ r}t        |«      |‚d }~ww xY wr!   )r,   r   r¢   r[   ©r   r0   r¥   s      r   Ú_rmzMemoryFileSystem._rmd  s@   € Ø×#Ñ# DÓ)ˆð	1Ø—
‘
˜4Ñ øÜò 	1Ü# DÓ)¨qÐ0ûð	1ús   “! ¡	;ª6¶;c                ó’   — | j                  |«      }	 | j                  |   j                  S # t        $ r}t	        |«      |‚d }~ww xY wr!   )r,   r   Úmodifiedr¢   r[   r¨   s      r   r«   zMemoryFileSystem.modifiedk  sI   € Ø×#Ñ# DÓ)ˆð	1Ø—:‘:˜dÑ#×,Ñ,Ð,øÜò 	1Ü# DÓ)¨qÐ0ûð	1úó   “, ¬	AµAÁAc                ó’   — | j                  |«      }	 | j                  |   j                  S # t        $ r}t	        |«      |‚d }~ww xY wr!   )r,   r   r8   r¢   r[   r¨   s      r   r8   zMemoryFileSystem.createdr  sI   € Ø×#Ñ# DÓ)ˆð	1Ø—:‘:˜dÑ#×+Ñ+Ð+øÜò 	1Ü# DÓ)¨qÐ0ûð	1úr¬   c                ó@   — | j                  |«      }|| j                  v S r!   )r,   r   ry   s     r   rf   zMemoryFileSystem.isfiley  s!   € Ø×#Ñ# DÓ)ˆØ�t—z‘zÐ!Ð!r   c                óÌ  — t        |t        «      r| j                  |«      }n|D �cg c]  }| j                  |«      ‘Œ }}| j                  |||¬«      }|D �ch c]  }| j	                  |«      sŒ|’Œ }}t        |«      D ]W  }| j                  |«      r| j                  |«       Œ&| j	                  |«      s||vrt        |«      ‚ŒG| j                  |«       ŒY y c c}w c c}w )N)Ú	recursiverC   )
r+   Ústrr,   Úexpand_pathr�   Úreversedrf   Úrm_filer[   rz   )r   r0   r°   rC   r~   r\   Úexisteds          r   ÚrmzMemoryFileSystem.rm}  sÑ   € Ü�dœCÔ Ø×'Ñ'¨Ó-‰Dà59Ö:°�D×(Ñ(¨Õ+Ð:ˆDÐ:Ø× Ñ  °ÀXÐ ÓNˆð $Ö6˜ t§{¡{°1¥~’1Ð6ˆÐ6Ü˜%“ò 	ˆAØ�{‰{˜1Œ~Ø—‘˜Q•Ø—[‘[ ”^ð
 ˜GÑ#Ü+¨AÓ.Ð.Øà—
‘
˜1•ñ	ùò ;ùò 7s   §CÁC!Á0C!)NFF)T)F)Ú	overwrite)r‡   NTN)NN)FN)r”   Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   ÚprotocolÚroot_markerr   Úpropertyr"   r&   Úclassmethodr,   rU   ra   rh   rl   ru   rz   rM   r™   rž   r¦   r©   r«   r8   rf   r¶   Ú__classcell__©r   s   @r   r   r      s¹   ø… ñð €Eˆ>ÓØ�$€KØ€HØ€Kà+/ö $ð& ó5ó ð5ô

ð ñ*ó ð*óGHóR>0ó@*óó/ò*ò*ð2 ØØØó1Lòf+ó1ò1ò1ò1ò"÷r   r   c                  óL   ‡ — e Zd ZdZdˆ fd„	Zed„ «       Zd„ Zd„ Zd„ Z	d„ Z
ˆ xZS )	r�   zÐA 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                ó8  •— t         j                  d|«       || _        || _        t	        j
                  t        j                  ¬«      | _        t	        j
                  t        j                  ¬«      | _	        |r!t        ‰| �-  |«       | j                  d«       y y )Nzopen file %s©Útzr   )r€   r�   Úfsr0   r   Únowr   Úutcr8   r«   r   r   r�   )r   rÆ   r0   rr   r   s       €r   r   zMemoryFile.__init__�  sg   ø€ Ü�‰�^ TÔ*ØˆŒØˆŒ	Ü—|‘|¤x§|¡|Ô4ˆŒÜ Ÿ™¬¯©Ô5ˆŒÙÜ‰GÑ˜TÔ"Ø�I‰I�a�Lð r   c                ó6   — | j                  «       j                  S r!   )r¡   Únbytes©r   s    r   r6   zMemoryFile.size§  s   € à�~‰~Ó×&Ñ&Ð&r   c                ó   — | S r!   © rË   s    r   Ú	__enter__zMemoryFile.__enter__«  s   € Øˆr   c                 ó   — y r!   rÍ   rË   s    r   ÚclosezMemoryFile.close®  ó   € Ør   c                 ó   — y r!   rÍ   rË   s    r   ÚdiscardzMemoryFile.discard±  rÑ   r   c                óœ   — | | j                   j                  | j                  <   t        j                  t
        j                  ¬«      | _        y )NrÄ   )rÆ   r   r0   r   rÇ   r   rÈ   r«   rË   s    r   r“   zMemoryFile.commit´  s,   € Ø#'ˆ�‰�‰�d—i‘iÑ Ü Ÿ™¬¯©Ô5ˆ�r   )NNN)r”   r¸   r¹   rº   r   r¾   r6   rÎ   rÐ   rÓ   r“   rÀ   rÁ   s   @r   r�   r�   •  s5   ø„ ñõð ñ'ó ð'òòòö6r   r�   )Ú
__future__r   Úloggingr   r   Úerrnor   Úior   Úpathlibr   r	   Útypingr
   Úfsspecr   Úfsspec.implementations.localr   Úfsspec.utilsr   r   Ú	getLoggerr€   r   r�   rÍ   r   r   ú<module>rß      sR   ðÝ "ã ß 'Ý Ý ß -Ý å %Ý 8ß 1à	ˆ×	Ñ	Ð,Ó	-€ôAÐ)ô AôH!6�õ !6r   