
    ^h                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJrJ	r	J
r
  SSKJr  SSKJr  SS jrS rS	 rS
 r\	 " S S\5      5       rS rg)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                     U R                   R                  S0 5      nUc5  UR                  5        H   u  p4U R                  R	                  X45        M"     g U R                  R	                  XU   5        g )Nstored_aliases)dbgetitemsalias_managerdefine_alias)ipalias	staliaseskvs        W/home/james-whalen/.local/lib/python3.13/site-packages/IPython/extensions/storemagic.pyrestore_aliasesr      s`    		*B/I}??$CA ))!. %
 	%%eu-=>    c                 2   U R                   nUR                  S5       H5  n[        R                  R	                  U5      n X   nX@R
                  U'   M7     g ! [         a4    [        SU-  5        [        S[        R                  " 5       S   5         Mw  f = f)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ww'''""3'	&'C #&JJw (
  	7Y\ccd"CLLN1$56	7s   A:BBc                 V    U R                   R                  S/ 5      U R                  S'   g )Ndhist_dh)r   r   r   r   s    r   restore_dhistr+   2   s    		'"-BJJur   c                 F    [        U 5        [        U 5        [        U 5        g N)r&   r   r+   r*   s    r   restore_datar.   6   s    bB"r   c                   r   ^  \ rS rSrSr\" SSS9R                  SS9rU 4S jr\	\
SS	 j5       5       rS
rU =r$ )StoreMagics<   zILightweight persistence for python variables.

Provides the %store magic.FzdIf True, any %store-d variables will be automatically restored
        when IPython starts.
        )helpT)configc                    > [         [        U ]  US9  U R                  R                  R                  U 5        U R                  (       a  [        U R                  5        g g )N)shell)superr0   __init__r5   configurablesappendautorestorer.   )selfr5   	__class__s     r   r7   StoreMagics.__init__H   sG    k4))6

  ''-$ r   c                    U R                  USSS9u  p#UR                  5       nU R                  nUR                  nSU;   a   US   n USU-   	 gS
U;   a  UR                  S5       H  n	Xi	 M     gSU;   a4  U(       a!  U H  n
 USU
-      nXR                  U
'   M     g[        U5        gU(       d  UR                  S5      nUR                  5         U(       a  [        [        [         U5      5      nOSn[        S5        S[#        U5      -   S-   nUR$                  nU HE  n[&        R(                  R+                  U5      n[        UU[-        U" US5      5      SS 4-  5        MG     g[!        U5      S:  Ga5  US   R/                  S5      (       Ga  [&        R(                  R1                  US   R3                  S5      R3                  5       5      nUS   R/                  S5      (       a  [5        USSS9nO[5        USSS9nU   UR7                  US   5      n[        SUS   < SUR8                  R:                  < SU< S35        [=        U["        5      (       d  SSKJn  U" UU5        O8URA                  U5        URC                  S 5      (       d  URA                  S 5        SSS5        gU H  n
 UR                  U
   n[E        [F        RH                  " U5      S!S"5      nUS#:X  a*  [        [J        RL                  " S$U
< S%U< S&35      5          gXSU
-   '   [        S'U
< SUR8                  R:                  < S(35        M     g! [         a  n[        SU-  5      UeSnAff = f! [         a  n[        S	5      UeSnAff = f! [         a0     [        XZS9   GM   ! [         a    [        SU
-  5          GM=  f = ff = f! , (       d  f       g= f! [         at    U
n URN                  RQ                  U5      nO!! [R         a  n[        S)U-  5      UeSnAff = fUR%                  S*0 5      nUUU'   UUS*'   [        S+U< S,U< S(35           gf = f)-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splitr5   r   BaseExceptionr   
IndexErrorr   r   r   r   r    r.   sortmaxmaplenstrr   r   r   r   repr
startswith
expanduserlstripopenevr<   rM   
isinstancerK   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filrK   modnamenamecmdr   s                            r   storeStoreMagics.storeN   s   \ ''Ex'H
{{}ZZUU$;RQR>E12 D[WW_-E . D[C. #!56 +.

3   R  77?+DIIK3sD>*<=s4y.*C&&C''**3/cWd3sO+D&Ecr&JKKL  4y1}a!3!3C!8!8ww))$q'..*=*D*D*FG7%%d++tS7;CtS7;C%%Q.CtAw..6 7 &sC001sC(		#"||D11IIdO   N**S/C  &g&7&7&<j"MG*,hoo
  #C/) + , 14,.S]]5K5KLM; A % R$%AE%IJPQQR  S !JKQRRS" $ JJ+B:' J!"BS"HIIJJH S    DP ..==dC% P()@4)GHaOP !#'7 ;I&)IdO+4B'(T3?@s   M* 	M	 NB!O5O	
M'M""M'*
N4N  N
O	N  N>8O=N>>O
OQ#O?>Q?
P	PP3QQ )rN   )rM   
__module____qualname____firstlineno____doc__r   tagr:   r7   r   r   rz   __static_attributes____classcell__)r<   s   @r   r0   r0   <   sQ    " u	 
cc	 % VN  VNr   r0   c                 .    U R                  [        5        g)zLoad the extension in IPython.N)register_magicsr0   r*   s    r   load_ipython_extensionr      s    {#r   r-   )r   rd   r   r!   rf   IPython.core.errorr   IPython.core.magicr   r   r   IPython.testing.skipdoctestr   	traitletsr   r   r&   r+   r.   r0   r   r|   r   r   <module>r      s\   	 " ! ) ? ? 4 ?&. iN& iN iNX$r   