Ë
    7;hè  ã                   ó    — d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ dd„Zd„ Zd	„ Zd
„ Ze	 G d„ de«      «       Zd„ Zy)zõ
%store magic for lightweight persistence.

Stores variables, aliases and macros in IPython's database.

To automatically restore stored variables at startup, add this to your
:file:`ipython_config.py` file::

  c.StoreMagics.autorestore = True
é    N)Ú
UsageError)ÚMagicsÚmagics_classÚ
line_magic)Úskip_doctest)ÚBoolc                 óè   — | j                   j                  di «      }|€5|j                  «       D ]!  \  }}| j                  j	                  ||«       Œ# y | j                  j	                  |||   «       y )NÚstored_aliases)ÚdbÚgetÚitemsÚalias_managerÚdefine_alias)ÚipÚaliasÚ	staliasesÚkÚvs        ún/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/IPython/extensions/storemagic.pyÚrestore_aliasesr      sf   € Ø—‘—	‘	Ð*¨BÓ/€IØ€}Ø—?‘?Ö$‰CˆAˆað ×Ñ×)Ñ)¨!¨AÕ.ñ %ð
 	×Ñ×%Ñ% e¨Y°uÑ-=Õ>ó    c                 ó,  — | j                   }|j                  d«      D ]6  }t        j                  j	                  |«      }	 ||   }|| j
                  |<   Œ8 y # t        $ r2 t        d|z  «       t        dt        j                  «       d   «       Y Œtw xY w)Núautorestore/*zEUnable to restore variable '%s', ignoring (use %%store -d to forget!)zThe error was:r   )
r   ÚkeysÚosÚpathÚbasenameÚuser_nsÚKeyErrorÚprintÚsysÚexc_info)r   r   ÚkeyÚjustkeyÚobjs        r   Úrefresh_variablesr&   #   s†   € Ø	�‰€BØ�w‰w�Ö'ˆä—'‘'×"Ñ" 3Ó'ˆð	&Ø�S‘'ˆCð #&ˆB�J‰J�wÒñ (øô
 ò 	7ÜÐYÐ\cÑcÔdÜÐ"¤C§L¡L£N°1Ñ$5Ö6ð	7ús   ÁAÁ8BÂBc                 óV   — | j                   j                  dg «      | j                  d<   y )NÚdhistÚ_dh)r   r   r   ©r   s    r   Úrestore_dhistr+   2   s   € ØŸ™Ÿ	™	 '¨"Ó-€B‡J�JˆuÒr   c                 óF   — t        | «       t        | «       t        | «       y ©N)r&   r   r+   r*   s    r   Úrestore_datar.   6   s   € Ü�bÔÜ�BÔÜ�"Õr   c                   ór   ‡ — e Zd ZdZ edd¬«      j                  d¬«      Zˆ fd„Zee	d	d„«       «       Z
ˆ xZS )
ÚStoreMagicszMLightweight persistence for python variables.

    Provides the %store magic.FzdIf True, any %store-d variables will be automatically restored
        when IPython starts.
        )ÚhelpT)Úconfigc                 ó¼   •— t         t        | �  |¬«       | j                  j                  j                  | «       | j                  rt        | j                  «       y y )N)Úshell)Úsuperr0   Ú__init__r4   ÚconfigurablesÚappendÚautorestorer.   )Úselfr4   Ú	__class__s     €r   r6   zStoreMagics.__init__H   sG   ø€ ÜŒk˜4Ñ)°Ð)Ô6Ø�
‰
× Ñ ×'Ñ'¨Ô-Ø×ÒÜ˜Ÿ™Õ$ð r   c                 ó8  — | j                  |dd¬«      \  }}|j                  «       }| j                  }|j                  }d|v r	 |d   }	 |d|z   = yd
|v r|j                  d«      D ]  }	||	= Œ yd|v r.|r |D ]  }
	 |d|
z      }||j                  |
<   Œ yt        |«       y|s±|j                  d«      }|j                  «        |rt        t        t         |«      «      }nd}t        d«       dt#        |«      z   dz   }|j$                  }|D ]D  }t&        j(                  j+                  |«      }t        ||t-         ||d«      «      dd fz  «       ŒF yt!        |«      dkD  �r$|d   j/                  d«      �rt&        j(                  j1                  |d   j3                  d«      j3                  «       «      }|d   j/                  d«      rt5        |dd¬«      }nt5        |dd¬«      }|5  |j7                  |d   «      }t        d|d   ›d|j8                  j:                  ›d|›d�«       t=        |t"        «      sddlm}  |||«       n3|jA                  |«       |jC                  d «      s|jA                  d «       ddd«       y|D ]Œ  }
	 |j                  |
   }tE        tG        jH                  |«      d!d"«      }|d#k(  r't        tK        jL                  d$|
›d%|›d&�«      «        y||d|
z   <   t        d'|
›d|j8                  j:                  ›d(�«       ŒŽ y# t        $ r}t        d|z  «      |‚d}~ww xY w# t        $ r}t        d	«      |‚d}~ww xY w# t        $ r0 	 t        ||
¬«       n# t        $ r t        d|
z  «       Y nw xY wY �Œw xY w# 1 sw Y   yxY w# t        $ rq |
}	 |jN                  jQ                  |«      }n # tR        $ r}t        d)|z  «      |‚d}~ww xY w|j%                  d*i «      }|||<   ||d*<   t        d+|›d,|›d(�«       Y  yw xY w)-aŽ  Lightweight persistence for python variables.

        Example::

          In [1]: l = ['hello',10,'world']
          In [2]: %store l
          Stored 'l' (list)
          In [3]: exit

          (IPython session is closed and started again...)

          ville@badger:~$ ipython
          In [1]: l
          NameError: name 'l' is not defined
          In [2]: %store -r
          In [3]: l
          Out[3]: ['hello', 10, 'world']

        Usage:

        * ``%store``          - Show list of all variables and their current
                                values
        * ``%store spam bar`` - Store the *current* value of the variables spam
                                and bar to disk
        * ``%store -d spam``  - Remove the variable and its value from storage
        * ``%store -z``       - Remove all variables from storage
        * ``%store -r``       - Refresh all variables, aliases and directory history
                                from store (overwrite current vals)
        * ``%store -r spam bar`` - Refresh specified variables and aliases from store
                                   (delete current val)
        * ``%store foo >a.txt``  - Store value of foo to new file a.txt
        * ``%store foo >>a.txt`` - Append value of foo to file a.txt

        It should be noted that if you change the value of a variable, you
        need to %store it again if you want to persist the new value.

        Note also that the variables will need to be pickleable; most basic
        python types can be safely %store'd.

        Also aliases can be %store'd across sessions.
        To remove an alias from the storage, use the %unalias magic.
        ÚdrzÚstring)ÚmodeÚdr   zautorestore/zCan't delete variable '%s'Nz'You must provide the variable to forgetÚzr   Úr)r   zno stored variable or alias %sz(Stored variables and their in-db values:z%-zs -> %sz<unavailable>é2   é   Ú>z>>Úazutf-8)ÚencodingÚwz	Writing 'z' (z) to file 'z'.)ÚpprintÚ
Ú__name__Ú Ú__main__z                         Warning:z is a  
                        Proper storage of interactively declared classes (or instances
                        of those classes) is not possible! Only instances
                        of classes in real modules on file system can be %store'd.
                        zStored 'Ú)zUnknown variable '%s'r
   zAlias stored: z ()*Úparse_optionsÚsplitr4   r   ÚBaseExceptionr   Ú
IndexErrorr   r   r   r   r    r.   ÚsortÚmaxÚmapÚlenÚstrr   r   r   r   ÚreprÚ
startswithÚ
expanduserÚlstripÚopenÚevr;   rK   Ú
isinstancerI   ÚwriteÚendswithÚgetattrÚinspectÚ	getmoduleÚtextwrapÚdedentr   Úretrieve_aliasÚ
ValueError)r:   Úparameter_sÚoptsÚargslÚargsr   r   ÚtodelÚer   Úargr%   ÚvarsÚsizeÚfmtr   Úvarr$   ÚfnamÚfilrI   ÚmodnameÚnameÚcmdr   s                            r   ÚstorezStoreMagics.storeN   s	  € ð\ ×'Ñ'¨°E¸xÐ'ÓH‰
ˆˆUØ�{‰{‹}ˆØ�Z‰ZˆØ�U‰Uˆà�$‰;ðRØ˜Q™�ðRØ˜>¨EÑ1Ñ2ð �D‰[Ø—W‘W˜_Ö-�Ø�q‘Eñ .ð �D‰[ÙÛ�Cð.Ø  °#Ñ!5Ñ6˜ð +.˜Ÿ
™
 3šñ  ô ˜RÕ ñ Ø—7‘7˜?Ó+ˆDØ�I‰IŒKÙÜœ3œs D›>Ó*‘à�äÐ<Ô=Ø”s˜4“y‘. Ñ*ˆCØ—&‘&ˆCÛ�ÜŸ'™'×*Ñ*¨3Ó/�ä�c˜W¤d©3¨s°OÓ+DÓ&EÀcÀrÐ&JÐKÑKÕLñ ô �4‹y˜1‹}  a¡×!3Ñ!3°CÕ!8Ü—w‘w×)Ñ)¨$¨q©'¯.©.¸Ó*=×*DÑ*DÓ*FÓG�Ø˜‘7×%Ñ% dÔ+Ü˜t S°7Ô;‘Cä˜t S°7Ô;�CÚØŸ%™%  Q¡›.�CÝ¸tÀA»wØŸ™×.Ó.²ð6ô 7ô & s¬CÔ0Ý1Ù˜s CÕ(àŸ	™	 #œØ"Ÿ|™|¨DÔ1ØŸI™I dœO÷ ð ó �ðNØŸ*™* S™/�Cô  &¤g×&7Ñ&7¸Ó&<¸jÈ"ÓM�GØ *Ò,ÜœhŸošoò
  #¢Cð/)ó +ô ,ñ à14�B˜¨Ñ,Ñ.Ý²°S·]±]×5KÓ5KÐLÕMñ; øôA %ò RÜ$Ð%AÀEÑ%IÓJÐPQÐQûðRûô ò SÜ Ð!JÓKÐQRÐRûðSûô" $ò JðJÜ+¨B°cÖ:øÜ'ò JÜ!Ð"BÀSÑ"HÖIðJýðJú÷H ð ûô  ò à�DðPØ ×.Ñ.×=Ñ=¸dÓC™øÜ%ò PÜ(Ð)@À4Ñ)GÓHÈaÐOûðPúð !#§¡Ð'7¸Ó ;�IØ&)�I˜d‘OØ+4�BÐ'Ñ(Ý²Tº3Ð?Ô@Úðús©   ÁL: ÁL Á<MÇ+BNÊNÌ	L7Ì#L2Ì2L7Ì:	MÍMÍMÍ	NÍ!M/Í.NÍ/N	ÎNÎN	Î	NÎNÎNÎPÎ+OÏPÏ	O$ÏOÏO$Ï$1PÐP)rL   )rK   Ú
__module__Ú__qualname__Ú__doc__r   Útagr9   r6   r   r   rx   Ú__classcell__)r;   s   @r   r0   r0   <   sQ   ø„ ñ"ñ �uð	ô÷ 
�c�€cÓð	 ô%ð ØòVNó ó ôVNr   r0   c                 ó.   — | j                  t        «       y)zLoad the extension in IPython.N)Úregister_magicsr0   r*   s    r   Úload_ipython_extensionr€   é   s   € à×Ñ”{Õ#r   r-   )r{   rb   r   r!   rd   ÚIPython.core.errorr   ÚIPython.core.magicr   r   r   ÚIPython.testing.skipdoctestr   Ú	traitletsr   r   r&   r+   r.   r0   r€   © r   r   Ú<module>r†      s\   ðñ	÷ "× !å )ß ?Ñ ?Ý 4Ý ó?ò&ò.òð ôiN�&ó iNó ðiNóX$r   