;ò
ÎÑAHc           @   sð   d  Z  d k l Z d k Z e i i ƒ  Z d k Z d k Z d k	 Z	 d k
 Z
 d k Z d k Z d k l Z d k l Z e d „ Z e d „ Z e d „ Z d „  Z d	 d
 „ Z d	 d „ Z d	 d „ Z e i d e ƒ e i d e ƒ d S(   sn   
%jot magic for lightweight persistence.

Stores variables in Struct with some notes in PicleShare database


(   s   datetimeN(   s
   FakeModule(   s   Structc         C   s÷   |  i } | t j o | i d ƒ } n | i d | ƒ } x´ | D]¬ } t i i | ƒ } d G| Gd GHy | | } Wn/ t
 j
 o# d | GHd Gt i ƒ  d GHqC Xy | i } Wn | |  i | <d G| GHqC X| d	 |  i | <d G| GHqC Wd  S(
   Ns   jot/*s   jot/s   Restoring froms   ...sC   Unable to restore variable '%s', ignoring (use %%jot -d to forget!)s   The error was:i    s   Restoreds   val(   s   ips   dbs   keys   Nones   keyss   oss   paths   basenames   justkeys   objs   KeyErrors   syss   exc_infos   names   orignames   user_ns(   s   ips   keys   objs   orignames   keyss   dbs   justkey(    (    sK   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_jot.pys   refresh_variables   s(    	 	c         C   s¥   |  i } | t j o t Sn | i d | ƒ } xm | D]e } t i i | ƒ } d G| GHy | | } Wn/ t
 j
 o# d | GHd Gt i ƒ  d GHq8 X| Sq8 Wd  S(   Ns   jot/s   restoring from s@   Unable to read variable '%s', ignoring (use %%jot -d to forget!)s   The error was:i    (   s   ips   dbs   keys   Nones   keyss   oss   paths   basenames   justkeys   objs   KeyErrors   syss   exc_info(   s   ips   keys   objs   keyss   dbs   justkey(    (    sK   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_jot.pys   read_variables/   s    	 		c         C   s}  |  i |  i i f \ } } | t j o | i d ƒ } n | i d | ƒ } | o t t t | ƒ ƒ } n d } d t
 | ƒ d }
 d }	 d } xâ | D]Ú } | | d ƒ } t i i | ƒ } y~ |
 | t i | i d	 d ƒ ƒ f GH|	 | i d
 d ƒ GH| i d d ƒ } | t t | ƒ ƒ d f GHt | ƒ d d !GHHHWq› t j
 o& t | d d t | ƒ d  f GHq› Xq› Wd  S(   Ns   jot/*s   jot/i    s   %-s   s [%s]s   Comment:
 %ss   Data:
 %s, %ss   <unavailable>s   times   comments   vals   unavailables    iÈ   i2   (   s   ips   dbs   gets   keys   Nones   keyss   maxs   maps   lens   sizes   strs   fmtheads   fmtbodys   fmtdatas   vs   oss   paths   basenames   justkeys   datetimes   ctimes   ds   reprs   types   AttributeErrors   fmt(   s   ips   keys   sizes   fmtdatas   gets   keyss   dbs   justkeys   ds   fmtbodys   fmtheads   v(    (    sK   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_jot.pys   detail_variablesB   s0     $c         C   s    y t  |  ƒ SWn d Sn Xd  S(   Ni    (   s   ints   n(   s   n(    (    sK   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_jot.pys   intm`   s    s    c         C   sO  |  i i d | d ƒ }	 d } t |	 ƒ d j oo t i i	 |	 ƒ } g  i } |	 D] } | | i | ƒ d ƒ qS ~ } t t | ƒ }
 t t |
 ƒ d ƒ } n d | | } t i i i } y t i i d ƒ i ƒ  } Wn d GHd } n Xt h  d | <d	 t  i! ƒ  <d
 | <d | <d | <ƒ |  i | <d | | i" i# f GHd S(   sR   
    write obj data to the note database, with whatever that should be noted.
    s   jot/s   *s    i    i   s   -xs   No comment is recorded.s   vals   times   hists   names   comments   Jotted down notes for '%s' (%s)N($   s   selfs   dbs   keyss   names   hads   suffixs   lens   oss   paths   commonprefixs   pres   appends   _[1]s   ns   splits   sufs   maps   intms   versionss   strs   maxs   unames   ips   IPs   shells
   input_hists   alls
   magic_edits   strips   comments   Structs   objs   datetimes   nows	   __class__s   __name__(   s   selfs   objs   names   comments   pres   alls   unames   suffixs   sufs   hads   versionss   ns   _[1](    (    sK   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_jot.pys   jot_objf   s"     4
Fc         C   sC  |  i | d d d ƒ\ } } | i t d ƒ } |  i ƒ  } | i
 } | i d ƒ oY y | d } Wn t j
 o t d ƒ q?Xy | d | =Wq?t d	 | ƒ q?Xn’| i d
 ƒ o	 d GHny| i d ƒ o8 y | d } Wn d GHt | ƒ q?Xt | | ƒ n1| i d ƒ oE y | d }
 Wn d GHt | ƒ q?Xd G|
 Gd GHt | |
 ƒ nÜ| o|  i
 i d ƒ } | i ƒ  | o t t t | ƒ ƒ d } n d } d GHd t | ƒ d } | i } xh| D]£ } t i i  | ƒ } | | d ƒ } yG | | t# i$ | i d d ƒ ƒ | i d d ƒ d  i% d d ƒ f GHWqÛt& j
 o& | | d d t' | ƒ d  f GHqÛXqÛWnºt | ƒ d j o | d i( d ƒ oú t i i) | d i* d ƒ i* ƒ  ƒ } | d i( d ƒ o t, | d  ƒ }	 n t, | d! ƒ }	 | i. | d ƒ } d" | d | i0 i1 | f GHt2 | t3 ƒ o d# k4 l4 } | | |	 ƒ n0 |	 i5 | ƒ | i6 d ƒ o |	 i5 d ƒ n |	 i7 ƒ  d$ Sn y | i8 | d } Wn/ t9 j
 o# Hd% | d GHHd& d' GHd$ SnS Xt2 t: i; | ƒ t< ƒ o$ t= i> d( | d | f ƒ GHd$ Sn t? |  | | d ƒ d$ S()   så  Lightweight persistence for python variables.

    Example:
    
    ville@badger[~]|1> A = ['hello',10,'world']\
    ville@badger[~]|2> %jot A\
    ville@badger[~]|3> Exit
    
    (IPython session is closed and started again...)
    
    ville@badger:~$ ipython -p pysh\
    ville@badger[~]|1> print A
    
    ['hello', 10, 'world']
    
    Usage:
    
    %jot          - Show list of all variables and their current values\
    %jot -l       - Show list of all variables and their current values in detail\
    %jot -l <var> - Show one variable and its current values in detail\
    %jot <var>    - Store the *current* value of the variable to disk\
    %jot -d <var> - Remove the variable and its value from storage\
    %jot -z       - Remove all variables from storage (disabled)\
    %jot -r <var> - Refresh/Load variable from jot (delete current vals)\
    %jot foo >a.txt  - Store value of foo to new file a.txt\
    %jot 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 %note 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 %stored.
    
    s   drzls   modes   stringi   s   di    s'   You must provide the variable to forgets   jot/s   Can't delete variable '%s's   zs.   reseting the whole database has been disabled.s   rs*   restoring all the variables jotted down...s   ls   List details for all the items.s   Details fors   :s   jot/*i   s!   Variables and their in-db values:s   %-s   s [%s] -> %ss   <unavailable>s   times   commentiF   s   
s    i2   s   >s   >>s   as   ws   Writing '%s' (%s) to file '%s'.(   s   pprintNs   Error: %s doesn't exist.sB   Use %note -r <var> to retrieve variables. This should not be used s.   to store alias, for saving aliases, use %stores                  Warning:%s is %s 
                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.
                (@   s   selfs   parse_optionss   parameter_ss   optss   argsls   splits   Nones   argss   getapis   ips   dbs   has_keys   todels
   IndexErrors   errors   torets   refresh_variabless   tolists   detail_variabless   keyss   varss   sorts   maxs   maps   lens   sizes   strs   fmts   gets   vars   oss   paths   basenames   justkeys   vs   datetimes   ctimes   replaces   AttributeErrors   reprs
   startswiths
   expandusers   lstrips   fnams   opens   fils   evs   objs	   __class__s   __name__s
   isinstances
   basestrings   pprints   writes   endswiths   closes   user_nss   KeyErrors   inspects	   getmodules
   FakeModules   textwraps   dedents   jot_obj(   s   selfs   parameter_ss   vs   varss   ips   torets   sizes   pprints   vars   fils   tolists   argsls   fnams   gets   argss   dbs   justkeys   objs   todels   fmts   opts(    (    sK   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_jot.pys	   magic_jot   s–    " 		
	 G,'%
		c         C   sw   |  i | d d d ƒ\ } } | i t d ƒ } |  i ƒ  } | i
 } y | d } Wn d GHd Sn Xt | | ƒ Sd S(   sN       
    %read <var> - Load variable from data that is jotted down.\
    
    s   drzls   modes   stringi   i    s%   which record do you want to read out?N(   s   selfs   parse_optionss   parameter_ss   optss   argsls   splits   Nones   argss   getapis   ips   dbs   torets   read_variables(   s   selfs   parameter_ss   argsls   ips   argss   dbs   torets   opts(    (    sK   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_jot.pys
   magic_read"  s     	s   jots   read(   s   __doc__s   datetimes   IPython.ipapis   IPythons   ipapis   gets   ips   pickleshares   inspects   pickles   oss   syss   textwraps   IPython.FakeModules
   FakeModules   IPython.ipstructs   Structs   Nones   refresh_variabless   read_variabless   detail_variabless   intms   jot_objs	   magic_jots
   magic_reads   expose_magic(   s   detail_variabless	   magic_jots   oss   intms   ips
   magic_reads   inspects   textwraps   datetimes   syss
   FakeModules   read_variabless   refresh_variabless   IPythons   pickles   pickleshares   jot_objs   Struct(    (    sK   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_jot.pys   ?   s    		-	'•