ó
æNXc           @  s:  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d l m Z m Z m Z m Z d d l m Z m Z m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z m  Z  d e! f d „  ƒ  YZ" e d e f d „  ƒ  Yƒ Z# d S(   s(   Implementation of basic magic functions.iÿÿÿÿ(   t   print_functionN(   t   pformat(   t   magic_argumentst   page(   t
   UsageError(   t   Magicst   magics_classt
   line_magict   magic_escapes(   t   format_screent   dedentt   indent(   t   skip_doctest(   t   Struct(   t   unquote_filename(   t   unicode_type(   t   warnt   errort   MagicsDisplayc           B  s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C  s   | |  _  d  S(   N(   t   magics_manager(   t   selfR   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   __init__   s    c      	   C  s   t  d } t  d } |  j } | j ƒ  } d | d | j t | d ƒ ƒ d d | d | j t | d ƒ ƒ d | j ƒ  g } d j | ƒ S(   s'   The main implementation of the %lsmagict   linet   cells   Available line magics:s     t    s   Available cell magics:s   
(   R   R   t   lsmagict   joint   sortedt   auto_status(   R   t   mesct   cesct   mmant   magicst   out(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   _lsmagic   s    

	c         C  s   | j  |  j ƒ  ƒ d  S(   N(   t   textR"   (   R   t   pt   cycle(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   _repr_pretty_(   s    c         C  s
   |  j  ƒ  S(   N(   R"   (   R   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   __str__+   s    c   
      C  s    i  } |  j  } | j ƒ  } x~ | j ƒ  D]p \ } } i  } | | | <xQ | j ƒ  D]C \ } } y | j j j }	 Wn t k
 r‰ d }	 n X|	 | | <qQ Wq( W| S(   s   turn magics dict into jsonable dict of the same structure
        
        replaces object instances with their class names as strings
        t   Other(   R   R   t   itemst   __self__t	   __class__t   __name__t   AttributeError(
   R   t
   magic_dictR   R    t   keyt   subdictt   dt   namet   objt	   classname(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt	   _jsonable.   s    	

c         C  s
   |  j  ƒ  S(   N(   R5   (   R   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   _repr_json_B   s    (   R,   t
   __module__R   R"   R&   R'   R5   R6   (    (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyR      s   					t   BasicMagicsc        
   B  sÄ  e  Z d  Z e j ƒ  e j d d d d d d ƒe j d d d d d d	 ƒe j d
 d d ƒe j d d d ƒe d d „ ƒ ƒ ƒ ƒ ƒ ƒ Z e d d „ ƒ Z e e d „ Z	 e d d „ ƒ Z
 e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z e d „  ƒ Z e d d „ ƒ Z e d d „ ƒ Z e e d d „ ƒ ƒ Z e j ƒ  e j d d d d d e d d ƒe j d  d! e d d" ƒe d# „  ƒ ƒ ƒ ƒ Z RS($   s´   Magics that provide central IPython functionality.

    These are various magics that don't fit into specific categories but that
    are all part of the base 'IPython experience'.s   -ls   --linet   actiont
   store_truet   helps   Create a line magic alias.s   -cs   --cells   Create a cell magic alias.R2   s    Name of the magic to be created.t   targets(   Name of the existing line or cell magic.R   c   
   
   C  sÇ  t  j |  j | ƒ } |  j } |  j j } d j t j ƒ  ƒ } | j j	 | ƒ } | j
 j	 | ƒ } | j | d ƒ } | j | d ƒ }	 | j r¹ | d k r¹ t d t d | f ƒ ‚ n  | j rë |	 d k rë t d t d | f ƒ ‚ n  | j rA| j rA| r |	 r t d | ƒ ‚ n  t | ƒ | _ t |	 ƒ | _ n  | j r‚| j | | d ƒ t d t d | t d | f ƒ n  | j rÃ| j | | d ƒ t d t d | t d | f ƒ n  d S(	   sÓ  Create an alias for an existing line or cell magic.

        Examples
        --------
        ::

          In [1]: %alias_magic t timeit
          Created `%t` as an alias for `%timeit`.
          Created `%%t` as an alias for `%%timeit`.

          In [2]: %t -n1 pass
          1 loops, best of 3: 954 ns per loop

          In [3]: %%t -n1
             ...: pass
             ...:
          1 loops, best of 3: 954 ns per loop

          In [4]: %alias_magic --cell whereami pwd
          UsageError: Cell magic function `%%pwd` not found.
          In [5]: %alias_magic --line whereami pwd
          Created `%whereami` as an alias for `%pwd`.

          In [6]: %whereami
          Out[6]: u'/home/testuser'
        R   R   R   s%   Line magic function `%s%s` not found.s%   Cell magic function `%s%s` not found.s+   No line or cell magic with name `%s` found.s&   Created `%s%s` as an alias for `%s%s`.N(   R   t   parse_argstringt   alias_magict   shellR   R   R   t   valuesR<   t   lstripR2   t
   find_magicR   t   NoneR   R   t   boolt   register_aliast   print(
   R   R   t   argsR?   R   t   escsR<   R2   t   m_linet   m_cell(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyR>   M   s<    -		
	
c         C  s   t  |  j j ƒ S(   s)   List currently available magic functions.(   R   R?   R   (   R   t   parameter_s(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyR   ¢   s    c      
   C  sÓ   |  j  j } | j | d d ƒ} | r0 d } n d } d j g  t | d j ƒ  ƒ D]/ \ } } | t d | t t | ƒ ƒ f ^ qS g  t | d j ƒ  ƒ D]/ \ } } | t d | t t | ƒ ƒ f ^ qœ ƒ S(   s'   Return docstrings from magic functions.t   missings   No documentations   **%s%s**::

%s

s	   %s%s:
%s
R   R   R   (	   R?   R   t   lsmagic_docsR   R   R)   R   R   R
   (   R   t   brieft   restR   t   docst   format_stringt   fnamet   fndoc(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   _magic_docs§   s    	Fc         C  sà   d } y- | j  ƒ  d d } | d k r2 g  } n  Wn t k
 rF n X| d k } | d k } |  j | | ƒ } | d k r” t |  j | ƒ ƒ d St | ƒ } d | d	 t d
 t |  j ƒ  ƒ g } t	 j	 d j
 | ƒ ƒ d S(   sm   Print information about the magic function system.

        Supported formats: -latex, -brief, -rest
        R   i    i   RO   RN   t   latexNsÜ  
IPython's 'magic' functions
===========================

The magic function system provides a series of functions which allow you to
control the behavior of IPython itself, plus a lot of system-type
features. There are two kinds of magics, line-oriented and cell-oriented.

Line magics are prefixed with the % character and work much like OS
command-line calls: they get as an argument the rest of the line, where
arguments are passed without parentheses or quotes.  For example, this will
time the given statement::

        %timeit range(1000)

Cell magics are prefixed with a double %%, and they are functions that get as
an argument not only the rest of the line, but also the lines below it in a
separate argument.  These magics are called with two arguments: the rest of the
call line and the body of the cell, consisting of the lines below the first.
For example::

        %%timeit x = numpy.random.randn((100, 100))
        numpy.linalg.svd(x)

will time the execution of the numpy svd routine, running the assignment of x
as part of the setup phase, which is not timed.

In a line-oriented client (the terminal or Qt console IPython), starting a new
input with %% will automatically enter cell mode, and IPython will continue
reading input until a blank line is given.  In the notebook, simply type the
whole cell as one entity, but keep in mind that the %% escape can only be at
the very start of the cell.

NOTE: If you have 'automagic' enabled (via the command line option or with the
%automagic function), you don't need to type in the % explicitly for line
magics; cell magics always require an explicit '%%' escape.  By default,
IPython ships with automagic on, so you should only rarely need the % escape.

Example: typing '%cd mydir' (without the quotes) changes you working directory
to 'mydir', if it exists.

For a list of the available magic functions, use %lsmagic. For a description
of any of them, type %magic_name?, e.g. '%cd?'.

Currently the magic system has the following functions:s,   Summary of magic functions (from %slsmagic):R   s   
(   t   splitt
   IndexErrorRT   RF   t   format_latexR	   R   t   strR   R   R   (   R   RK   t   modet	   rest_docsRN   RO   t
   magic_docsR!   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   magic»   s&    .c         C  s   |  j  | d ƒ \ } } d | k } | r0 | p3 d } |  j j | ƒ } | d r~ | r^ t pa t | d ƒ } t j | ƒ n t d | ƒ d S(   sÖ   Pretty print the object and display it through a pager.

        %page [options] OBJECT

        If no object is given, use _ (last output).

        Options:

          -r: page str(object), don't pretty-print it.t   rt   _t   foundR3   s   Object `%s` not foundN(   t   parse_optionsR?   t   _ofindRY   R   R   RF   (   R   RK   t   optsRG   t   rawt   onamet   infot   txt(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyR     s    
c         C  sJ   t  d ƒ d d l m } | j ƒ  r< t | j ƒ  j ƒ n
 t d ƒ d S(   s×   Print your currently active IPython profile.

        See Also
        --------
        prun : run code using the Python profiler
               (:meth:`~IPython.core.magics.execution.ExecutionMagics.prun`)
        sE   %profile is now deprecated. Please use get_ipython().profile instead.iÿÿÿÿ(   t   BaseIPythonApplications[   profile is an application-level value, but you don't appear to be in an IPython applicationN(   R   t   IPython.core.applicationRh   t   initializedRF   t   instancet   profileR   (   R   RK   Rh   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyRl   "  s
    	
c         C  sG   |  j  j j d } t d | j ƒ | _ t d d d g | j ƒ d S(   s   Toggle pretty printing on/off.s
   text/plaini   s   Pretty printing has been turnedt   OFFt   ONN(   R?   t   display_formattert
   formattersRD   t   pprintRF   (   R   RK   t   ptformatter(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyRq   2  s    c         C  si  d „  } | j  ƒ  } | s* t d ƒ ‚ n  |  j } d d l j j } | j r | j r t j	 d k sw t j	 d k r d } d } t
 | ƒ n  | j r­ | j r­ d } n  y | | j _ Wn | d	 ƒ n X| j j j | _ y* | j j d
 | ƒ | j j d
 | ƒ Wn | d ƒ n X| j rUy | j j | ƒ Wqe| d ƒ qeXn | j j d ƒ d S(   s2  Switch color scheme for prompts, info system and exception handlers.

        Currently implemented schemes: NoColor, Linux, LightBG.

        Color scheme names are not case-sensitive.

        Examples
        --------
        To get a plain black and white terminal::

          %colors nocolor
        c         S  s"   t  d |  t j ƒ  d f ƒ d  S(   Ns#   Error changing %s color schemes.
%si   (   R   t   syst   exc_info(   R2   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   color_switch_errH  s    s8   %colors: you must specify a color scheme. See '%colors?'iÿÿÿÿNt   win32t   clis£   Proper color support under MS Windows requires the pyreadline library.
You can find it at:
http://ipython.org/pyreadline.html

Defaulting color scheme to 'NoColor't   NoColort   promptt   schemet	   exceptions   object inspector(   t   stripR   R?   t   IPython.utils.rlineimplt   utilst	   rlineimplt   colors_forcet   have_readlineRs   t   platformR   t   has_readlinet   prompt_managert   color_schemet   color_scheme_tablet   active_scheme_namet   colorst   InteractiveTBt
   set_colorst   SyntaxTBt
   color_infot	   inspectort   set_active_scheme(   R   RK   Ru   t
   new_schemeR?   t   readlinet   msg(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyRˆ   :  s>    		

		c         C  sf   d „  } |  j  } | j ƒ  j ƒ  } y* | j j d | ƒ t d | j j ƒ Wn | d ƒ n Xd S(   s’   Switch modes for the exception handlers.

        Valid modes: Plain, Context and Verbose.

        If called without arguments, acts as a toggle.c         S  s"   t  d |  t j ƒ  d f ƒ d  S(   Ns%   Error changing %s exception modes.
%si   (   R   Rs   Rt   (   R2   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   xmode_switch_err†  s    RZ   s   Exception reporting mode:t   userN(   R?   R|   t
   capitalizeR‰   t   set_modeRF   RZ   (   R   RK   R’   R?   t   new_mode(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   xmode~  s    		c         C  s7   d d l  m } | |  j d t ƒ } t j | ƒ d S(   s    Show a quick reference sheet iÿÿÿÿ(   t   quick_referenceRN   N(   t   IPython.core.usageR˜   RT   t   TrueR   (   R   t   argR˜   t   qr(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   quickref’  s    c         C  s  |  j  } | j } | j } |  j  j } | j d } | j d t ƒ  ƒ } | j } | d t ƒ }	 | d | j ƒ | d | j	 j
 ƒ | d | j ƒ | d | j ƒ | d | j ƒ | d	 | j ƒ | d
 | j ƒ | d | j | j | j f ƒ |	 t k rcd | _ d | _ d | _ d | _ d | _ d | _ t | _ t | _ d g | _ | j d ƒ nw | j \ | _ | _ | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j d | j ƒ t d t |	 ƒ ƒ | _
 d d g | j
 }
 t d |
 ƒ d S(   s¢  Toggle doctest mode on and off.

        This mode is intended to make IPython behave as much as possible like a
        plain Python shell, from the perspective of how its prompts, exceptions
        and output look.  This makes it easy to copy and paste parts of a
        session into doctests.  It does so by:

        - Changing the prompts to the classic ``>>>`` ones.
        - Changing the exception reporting mode to 'Plain'.
        - Disabling pretty-printing of output.

        Note that IPython also supports the pasting of code snippets that have
        leading '>>>' and '...' prompts in them.  This means that you can paste
        doctests from files or docstrings (even if they have leading
        whitespace), and the code will execute correctly.  You can then use
        '%history -t' to see the translated history; this will give you the
        input after removal of all the leading prompts and whitespace, which
        can be pasted back into an editor.

        With these features, you can switch into this mode easily whenever you
        need to do testing and changes to doctests, without having to leave
        your existing IPython session.
        s
   text/plaint   doctest_modeRZ   t	   rc_pprintR—   t   rc_separate_outt   rc_separate_out2t   rc_prompts_pad_leftt   rc_separate_int   rc_active_typest   prompt_templatess   >>> s   ... R   s   xmode Plains   xmode i   Rm   Rn   s   Doctest mode is:N(   R?   R„   t   metaRo   Rp   t
   setdefaultR   t   FalseRq   R‰   RZ   t   separate_outt   separate_out2t   justifyt   separate_int   active_typest   in_templatet   in2_templatet   out_templateR]   R¥   R£   R    R¡   R¢   RŸ   R¤   R—   RD   t   intRF   (   R   RK   R?   t   pmR¦   t   disp_formatterRr   t   dstoret   save_dstoreRZ   t
   mode_label(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyRž   ™  sL    												c         C  sk   |  j  | d ƒ \ } } | d k r- d } n  y |  j j | ƒ SWn# t k
 rf } t t | ƒ ƒ n Xd S(   sš  Enable or disable IPython GUI event loop integration.

        %gui [GUINAME]

        This magic replaces IPython's threaded shells that were activated
        using the (pylab/wthread/etc.) command line flags.  GUI toolkits
        can now be enabled at runtime and keyboard
        interrupts should work without any problems.  The following toolkits
        are supported:  wxPython, PyQt4, PyGTK, Tk and Cocoa (OSX)::

            %gui wx      # enable wxPython event loop integration
            %gui qt4|qt  # enable PyQt4 event loop integration
            %gui qt5     # enable PyQt5 event loop integration
            %gui gtk     # enable PyGTK event loop integration
            %gui gtk3    # enable Gtk3 event loop integration
            %gui tk      # enable Tk event loop integration
            %gui osx     # enable Cocoa event loop integration
                         # (requires %matplotlib 1.1)
            %gui         # disable all event loop integration

        WARNING:  after any of these has been called you can simply create
        an application object, but DO NOT start the event loop yourself, as
        we have already handled that.
        R   N(   Ra   RC   R?   t
   enable_guit	   ExceptionR   RY   (   R   RK   Rc   R›   t   e(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   guiï  s     	c         C  s#   |  j  j j d } | | _ | j S(   sm  Set floating point precision for pretty printing.

        Can set either integer precision or a format string.

        If numpy has been imported and precision is an int,
        numpy display precision will also be set, via ``numpy.set_printoptions``.

        If no argument is given, defaults will be restored.

        Examples
        --------
        ::

            In [1]: from math import pi

            In [2]: %precision 3
            Out[2]: u'%.3f'

            In [3]: pi
            Out[3]: 3.142

            In [4]: %precision %i
            Out[4]: u'%i'

            In [5]: pi
            Out[5]: 3

            In [6]: %precision %e
            Out[6]: u'%e'

            In [7]: pi**10
            Out[7]: 9.364805e+04

            In [8]: %precision
            Out[8]: u'%r'

            In [9]: pi**10
            Out[9]: 93648.047476082982
        s
   text/plain(   R?   Ro   Rp   t   float_precisiont   float_format(   R   t   sRr   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt	   precision  s    *	s   -es   --exportt   defaults+  Export IPython history as a notebook. The filename argument is used to specify the notebook name and format. For example a filename of notebook.ipynb will result in a notebook name of "notebook" and a format of "json". Likewise using a ".py" file extension will write the notebook as a Python scriptt   filenamet   types   Notebook name or filenamec      	   C  s  t  j |  j | ƒ } d d l m } m } t | j ƒ | _ | j rg  } t	 |  j
 j j ƒ  ƒ } t | ƒ d k r… t d ƒ ‚ n  x: | d  D]. \ } } }	 | j | j d | d |	 ƒ ƒ q W| j d | ƒ }
 t j | j d d	 d
 ƒ } | |
 | d d ƒWd QXn  d S(   s  Export and convert IPython notebooks.

        This function can export the current IPython history to a notebook file.
        For example, to export the history to "foo.ipynb" do "%notebook -e foo.ipynb".
        To export the history to "foo.py" do "%notebook -e foo.py".
        iÿÿÿÿ(   t   writet   v4i   s   History is empty, cannot exportt   execution_countt   sourcet   cellst   wt   encodings   utf-8t   versioni   N(   R   R=   t   notebookt   nbformatRÂ   RÃ   R   RÀ   t   exportt   listR?   t   history_managert	   get_ranget   lent
   ValueErrort   appendt   new_code_cellt   new_notebookt   iot   open(   R   R½   RG   RÂ   RÃ   RÆ   t   histt   sessionRÄ   RÅ   t   nbt   f(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyRÊ   @  s    	(   R,   R7   t   __doc__R   t   argumentR   R>   R   R¨   RT   R]   R   Rl   Rq   Rˆ   R—   R   Rž   Rº   R   R¾   R   RÊ   (    (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyR8   F   s^   	CLCU",	($   RÛ   t
   __future__R    RÕ   t   jsonRs   Rq   R   t   IPython.coreR   R   t   IPython.core.errorR   t   IPython.core.magicR   R   R   R   t   IPython.utils.textR	   R
   R   t   IPython.testing.skipdoctestR   t   IPython.utils.ipstructR   t   IPython.utils.pathR   t   IPython.utils.py3compatR   t   IPython.utils.warnR   R   t   objectR   R8   (    (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/magics/basic.pyt   <module>   s"   "1