wL idZddlZddlZddlZddlZddlmZddlmZm Z m Z ddl m Z ddl mZddZdZd Zd Ze Gd d eZd Zy)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|jjdi}|5|jD]!\}}|jj ||#y|jj |||y)Nstored_aliases)dbgetitems alias_manager define_alias)ipalias staliaseskvs c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/extensions/storemagic.pyrestore_aliasesrsk *B/I }??$ /CAa    ) )!A . / %%eYu-=>c,|j}|jdD]6}tjj |} ||}||j |<8y#t $r2td|ztdtjdYtwxYw)N autorestore/*zEUnable to restore variable '%s', ignoring (use %%store -d to forget!)zThe error was:r) r keysospathbasenameuser_nsKeyErrorprintsysexc_info)rr keyjustkeyobjs rrefresh_variablesr&#s Bww' &''""3' &S'C #&BJJw  &  7 Y\cc d "CLLN1$5 6 7sA8BBcV|jjdg|jd<y)Ndhist_dh)r r rrs r restore_dhistr+2s '"-BJJurcFt|t|t|yN)r&rr+r*s r restore_datar.6sbB"rcreZdZdZeddj dZfdZee d dZ xZ S) StoreMagicszMLightweight persistence for python variables. Provides the %store magic.FzdIf True, any %store-d variables will be automatically restored when IPython starts. )helpT)configctt| ||jjj ||j rt|jyy)N)shell)superr0__init__r4 configurablesappend autorestorer.)selfr4 __class__s rr6zStoreMagics.__init__HsG k4))6   ''-     $ rc 8|j|dd\}}|j}|j}|j}d|vr |d} |d|z=yd |vr|jd D]} || =yd |vr.|r |D]} |d| z} | |j| <yt|y|s|jd } | j| rttt | } nd} tddt#| zdz}|j$}| D]D}t&j(j+|}t||t-||dddfzFyt!|dkDr$|dj/drt&j(j1|dj3dj3}|dj/drt5|dd}nt5|dd}|5|j7|d} td|dd| j8j:d|dt=| t"sddlm}|| |n3|jA| | jCd s|jAd dddy|D]} |j| } tEtGjH| d!d"}|d#k(r'ttKjLd$| d%| d&y| |d| z<td'| d| j8j:d(y#t$r}t d|z|d}~wwxYw#t $r}t d |d}~wwxYw#t$r0 t|| n#t$rtd| zYnwxYwYwxYw#1swYyxYw#t$rq| } |jNjQ|}n #tR$r}t d)|z|d}~wwxYw|j%d*i}|||<||d*<td+|d,|d(YywxYw)-aLightweight 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. drzstring)modedrz autorestore/zCan't delete variable '%s'Nz'You must provide the variable to forgetzrr)rzno stored variable or alias %sz(Stored variables and their in-db values:z%-zs -> %sz 2>z>>azutf-8)encodingwz 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. zStored ')zUnknown variable '%s'r zAlias stored: z ()* parse_optionssplitr4r BaseExceptionr IndexErrorrrrrr r.sortmaxmaplenstrr rrrrepr startswith expanduserlstripopenevr;rK isinstancerIwriteendswithgetattrinspect getmoduletextwrapdedentrretrieve_alias ValueError)r: parameter_soptsargslargsrr todelerargr%varssizefmtr varr$fnamfilrImodnamenamecmdrs rstorezStoreMagics.storeNs&\'' Ex'H U{{} ZZ UU $; RQR>E12D[WW_- qE D[ .C. #!56+. 3 .R 77?+D IIK3sD>* < =s4y.*C&&C M''**3/cWd3sO+D&Ecr&JKKL M4y1}a!3!3C!8ww))$q'..*=*D*D*FG7%%d+tS7;CtS7;C ,%%Q.CtAw ..67&sC01sC( #"||D1IIdO , NN**S/C &g&7&7&rs\ "!)??4? &. iN&iNiNX$r