
NXc           @  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 y d d l m Z Wn! e k
 r d d l m Z n Xd d l 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 d d
 l m Z d d l m Z d d l m Z e rSd d l m Z n d d l m Z e  d  \ Z! Z" Z# d   Z$ d e% f d     YZ& d e f d     YZ' d   Z( d   Z) e* d k re j+ j, d  re j- d  n  e)   e. d  n  d S(   s  
Sphinx directive to support embedded IPython code.

This directive allows pasting of entire interactive IPython sessions, prompts
and all, and their code will actually get re-executed at doc build time, with
all prompts renumbered sequentially. It also allows you to input code as a pure
python input by giving the argument python to the directive. The output looks
like an interactive ipython section.

To enable this directive, simply list it in your Sphinx ``conf.py`` file
(making sure the directory where you placed it is visible to sphinx, as is
needed for all Sphinx directives). For example, to enable syntax highlighting
and the IPython directive::

    extensions = ['IPython.sphinxext.ipython_console_highlighting',
                  'IPython.sphinxext.ipython_directive']

The IPython directive outputs code-blocks with the language 'ipython'. So
if you do not have the syntax highlighting extension enabled as well, then
all rendered code-blocks will be uncolored. By default this directive assumes
that your prompts are unchanged IPython ones, but this can be customized.
The configurable options that can be placed in conf.py are:

ipython_savefig_dir:
    The directory in which to save the figures. This is relative to the
    Sphinx source directory. The default is `html_static_path`.
ipython_rgxin:
    The compiled regular expression to denote the start of IPython input
    lines. The default is re.compile('In \[(\d+)\]:\s?(.*)\s*'). You
    shouldn't need to change this.
ipython_rgxout:
    The compiled regular expression to denote the start of IPython output
    lines. The default is re.compile('Out\[(\d+)\]:\s?(.*)\s*'). You
    shouldn't need to change this.
ipython_promptin:
    The string to represent the IPython input prompt in the generated ReST.
    The default is 'In [%d]:'. This expects that the line numbers are used
    in the prompt.
ipython_promptout:
    The string to represent the IPython prompt in the generated ReST. The
    default is 'Out [%d]:'. This expects that the line numbers are used
    in the prompt.
ipython_mplbackend:
    The string which specifies if the embedded Sphinx shell should import
    Matplotlib and set the backend. The value specifies a backend that is
    passed to `matplotlib.use()` before any lines in `ipython_execlines` are
    executed. If not specified in conf.py, then the default value of 'agg' is
    used. To use the IPython directive without matplotlib as a dependency, set
    the value to `None`. It may end up that matplotlib is still imported
    if the user specifies so in `ipython_execlines` or makes use of the
    @savefig pseudo decorator.
ipython_execlines:
    A list of strings to be exec'd in the embedded Sphinx shell. Typical
    usage is to make certain packages always available. Set this to an empty
    list if you wish to have no imports always available. If specified in
    conf.py as `None`, then it has the effect of making no imports available.
    If omitted from conf.py altogether, then the default value of
    ['import numpy as np', 'import matplotlib.pyplot as plt'] is used.
ipython_holdcount
    When the @suppress pseudo-decorator is used, the execution count can be
    incremented or not. The default behavior is to hold the execution count,
    corresponding to a value of `True`. Set this to `False` to increment
    the execution count after each suppressed command.

As an example, to use the IPython directive when `matplotlib` is not available,
one sets the backend to `None`::

    ipython_mplbackend = None

An example usage of the directive is:

.. code-block:: rst

    .. ipython::

        In [1]: x = 1

        In [2]: y = x**2

        In [3]: print(y)

See http://matplotlib.org/sampledoc/ipython_directive.html for additional
documentation.

Pseudo-Decorators
=================

Note: Only one decorator is supported per input. If more than one decorator
is specified, then only the last one is used.

In addition to the Pseudo-Decorators/options described at the above link,
several enhancements have been made. The directive will emit a message to the
console at build-time if code-execution resulted in an exception or warning.
You can suppress these on a per-block basis by specifying the :okexcept:
or :okwarning: options:

.. code-block:: rst

    .. ipython::
        :okexcept:
        :okwarning:

        In [1]: 1/0
        In [2]: # raise warning.

ToDo
----

- Turn the ad-hoc test() function into a real test suite.
- Break up ipython-specific functionality from matplotlib stuff into better
  separated code.

Authors
-------

- John D Hunter: orignal author.
- Fernando Perez: refactoring, documentation, cleanups, port to 0.11.
- VáclavŠmilauer <eudoxos-AT-arcig.cz>: Prompt generalizations.
- Skipper Seabold, refactoring, cleanups, pure python addition
i(   t   print_functionN(   t   md5(   t
   directives(   t   nodes(   t	   Directive(   t   Config(   t   InteractiveShell(   t
   ProfileDir(   t   io(   t   PY3(   t   StringIOi   c         C  sr  g  } |  j  d  } t |  } d } d }	 x>| | k r@ Pn  | | }
 | d 7} |
 j   } | j d  r | j t |
 f  q0 n  | j d  r | }	 q0 n  | j |
  } | rt | j	 d   | j	 d  } } d d j
 d	 g t t |   d  } t |  } g  } x | | k  r| | } | j |  } | sV| j d  rZPnZ | j |  r| | } | r| d d
 k r| d } n  | d | 7} n | j |  | d 7} qW| j t |	 | d j
 |  f f  q0 n  | j |
  } | r0 t | j	 d   | j	 d  } } | | d k  rTd j
 | g | |  } n  | j t | f  Pq0 q0 | S(   s  
    part is a string of ipython text, comprised of at most one
    input, one output, comments, and blank lines.  The block parser
    parses the text into a list of::

      blocks = [ (TOKEN0, data0), (TOKEN1, data1), ...]

    where TOKEN is one of [COMMENT | INPUT | OUTPUT ] and
    data is, depending on the type of token::

      COMMENT : the comment string

      INPUT: the (DECORATOR, INPUT_LINE, REST) where
         DECORATOR: the input decorator (or None)
         INPUT_LINE: the input as string (possibly multi-line)
         REST : any stdout generated by the input line (not OUTPUT)

      OUTPUT: the output string, possibly multi-line

    s   
i    i   t   #t   @i   s      %s:t    t   .t    N(   t   splitt   lent   Nonet   stript
   startswitht   appendt   COMMENTt   matcht   intt   groupt   joint   strt   INPUTt   OUTPUT(   t   partt   rgxint   rgxoutt   fmtint   fmtoutt   blockt   linest   Nt   it	   decoratort   linet   line_strippedt   matchint   linenot	   inputlinet   continuationt   Nct   restt   nextlinet   matchoutt   output(    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   block_parser   sZ    

%*

%%t   EmbeddedSphinxShellc           B  s   e  Z d  Z d d  Z d   Z d   Z e d  Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z RS(   s1   An embedded IPython instance to run inside Sphinxc   	      C  sa  t    |  _ | d  k r! g  } n  t   } t | j _ t | j _ d | j _ t	 j
 d d  } d } t j j | |  } t j |  } t j d | d |  } t j |  j  |  j t _ |  j t _ | |  _ |  j j |  _ |  j j |  _ d |  _ d |  _ | |  _ t |  _ t |  _ t |  _ d  |  _  t |  _! x! | D] } |  j" | d t q@Wd  S(	   Nt   NoColort   prefixt   profile_t   auto_profile_sphinx_buildt   configt   profile_dirR   t   store_history(#   R
   t   coutR   R   t   FalseR   t   autocallt
   autoindentt   colorst   tempfilet   mkdtempt   ost   pathR   R   t   create_profile_dirt   instancet   atexitt   registert   cleanupR   t   stdoutt   stderrt   IPt   user_nst   user_global_nst   inputR2   t   tmp_profile_dirt   is_verbatimt
   is_doctestt   is_suppresst	   directivet   _pyplot_importedt   process_input_line(	   t   selft
   exec_linesR9   RP   t   profnamet   pdirt   profileRL   R(   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   __init__  s8    											c         C  s   t  j |  j d t d  S(   Nt   ignore_errors(   t   shutilt   rmtreeRP   t   True(   RW   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyRI   T  s    c         C  s$   |  j  j d  |  j  j d  d  S(   Ni    (   R<   t   seekt   truncate(   RW   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt
   clear_coutW  s    c         C  sz   t  j } |  j j } zT |  j t  _ | j |  | j   } | sh | j   } |  j j | d | n  Wd | t  _ Xd S(   s#   process the input, capturing stdoutR;   N(	   t   sysRJ   RL   t   input_splitterR<   t   pusht   push_accepts_moret	   raw_resett   run_cell(   RW   R(   R;   RJ   t   splittert   moret
   source_raw(    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyRV   [  s    	c         C  s   |  j  } |  j } | j d  } | d } t j j t j j | |  |  } d | g } xV | d D]J } | j d  \ }	 }
 |	 j   }	 |
 j   }
 | j d |	 |
 f  qg Wt j j	 |  } d j |  } | | f S(   s   
        # build out an image directive like
        # .. image:: somefile.png
        #    :width 4in
        #
        # from an input like
        # savefig somefile.png width=4in
        R   i   s   .. image:: %si   t   =s
      :%s: %ss   
(
   t   savefig_dirt
   source_dirR   RC   RD   t   relpathR   R   R   t   basename(   RW   R'   Rn   Ro   t   saveargst   filenamet   outfilet	   imagerowst   kwargt   argt   valt
   image_filet   image_directive(    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   process_imagej  s    			
	c         C  s  | \ } } } d } d } | d k p- |  j }	 | d k	 rK | j d  pQ |  j }
 | d k pf |  j } | d k p{ |  j } | d k p |  j } | d k	 o | j d  } | j d  } t |  d k r | d	 d
 k r | j	 d
  q n  d d
 j
 d g t t |   d  } | r:|  j |  \ } } n  g  } t } | r^|  j r^t } n t } t j d t   } x t |  D] \ } } | j d  rt } n  | d k r|	 r|  j d
  |  j j d 7_ n |  j | d | d | | f } n, |	 s |  j | d | n  d | | f } | s| j	 |  qqWWd QX| rt | j    r|	 r| j	 |  n  |  j j d  |  j j   } | r| r| j	 |  n | r| j	 d
  n  d } d } |  j j r|  j j j j } |  j j j j } n  | rd | k rd | | f } | d 7} t  j! j" d d d  t  j! j" |  t  j! j" |  t  j! j" d d d d  n  | s_x | D] } d | | f } | d 7} t  j! j" d d d  t  j! j" |  t  j! j" d d d  t j# | j$ | j% | j& | j' | j(  } t  j! j" |  t  j! j" d d d d  qWn  |  j j) d  | | | |
 | | | f S(    s6   
        Process data block for INPUT token.

        s	   @verbatims   @doctests	   @suppresss	   @okexcepts
   @okwarnings   @savefigs   
i   iR   s      %s:R   i   t   recordt   ;i    R;   s   %s %sNt   Unknownt	   Tracebacks,   
Exception in %s at block ending on line %s
sP   Specify :okexcept: as an option in the ipython:: block to suppress this message
s   

>>>t   -iI   s   <<<s   

s*   
Warning in %s at block ending on line %s
sQ   Specify :okwarning: as an option in the ipython:: block to suppress this message
iL   (*   R   RQ   R   RR   RS   t   is_okexceptt   is_okwarningR   R   R   R   R   R{   R=   t
   hold_countR`   t   warningst   catch_warningst	   enumeratet   endswithRV   RL   t   execution_countR   R<   Ra   t   readRT   t   statet   documentt   current_sourcet   current_lineRd   RJ   t   writet   formatwarningt   messaget   categoryRs   R+   R(   Rb   (   RW   t   datat   input_promptR+   R'   RO   R/   Ry   Rz   RQ   RR   RS   R   R   t
   is_savefigt   input_linesR-   t   rett   is_semicolonR;   t   wsR&   R(   t   formatted_linet   processed_outputRs   t   st   w(    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   process_input  s    *		)

#	c      	   C  s  d } | r| d k	 r| }	 |	 j   }	 | j   }
 |  j d k rT d } d } nD |  j j j j } |  j j } d j g  | D] } | | ^ q  } |	 j |  } | d k  r d } | j	 | | d j |  t
 |	  d | } t |   n  |	 t |  j   }	 | j   d k rw|	 |
 k rd	 } | j	 | | d j |  t
 |	  t
 |
  d | } t |   qq|  j | | |	 |
  n  g  } | d
 k p|  j } | r| j   r| j d j	 | |   n  | S(   s7   
        Process data block for OUTPUT token.

        R   i   t   Unavailables   
i    s   output does not contain output prompt

Document source: {0}

Raw content: 
{1}

Input line(s):
{TAB}{2}

Output line(s):
{TAB}{3}

t   TABs   @doctests   doctest failure

Document source: {0}

Raw content: 
{1}

On input line(s):
{TAB}{2}

we found output:
{TAB}{3}

instead of the expected:
{TAB}{4}

s	   @verbatims   {0} {1}
s       N(   R   R   RT   R   R   R   t   contentR   t   findt   formatt   reprt   RuntimeErrorR   t   custom_doctestRQ   R   (   RW   R   t   output_promptR   R2   RR   R'   Ry   R   t   foundt	   submittedt   sourceR   R(   t   indt   et   out_dataRQ   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   process_output#  s<    		&c         C  s   |  j  s | g Sd S(   s'   Process data fPblock for COMMENT token.N(   RS   (   RW   R   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   process_comments  s    	c         C  s   |  j    d | } |  j d d t |  j d d t |  j | d t |  j d d t |  j d d t |  j   d S(   s/   
        Saves the image file to disk.
        s   plt.gcf().savefig("%s")s   bookmark ipy_thisdirR;   s   cd -b ipy_savedirs   cd -b ipy_thisdirs   bookmark -d ipy_thisdirN(   t   ensure_pyplotRV   R=   Rc   (   RW   Ry   t   command(    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt
   save_imagex  s    

c      	   C  s  g  } d } d } |  j j } |  j | } |  j | } d } d }	 t }
 x| D]\ } } | t k r{ |  j |  } nX| t k r t	 }
 |  j
 | | |  \ } } } } } } }	 n| t k r|
 sd } d } d } d } |  j rF|  j j j j } |  j j j j } |  j j } d j g  | D] } | | ^ q* } n  d } | j | | | | d | } t j j |  t d   n  |  j | | | | | | |  } | r| d	 d
 k st  | d	 =qn  | rQ | j |  qQ qQ W| d k	 r	|  j |  n  | |	 f S(   sZ   
        process block from the block_parser and return a list of processed lines
        R   i   i    R   s   
s   

Invalid block: Block contains an output prompt without an input prompt.

Document source: {0}

Content begins at line {1}: 

{2}

Problematic block within content: 

{TAB}{3}

R   s   An invalid block was detected.iR   Ns       (   R   RL   R   t   promptint	   promptoutR=   R   R   R   R`   R   R   RT   R   R   R   R   R   R   R   Rd   RJ   R   R   R   t   AssertionErrort   extendR   (   RW   R#   R   R2   R   R+   R   R   Ry   Rz   t   found_inputt   tokenR   R   RR   R'   R   t
   linenumberR   R   R(   R   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   process_block  sR    -	)		c         C  sW   |  j  sS d t j k r4 d d l } | j d  n  |  j d d t t |  _  n  d S(   s   
        Ensures that pyplot has been imported into the embedded IPython shell.

        Also, makes sure to set the backend appropriately if not set already.

        s   matplotlib.backendsiNt   aggs   import matplotlib.pyplot as pltR;   (   RU   Rd   t   modulest
   matplotlibt   useRV   R=   R`   (   RW   R   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyR     s    	c         C  s  g  } t  } t  } d } |  j } d } xt |  D]t\ } }	 |	 j   }
 t |	  sk | j |	  q4 n  |
 j d  r | j |	 g  d |	 k r4 t	 } q4 q4 n  |
 j d  r | j |	 g  q4 n  d d j
 d g t t |   d  } | sfd	 | | |
 f } | j |  | d
 7} y t j |
  | j d  Wqrt k
 rbt	 } | } qrXnd	 | |	 f } | j |  t |  | d
 k r| | d
 } t |  t | j    d k rq4 qn  y t j d j
 | | | d
 !  } t | j d t j  rJxI | j d j D]! } t | t j  r"t  } q"q"Wn | j d  t  } Wn t k
 rqn X| r4 |  j   |  j d d t  |  j   t  } q4 q4 W| S(   s  
        content is a list of strings. it is unedited directive content

        This runs it line by line in the InteractiveShell, prepends
        prompts as needed capturing stderr and stdout, then returns
        the content as a list as if it were ipython code
        i    R   t   savefigR   u      %s:R   R   i   u   %s %si   u    i   s   
s	   plt.clf()R;   N(   R=   R   R   R   R   R   R   R   R   R`   R   R   t   astt   parset	   Exceptiont   lstript
   isinstancet   bodyt   FunctionDeft   ReturnR   RV   Rc   (   RW   R   R2   R   t	   multilinet   multiline_startR!   t   ctR+   R(   R)   R-   t   modifiedR0   t   modt   element(    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   process_pure_python  sj    		*
"	


c   	      C  sn   d d l  m } | j   } | d } | | k rO | | |  | | | |  n d j |  } t |   d S(   s1   
        Perform a specialized doctest.

        i   (   t   doctestss   Invalid option to @doctest: {0}N(   t   custom_doctestsR   R   R   R   (	   RW   R'   R   R   R   R   t   argst   doctest_typeR   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyR   4  s    
N(   t   __name__t
   __module__t   __doc__R   R\   RI   Rc   R`   RV   R{   R   R   R   R   R   R   R   R   (    (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyR4     s   =					P			F		Nt   IPythonDirectivec           B  s   e  Z e Z d  Z d Z e Z i e j d 6e j	 d 6e j	 d 6e j	 d 6e j	 d 6e j	 d 6Z
 d Z e   Z d   Z d	   Z d
   Z d   Z RS(   i    i   t   pythont   suppresst   verbatimt   doctestt   okexceptt	   okwarningc      	   C  s   |  j  j j j j } |  j  j j j j j } | j } t j	 j
 |  j  j j  } | d  k ri | j } n  t | t  r | d } n  t j	 j | |  } | j } | j } | j } | j } | j }	 | j }
 | j } | | | | | | |	 |
 | f	 S(   Ni    (   R   R   t   settingst   envR9   t   appt   confdirt   ipython_savefig_dirRC   RD   t   dirnameR   R   t   html_static_pathR   t   listR   t   ipython_rgxint   ipython_rgxoutt   ipython_promptint   ipython_promptoutt   ipython_mplbackendt   ipython_execlinest   ipython_holdcount(   RW   R9   R   Rn   Ro   R   R    R   R   t
   mplbackendRX   R   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   get_config_optionsV  s$    								c      	   C  si  |  j    \	 } } } } } } } } }	 |  j d  k rv | rX d d  l }
 |
 j |  n  t |  |  _ |  |  j _ n  |  j j j	 |  j
 k r |  j j j j   d |  j j _ d |  j j j _ |  j
 j |  j j j	  n  | |  j _ | |  j _ | |  j _ | |  j _ | |  j _ | |  j _ |	 |  j _ |  j j d | d t |  j j   | | | | f S(   Nii   i    s   bookmark ipy_savedir %sR;   (   R   t   shellR   R   R   R4   RT   R   R   R   t	   seen_docsRL   t   history_managert   resetR   t   prompt_managert   widtht   addR   R    R   R   Rn   Ro   R   RV   R=   Rc   (   RW   Rn   Ro   R   R    R   R   R   RX   R   R   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   setupp  s.    'c         C  s'   |  j  j d d t |  j  j   d  S(   Ns   bookmark -d ipy_savedirR;   (   R   RV   R=   Rc   (   RW   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   teardown  s    c         C  s/  t  } |  j   \ } } } } |  j } d | k |  j _ d | k |  j _ d | k |  j _ d | k |  j _ d | k |  j _ d |  j	 k r |  j
 } |  j j |  |  _
 n  d j |  j
  j d  } d	 d
 g }	 g  }
 x | D] } t | | | | |  } t |  r |  j j |  \ } } x@ | D]8 } |	 j g  | j d  D] } d j |  ^ qJ q.W| d  k	 r|
 j |  qq q Wx> |
 D]6 } |	 j d
  |	 j | j d   |	 j d
  qWt |	  d k r!| rt d j |	   q!|  j j |	 |  j j j d   n  |  j   g  S(   NR   R   R   R   R   R   s   
s   

s   .. code-block:: ipythonR   s      {0}i   i    (   R=   R   t   optionsR   RS   RR   RQ   R   R   t	   argumentsR   R   R   R   R3   R   R   R   R   R   R   t   printt   state_machinet   insert_inputR   R   R   (   RW   t   debugR   R    R   R   R   R   t   partsR$   t   figuresR   R#   t   rowst   figuret   rowR(   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   run  sD    			-	
N(   R   R   R`   t   has_contentt   required_argumentst   optional_argumentst   final_argumuent_whitespaceR   t	   unchangedt   flagt   option_specR   R   t   setR   R   R   R   R  (    (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyR   D  s    



			0	c         C  s   |  t  _ |  j d t  |  j d d  d  |  j d t j d  d  |  j d t j d  d  |  j d d	 d  |  j d
 d d  |  j d d d  d d g } |  j d | d  |  j d t d  d  S(   Nt   ipythonR   R   R   s   In \[(\d+)\]:\s?(.*)\s*R   s   Out\[(\d+)\]:\s?(.*)\s*R   s   In [%d]:R   s   Out[%d]:R   R   s   import numpy as nps   import matplotlib.pyplot as pltR   R   (	   R   R   t   add_directiveR   t   add_config_valueR   t   ret   compileR`   (   R   t	   execlines(    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyR     s    			c          C  s   d d d d d d d d g }  |  d	 }  t    } xW |  D]O } | j d
  } t d d d  d | d | d d d d  d d  d d  d d  q8 Wd  S(   Ns6  
In [9]: pwd
Out[9]: '/home/jdhunter/py4science/book'

In [10]: cd bookdata/
/home/jdhunter/py4science/book/bookdata

In [2]: from pylab import *

In [2]: ion()

In [3]: im = imread('stinkbug.png')

@savefig mystinkbug.png width=4in
In [4]: imshow(im)
Out[4]: <matplotlib.image.AxesImage object at 0x39ea850>

s   

In [1]: x = 'hello world'

# string methods can be
# used to alter the string
@doctest
In [2]: x.upper()
Out[2]: 'HELLO WORLD'

@verbatim
In [3]: x.st<TAB>
x.startswith  x.strip
s6  

In [130]: url = 'http://ichart.finance.yahoo.com/table.csv?s=CROX\
   .....: &d=9&e=22&f=2009&g=d&a=1&br=8&c=2006&ignore=.csv'

In [131]: print url.split('&')
['http://ichart.finance.yahoo.com/table.csv?s=CROX', 'd=9', 'e=22', 'f=2009', 'g=d', 'a=1', 'b=8', 'c=2006', 'ignore=.csv']

In [60]: import urllib

s  \

In [133]: import numpy.random

@suppress
In [134]: numpy.random.seed(2358)

@doctest
In [135]: numpy.random.rand(10,2)
Out[135]:
array([[ 0.64524308,  0.59943846],
       [ 0.47102322,  0.8715456 ],
       [ 0.29370834,  0.74776844],
       [ 0.99539577,  0.1313423 ],
       [ 0.16250302,  0.21103583],
       [ 0.81626524,  0.1312433 ],
       [ 0.67338089,  0.72302393],
       [ 0.7566368 ,  0.07033696],
       [ 0.22591016,  0.77731835],
       [ 0.0072729 ,  0.34273127]])

st   
In [106]: print x
jdh

In [109]: for i in range(10):
   .....:     print i
   .....:
   .....:
0
1
2
3
4
5
6
7
8
9
s   

In [144]: from pylab import *

In [145]: ion()

# use a semicolon to suppress the output
@savefig test_hist.png width=4in
In [151]: hist(np.random.randn(10000), 100);


@savefig test_plot.png width=4in
In [151]: plot(np.random.randn(10000), 'o');
   s   
# use a semicolon to suppress the output
In [151]: plt.clf()

@savefig plot_simple.png width=4in
In [151]: plot([1,2,3])

@savefig hist_simple.png width=4in
In [151]: hist(np.random.randn(10000), 100);

s~  
# update the current fig
In [151]: ylabel('number')

In [152]: title('normal distribution')


@savefig hist_with_text.png
In [153]: grid(True)

@doctest float
In [154]: 0.1 + 0.2
Out[154]: 0.3

@doctest float
In [155]: np.arange(16).reshape(4,4)
Out[155]:
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])

In [1]: x = np.arange(16, dtype=float).reshape(4,4)

In [2]: x[0,0] = np.inf

In [3]: x[0,1] = np.nan

@doctest float
In [4]: x
Out[4]:
array([[ inf,  nan,   2.,   3.],
       [  4.,   5.,   6.,   7.],
       [  8.,   9.,  10.,  11.],
       [ 12.,  13.,  14.,  15.]])


        i   s   
R   R   R   R   R+   i    t   content_offsett
   block_textR   R   (   t   dictR   R   R   (   t   examplesR   t   exampleR   (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   test  s     &	
	t   __main__t   _statics!   All OK? Check figures in _static/(/   R   t
   __future__R    RG   RC   R  Rd   RA   R   R   R^   t   hashlibR   t   ImportErrort   sphinxt   docutils.parsers.rstR   t   docutilsR   t   sphinx.util.compatR   t   traitlets.configR   t   IPythonR   t   IPython.core.profiledirR   t   IPython.utilsR   t   IPython.utils.py3compatR	   R
   t   rangeR   R   R   R3   t   objectR4   R   R   R  R   RD   t   isdirt   mkdirR   (    (    (    s[   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/ipython_directive.pyt   <module>y   sL   	h  2		