Ñò
ÎÑAHc           @   s‡   d  Z  d d k Z d d k Z d d k l Z l Z d d „ Z d d „ Z d „  Z e	 ƒ  Z
 d d d	 „  ƒ  YZ d
 „  Z d „  Z d S(   s*    History related magics and functionality iÿÿÿÿN(   t   Termt
   ask_yes_not    c         C   s´  |  i  } |  i } | i i p
 d GHd S|  i | d d d ƒ\ } } y | d } Wn" t j
 o t i } t } nO Xt	 i
 i | ƒ o: t d | ƒ }	 |	 p
 d GHd St | d	 ƒ } t } n | i d
 ƒ o | i }
 n' | i d ƒ o | i }
 n
 | i }
 d } d } | i d ƒ oc d } t |
 ƒ } | i d d ƒ } t | ƒ d j o | d 7} n | \ } } d | d } n¼ t | ƒ d j o# t |
 ƒ } t d | | ƒ } n† t | ƒ d j o- t |
 ƒ } t d | t | d ƒ ƒ } nF t | ƒ d j o t t | ƒ \ } } n t d ƒ |  i i GHd St t | ƒ ƒ } d d g } | i d ƒ } t } | d j	 oY | i i i ƒ  } xD | D]8 \ } } t i | | ƒ o d | | f GHt } qžqžWn | o d GHd GHd GHn x  t  | | ƒ D] } |
 | } | d j	 o t i | | ƒ o qn t | i! d ƒ d j ƒ } | o+ | d t | ƒ i" | ƒ | | f In | | IqW| o | i# ƒ  n d S(   s«  Print input history (_i<n> variables), with most recent last.
    
    %history       -> print at most 40 inputs (some may be multi-line)\
    %history n     -> print at most n inputs\
    %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\
    
    Each input's number <n> is shown, and is accessible as the
    automatically generated variable _i<n>.  Multi-line statements are
    printed starting at a new line for easy copy/paste.
    

    Options:

      -n: do NOT print line numbers. This is useful if you want to get a
      printout of many lines which can be directly pasted into a text
      editor.

      This feature is only available if numbered prompts are in use.

      -t: (default) print the 'translated' history, as IPython understands it.
      IPython filters your input and converts it all into valid Python source
      before executing it (things like magics or aliases are turned into
      function calls, for example). With this option, you'll see the native
      history instead of the user-entered version: '%cd /' will be seen as
      '_ip.magic("%cd /")' instead of '%cd /'.
      
      -r: print the 'raw' history, i.e. the actual commands you typed.
      
      -g: treat the arg as a pattern to grep for in (full) history.
      This includes the "shadow history" (almost all commands ever written).
      Use '%hist -g' to show full shadow history (may be very long).
      In shadow history, every index nuwber starts with 0.

      -f FILENAME: instead of printing the output to the screen, redirect it to
       the given file.  The file is always overwritten, though IPython asks for
       confirmation first if it already exists.
      

    s>   This feature is only available if numbered prompts are in use.Ns   gntsrf:t   modet   listt   fs   File %r exists. Overwrite?s	   Aborting.t   wt   tt   ri(   t   gi   t   *i    i   s4   %hist takes 0, 1 or 2 arguments separated by spaces.R   s   
t   ns   0%d: %ss   ===s?   shadow history ends, fetch by %rep <number> (must start with 0)s   === start of normal history ===s   %s:%s($   t   apit   shellt   outputcachet   do_full_cachet   parse_optionst   KeyErrorR    t   coutt   Falset   ost   patht   existsR   t   opent   Truet   has_keyt
   input_histt   input_hist_rawt   Nonet   lent   splitt   maxt   intt   mapt   warnt
   magic_histt   __doc__t   strt   IPt
   shadowhistt   allt   fnmatcht   ranget   countt   ljustt   close(   t   selft   parameter_st   ipR   t   optst   argst   outfnamet   outfilet   close_at_endt   ansR   t   default_lengtht   patternt   initt   finalt   partst   headt   widtht   line_sept
   print_numst   foundt   sht   idxt   st   in_numt   inlinet	   multiline(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyt   magic_history   sŽ    )			
	!
 	 
!'c         C   s   |  i  | ƒ S(   s   Alternate name for %history.(   RG   (   R.   R/   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyR#      s    c   	      C   sæ  |  i  | d d d ƒ\ } } |  i } | p | i t | i d ƒ ƒ d St | ƒ d j o7d | d j o&| d } t | ƒ d j oJ | i d	 ƒ o: t | d ƒ } |  i i	 | ƒ } | i t | ƒ ƒ d Sy; t | d ƒ } | i t | i
 i | ƒ i ƒ  ƒ d SWn t j
 o n Xxk t |  i i ƒ D]S } d
 | j o q<n t i | d | d ƒ o | i t | ƒ i ƒ  ƒ d Sq<Wn y, |  i | t ƒ } d G| GH| i | ƒ Wn t j
 o d G| GHn Xd S(   sA   Repeat a command, or get command to input line for editing

    - %rep (no arguments):
    
    Place a string version of last computation result (stored in the special '_'
    variable) to the next input prompt. Allows you to create elaborate command
    lines without using copy-paste::
    
        $ l = ["hei", "vaan"]       
        $ "".join(l)        
        ==> heivaan        
        $ %rep        
        $ heivaan_ <== cursor blinking    
    
    %rep 45
    
    Place history line 45 to next input prompt. Use %hist to find out the
    number.
    
    %rep 1-4 6-7 3
    
    Repeat the specified lines immediately. Input slice syntax is the same as
    in %macro and %save.
    
    %rep foo
    
    Place the most recent line that has the substring "foo" to next input.
    (e.g. 'svn ci -m foobar').
    
    R   R   R   t   _Ni   t   -i    t   0t   repR
   t   liness   Not found in recent history:(   R   R   t   set_next_inputR%   t   user_nsR   t
   startswithR    R'   t   getR&   R   t   rstript
   ValueErrort   reversedR   R)   t   extract_input_slicesR   t   runlines(	   R.   t   argR1   R2   R0   t   numt   linet   hRL   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyt   rep_f“   s>    !	$
## 	t
   ShadowHistc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   d |  _  | |  _ d  S(   Ni    (   t   curidxt   db(   R.   R]   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyt   __init__Ý   s    	c         C   s*   |  i  i d d ƒ } | d |  i  d <| S(   Nt   shadowhist_idxi   (   R]   RP   (   R.   RB   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyt   inc_idxâ   s    c         C   sP   |  i  i d | t ƒ } | t j	 o d  S|  i ƒ  } |  i  i d | | ƒ d  S(   NR'   (   R]   t   hgett	   _sentinelR`   t   hset(   R.   t   entt   oldt   newidx(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyt   addç   s
    c         C   sS   |  i  i d ƒ } g  } | i ƒ  D] \ } } | | | f q# ~ } | i ƒ  | S(   NR'   (   R]   t   hdictt   itemst   sort(   R.   t   dt   _[1]RC   t   iRi   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyR(   ï   s    3
c         C   s9   |  i  ƒ  } x& | D] \ } } | | j o | Sq Wd  S(   N(   R(   (   R.   RB   R(   t   kt   v(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyRP   õ   s
     (   t   __name__t
   __module__R^   R`   Rg   R(   RP   (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyR[   Ü   s
   				c          C   s   d d k  l }  |  i d ƒ } t | ƒ } | i d ƒ | i d ƒ | i d ƒ | i d ƒ | i d ƒ d G| i ƒ  GH| i d ƒ GHd  S(	   Niÿÿÿÿ(   t   pickleshares   ~/shistt   hellot   worldt   karhuR(   i   (   t   IPython.ExtensionsRr   t   PickleShareDBR[   Rg   R(   RP   (   Rr   R]   RC   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyt
   test_shistý   s    c         C   sP   |  i  d t ƒ |  i  d t ƒ |  i  d t ƒ d d  k } | i d d ƒ d  S(   NRK   t   histt   historyiÿÿÿÿs   %hists   -g -t -r -n(   t   expose_magicRZ   R#   RG   t   ipy_completerst   quick_completer(   R0   R|   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyt   init_ipython	  s
    (    (   R$   R)   R   t   IPython.genutilsR    R   RG   R#   RZ   t   objectRb   R[   Rx   R~   (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/history.pyt   <module>   s   	G	!	