+
    ^|i3                         R t ^ RIt^ RIt^ RIHt ^ RIt^ RIHt ^ RI	H
t
HtHt ^ RIHtHtHt ^ RIHt ^ RIHt ]! 4       t] ! R R	]
4      4       tR# )
z6Implementation of magic functions related to History.
N)open)StdinNotImplementedError)Magicsmagics_class
line_magic)argumentmagic_argumentsparse_argstring)skip_doctest)ioc                     a  ] tR t^%t o ]! 4       ]! RRRRRR7      ]! RRRRR	R7      ]! R
RRRRR7      ]! RRRRRR7      ]! RRRR7      ]! RRRRRR7      ]! RRRRRR7      ]! R R!]R"]R#R$7      ]! R%R&RR'R(7      ]! R)RR*7      ]]	R/R+ l4       4       4       4       4       4       4       4       4       4       4       4       4       t
]	R, 4       t]	R/R- l4       tR.tV tR# )0HistoryMagicsz-n
print_nums
store_trueFz{
        print line numbers for each input.
        This feature is only available if numbered prompts are in use.
        )destactiondefaulthelpz-o
get_outputz"also print outputs for each input.z-p	pypromptsz
        print classic '>>>' python prompts before each input.
        This is useful for making documentation, and in conjunction
        with -o, for producing doctest-ready output.
        z-trawstore_falseTa  
        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 'get_ipython().run_line_magic("cd", "/")' instead of '%%cd /'.
        z-ffilenamea  
        FILENAME: instead of printing the output to the screen, redirect
        it to the given file.  The file is always overwritten, though *when
        it can*, IPython asks for confirmation first. In particular, running
        the command 'history -f FILENAME' from the IPython Notebook
        interface will replace FILENAME even if it already exists *without*
        confirmation.
        )r   r   z-y	overwritez&yes, overwrite filename even if existsN)r   r   r   r   z-gpattern*ac  
        treat the arg as a glob pattern to search for in (full) history.
        This includes the saved history (almost all commands ever written).
        The pattern may contain '?' to match one unknown character and '*'
        to match any number of unknown characters. Use '%%hist -g' to show
        full saved history (may be very long).
        )r   nargsr   r   z-llimit?z
        get the last n lines from all sessions. Specify n as a single
        arg, or the default is the last 10 lines.
        )r   typer   r   r   z-uuniquezN
        when searching history using `-g`, show only unique history.
        )r   r   r   range)r   c                  a \        V P                  V4      pV P                  P                  oV3R lpVP                  pV'       g   \
        P                  pRpM\        P                  P                  V4      pVP                  RJ d   RpM\        P                  P                  V4      '       d   Rp\
        P                  P                  4       '       d   \        P                  ! RV,          4      pM \        P                  ! RV,          4      pV'       g   \#        R4       R# \#        R4       \%        VRR	R
7      pRpVP&                  pVP(                  p	VP*                  p
VP,                  pRpVP.                  \0        J d   RMVP.                  pRpVP2                  er   VP4                  '       g`   VP2                  '       d+   RRP7                  VP2                  4      ,           R,           pMRpSP9                  WV	WP:                  R7      pRpMVP.                  \0        Jd   Vf   ^
MTpSP=                  VWR7      pMhVP2                  '       d,   RRP7                  VP2                  4      ,           R,           pRpSP?                  RP7                  VP4                  4      W4      p^pV EF  w  pppV	'       d   Vw  ppV'       d    \@        P@                  ! VV4      '       g   K<  VPC                  ^4      PE                  4       pRV9   pV'       d   RMRpV'       d,   \#        V! VV4      PG                  V4      : RV: 2VRR7       V
'       d=   \#        RRVR7       V'       d'   RP7                  VPI                  4       4      R,           p\#        VVR7       V	'       g   K  X'       g   EK  \#        VVR7       EK  	  V'       d   VPK                  4        R# R#   \          d    Rp ELi ; i)a  Print input history (_i<n> variables), with most recent last.

By default, input history is printed without line numbers so it can be
directly pasted into an editor. Use -n to show them.

By default, all input history from the current session is displayed.
Ranges of history can be indicated using the syntax:

``4``
    Line 4, current session
``4-6``
    Lines 4-6, current session
``4-``
    Lines 4 onward (to end), current session
``243/1-5``
    Lines 1-5, session 243
``~2/``
    All lines of session 2 before current
``~4/4-``
    Lines 4 onward (to end), session 4 before current
``~2/7``
    Line 7, session 2 before current
``~8/1-~6/5``
    From the first line of 8 sessions ago, to the fifth line of 6
    sessions ago.

Multiple ranges can be entered, separated by spaces

The same syntax is used by %macro, %save, %edit, %rerun

Examples
--------
::

  In [6]: %history -n 4-6
  4:a = 12
  5:print(a**2)
  6:%history -n 4-6

c                R   < V ^ SP                   39   d   \        V4      # V : RV: 2# )z0Helper function to format line numbers properly./)session_numberstr)sessionlinehistory_managers   &&=/usr/lib/python3/dist-packages/IPython/core/magics/history.py_format_lineno-HistoryMagics.history.<locals>._format_lineno   s+    1o<<==4y %t,,    FTzFile %r exists. Overwrite?z	Aborting.NzOverwriting file.wzutf-8)encodingr    )r   outputnr    )r   r1   
: )fileendz>>> )r7   r6   z
... z
...)r6   )&r	   historyshellr)   r   sysstdoutospath
expanduserr   existsstdinisattyr   
ask_yes_nor   printio_openr   r   r   r   r   _unspecifiedr   r!   joinsearchr    get_tailget_range_by_strfnmatch
expandtabsrstriprjust
splitlinesclose)selfparameter_sargsr+   outfnameoutfileclose_at_endansr   r   r   r   r   r   range_patternhistr2   widthr'   linenoinliner1   	multilineline_sepr)   s   &&                      @r*   r8   HistoryMagics.history(   s   b t||[9 **44	- ==jjG Lww))(3H~~%))99##%%--(Dx(OPC# mm,H8,ST +&)*hg>GL__
__
NN	hh

l2

<<#DJJJ||| 66<"))':,1++ * GDJZZ|+mA"++A3+JD||| #chht||&< <s B!
"33$cD '+#GVV
 !'v}==&&q)002FI(tcH.&"A"G"G"N ")0c;g3W5%]]6+<+<+>?'IF&w'zfff7++/ (,2 MMO G 4 #"#s   7O( (O98O9c                   V'       gB   V P                   P                  \        V P                   P                  R,          4      4       R# V P                   P                  P                  V4      pRP                  R V 4       4      pV'       d,   V P                   P                  VP                  4       4       R#  \        \        WP                   P                  4      4      pV P                   P                  VP                  4       4       R#   \         d    T P                   P                  P                  RT,           R,           4      p\        T Uu. uF  qD^,          NK  	  Mu upi up4       F>  pRT9   g   RT9   d   K  T P                   P                  TP                  4       4         R# 	   Mi ; i\        RT4       R# )	a  Repeat a command, or get command to input line for editing.

%recall and %rep are equivalent.

- %recall (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::

     In[1]: l = ["hei", "vaan"]
     In[2]: "".join(l)
    Out[2]: heivaan
     In[3]: %recall
     In[4]: heivaan_ <== cursor blinking

%recall 45

Place history line 45 on the next input prompt. Use %hist to find
out the number.

%recall 1-4

Combine the specified lines into one cell, and place it on the next
input prompt. See %history for the slice syntax.

%recall foo+bar

If foo+bar can be evaluated in the user namespace, the result is
placed at the next input prompt. Otherwise, the history is searched
for lines which contain that substring, and the most recent one is
placed at the next input prompt.
_Nr3   c              3   2   "   T F  q^,          x  K  	  R# 5i)   N ).0xs   & r*   	<genexpr>'HistoryMagics.recall.<locals>.<genexpr>#  s     0i!is   r   recallrepz%Couldn't evaluate or find in history:)r9   set_next_inputr&   user_nsr)   rI   rF   rL   eval	ExceptionrG   reversedrC   )rP   arg	histlinescmdre   hs   &&    r*   rh   HistoryMagics.recall   sE   F JJ%%c$***<*<S*A&BCJJ..??D	ii0i00JJ%%cjjl3	d3

 2 234C JJ%%cjjl3  	

2299#c'#+FIY7YttY78q=EQJ

))!((*5	 9	 	5s;s&   ;(D AF8E'
&A
F83F87F8c                   V P                  VRRR7      w  r#RV9   db    \        VR,          4      pT^ 8X  d   \        R4       R# T^ 8  d   \        R4       R# T P                  P
                  P                  T4      pMR	V9   dn   R
VR	,          ,           R
,           p\        V P                  P
                  P                  V4      4      p\        V4       F  pRV^,          9  g   K  V.p MX	  . pMSV'       d'   V P                  P
                  P                  V4      pM%V P                  P
                  P                  ^4      pV Uu. uF  q^,          NK  	  ppV'       g   \        R4       R# RP                  V4      p	\        R4       \        V	4       \        R4       V P                  P                  RP                  V4      RR7       R#   \         d    \        R4        R# i ; iu upi )a7  Re-run previous input

By default, you can specify ranges of input history to be repeated
(as with %history). With no arguments, it will repeat the last line.

Options:

  -l <n> : Repeat the last n lines of input, not including the
  current command.

  -g foo : Repeat the most recent line which contains foo
zl:g:string)modelz"Number of lines must be an integerNz'Requested 0 last lines - nothing to runz+Number of lines to rerun cannot be negativegr   rerunz'No lines in history match specificationr3   z=== Executing: ===z=== Output: ===F)store_history)parse_optionsint
ValueErrorrC   r9   r)   rH   listrG   rn   rI   rF   run_cell)
rP   rQ   optsrR   r2   rX   prw   re   rp   s
   &&        r*   ry   HistoryMagics.rerun6  s    ''V('K
$;S	N
 Av?@QCD::--66q9DD[DIc!A

2299!<=Dd^!A$&3D $
 ::-->>tDD::--66q9D"#d!d#;<IIdO	"#i 

DIIdO5AC  :;2 $s   G 
G/G,+G,rc   )r5   )__name__
__module____qualname____firstlineno__r   r   r|   rE   r
   r   r8   rh   ry   __static_attributes____classdictcell__)__classdict__s   @r*   r   r   %   sm     <e <e13 ;|U 5	 :
 5  7C 8L
 gS!J   "
	3 NJX 8< 8<t 2B 2Br-   r   )__doc__r<   r:   r   r   rD   rJ   IPython.core.errorr   IPython.core.magicr   r   r   IPython.core.magic_argumentsr   r   r	   IPython.testing.skipdoctestr
   IPython.utilsobjectrE   r   rc   r-   r*   <module>r      s]    
 
   8 ? ?; ; 4  x CBF CB CBr-   