ó O;Mc@sÊddlZddlZddlZddlZddlZddlZddlZddlZddlm Z yddl m Z Wn!e k r§ddl m Z nXddl mZddlZejjdƒZeged D]"Zeejdeƒdƒ^qäƒZed ƒ\ZZZejd ƒZejd ƒZd Zd Zd„Zddl Z e j!dƒddd„ƒYZ"e"ƒZ#d„Z$e%e$_&d„Z'd„Z(e)dkrÆe(ƒndS(iÿÿÿÿN(tMatplotlibShell(tmd5(t directivest.is[a-z]iisIn \[(\d+)\]:\s?(.*)\s*sOut\[(\d+)\]:\s?(.*)\s*sIn [%d]:sOut[%d]:cCsIg}|jdƒ}t|ƒ}d}d }x||kr@Pn||}|d7}|jƒ}|jdƒrˆ|jt|fƒq0n|jdƒr£|}q0ntj|ƒ}|rÄt |j dƒƒ|j dƒ} } ddj d gtt | ƒƒdƒ} t| ƒ} g} x}||kr˜||}t j|ƒ}|sV|jdƒrZPn1|j| ƒr~| d|| 7} n | j|ƒ|d7}qW|jt|| dj | ƒffƒq0nt j|ƒ}|r0t |j dƒƒ|j dƒ} }||dkr+dj |g||ƒ}n|jt|fƒPq0q0|S( s” part is a string of ipython text, comprised of at most one input, one ouput, 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 iit#t@is %s:tRN(tsplittlentNonetstript startswithtappendtCOMMENTtrgxintmatchtinttgrouptjointstrtrgxouttINPUTtOUTPUT(tparttblocktlinestNtit decoratortlinet line_strippedtmatchintlinenot inputlinet continuationtNctresttnextlinetmatchouttoutput((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyt block_parsersT     %*   %%tAggtEmbeddedSphinxShellcBs,eZd„Zd„Zd„Zd„ZRS(c Csôtjƒ|_|jtjj_|jtjj_ddg}i|_i|_tj j ||j|jdt dt dt ddƒƒ|_d|_d|_t|_t|_t|_t|_|jd ƒ|jjd ƒ|jjd ƒdS( Ns -autocallt0tembeddedt shell_classt rc_overridetcolorstNoColorRsbookmark ipy_basediri(t cStringIOtStringIOtcouttIPythontShelltTermtcerrtuser_nstuser_glocal_nstipmakert make_IPythontTrueRtdicttIPtinputR'tFalset is_verbatimt is_doctestt is_suppresst_pyplot_importedt process_inputtseekttruncate(tselftargv((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyt__init__‡s&           cCsAtj}|jt_|jj|jj|dƒƒ|t_dS(s#process the input, capturing stdoutiN(tsyststdoutR3R>tpusht prefilter(RHRRL((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyRE¨s  c% CsÂg}d}d}tjt|jjjƒjƒƒ}t|j dƒƒ}t |}t |}d} d} xÓ|D]Ë\} } | t kr¦|j s=|j| ƒq=qr| tkrh| \} }}| dkpÓ|j}| dkpè|j}| dkpý|j }| dk o| jdƒ}|jdƒ}ddjd gtt|ƒƒd ƒ}t|ƒ}|r| jd ƒ}|d}tjjd |ƒ}d |g}xV|d D]J}|jdƒ\}}|jƒ}|jƒ}|jd||fƒq­W|} dj|ƒ} nt}x°t|ƒD]¢\}}|jdƒrJt}n|dkrŒ|rl|jdƒn |j|ƒd||f} n&|s¢|j|ƒnd||f} |s&|j| ƒq&q&W|st|jƒƒr|r|jd|ƒ|jdƒqqn|jjdƒ|jjƒ}| rU| rU| rU|j|ƒn|jj dƒqr| t!krr|rždt || f}|j|ƒn|r=| jƒ}!|}"|"dk r:|"j"|ƒ}#|#dkröt#d||"fƒ‚n|"t|ƒjƒ}"|"|!kr7t#d||"|!fƒ‚q7q:q=qrqrW| dk r¸|j$ƒd| }$|jdƒ|jdƒ|j|$ƒ|jdƒ|jjdƒ|jj dƒn|| fS(sZ process block from the block_parser and return a list of processed lines is @verbatims@doctests @suppresss@savefigs s %s:RRit s _static/%ss .. image:: %st=s :%s: %st;is%s %ss%ss%s %s s-output prompt="%s" does not match out line=%ssUdoctest failure for input_lines="%s" with found_output="%s" and submitted output="%s"splt.gcf().savefig("%s")sbookmark ipy_thisdirscd -b ipy_basedirscd -b ipy_thisdirN(%R RRRR>t outputcachetprompt1R RRtfmtintfmtoutR RCR RRARBR RRRtostpathR@t enumeratetendswithR<RER3RFtreadRGRtfindt RuntimeErrort insure_pyplot(%RHRtretR't input_linestmR t input_promptt output_promptt image_filetimage_directivettokentdataRR?R$RARBRCt is_savefigR"R#tsaveargstfilenametoutfilet imagerowstkwargtargtvalt is_semicolonRRtformatted_linet submittedtfoundtindtcommand((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyt process_block³s¤$     *             )       cCs|jr dS|jdƒdS(Nsimport matplotlib.pyplot as plt(RDRE(RH((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyR]Fs (t__name__t __module__RJRERuR](((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyR*…s ! “c Cs‘tj} |jdƒt_|jdƒt_|jdƒt_dj|ƒjdƒ} ddg} g} x˜| D]} t | ƒ}t |ƒrptj |ƒ\}}x;|D]3}| j g|jdƒD]}d|^qƃqªW|dk r| j|ƒqqpqpWx>| D]6}| jdƒ| j |jdƒƒ| jdƒq Wt | ƒd kr| rndj| ƒGHq|j| |jjd ƒƒngS( Ntsuppresstdoctesttverbatims s s.. sourcecode:: ipythonRs %sii(tipython_directivetDEBUGthas_keytshellRCRBRARRR(RRutextendR R t insert_inputR_tsource(tnamet argumentstoptionstcontentR tcontent_offsett block_texttstatet state_machinetdebugtpartsRtfiguresRRtrowstfiguretrowR((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyR{Ps2      1   cCsJ|t_itjd6tjd6tjd6}|jdttd|dS(NRxRyRztipythonii(iii(tsetuptappRtflagt add_directiveR{R<(R’R„((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyR‘{s     cCs—ddddddddd d d g }tt_tƒ}xW|D]O}|jd ƒ}td ddd|d|ddddddddddƒq@WdS(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]: 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 x.startswith x.strip sV 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('&') --------> 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]: np.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]]) s‰ In [106]: print x --------> 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) sG In [239]: 1/2 @verbatim Out[239]: 0 In [240]: 1.0/2.0 Out[240]: 0.5 s5 @verbatim In [6]: pwd Out[6]: '/home/jdhunter/mypy' s? @verbatim In [151]: myfile.upper? Type: builtin_function_or_method Base Class: String Form: Namespace: Interactive Docstring: S.upper() -> string Return a copy of the string S converted to uppercase. s RŠRƒR„R…R iR†R‡RˆR‰(R<R{R|R=RR (texamplesR„texampleR…((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyttest‡s&          t__main__((*RKRVtshutiltimptwarningsR1treR4t IPython.ShellRthashlibRt ImportErrortdocutils.parsers.rstRtsphinxt __version__Rtsphinx_versionttupletxRtrangeR RRtcompileRRRTRUR(t matplotlibtuseR*R~R{R@R|R‘R—Rv(((sY/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/sphinxext/ipython_directive.pyts6T   3 d  È  )  ¯