• File: doctest_webapp.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyc
  • Date Modified: 08/01/2016 7:39 PM
  • File size: 14.79 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

|Wc
@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZej
jeZej
jej
jej
jeZdZdZedZdZd	Zded
dZdadadZd
ZdZdZ dZ!dZ"dZ#dddZ$dZ%dZ&dZ'dej(fdYZ)e*dkrej+drej+ddkrej,ej-neej
krej
j.enxej+dD]Z/ej
je/Z/e/e_0ej1e/dedej2ej3Bde)ej
j4e/d
dZ5e5e/ks~t6ej7d e/e5fqWndS(!s>
These are functions for use when doctest-testing a document.
iN(tStringIO(t
PySourceColorcCst|}|r|GHndS(N(trun_raw(tcommandtdata((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytrunsc
Cstj|dtdtjdtjdt}|jj}|jx,|j	dsj|j	drw|d }qLW|rdj
g|jD]}|r|^q}|SdSd	S(
s6
    Runs the string command, returns any output.
    tshelltstderrtstdouttenvs
s
itN(t
subprocesstPopentTruetSTDOUTtPIPEt	_make_envRtreadtwaittendswithtjoint
splitlines(RtprocRtl((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyRs	
!(cCsMt|}d||f}td|ddd||rI|rI|GHndS(Ns$ %s
%ss
shell-commandtdescriptionsshell transcriptR(Rt	show_file(Rtnamet	and_printtoutputR((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytrun_command1scCs~tjj}|jdddtjjtddtjjtdddd|d<|jdddt|d<|S(	NtPATHR
t:tscriptstpastes	3rd-partyssqlobject-filest
PYTHONPATH(tostenvirontcopytgettpathRtpaste_parent(R	((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyR9s
<cCstj|tdS(s.
    Clears (deletes) the given directory
    N(tshutiltrmtreeR
(tdir((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyt	clear_dirFsicCs|ptj}tj|}|jx|D]}tjj||}tjj|rl|d}nd||GHtjj|r2|r2td|dtd|dq2q2WdS(s"
    Show a directory listing
    t/t R+trecursetindentiN(	R#tgetcwdtlistdirtsortR'RtisdirtlsR
(R+R/R0tfnstfntfull((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyR5Ls



cCs|a|adS(N(tdefault_apptdefault_url(tappturl((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytset_default_app^scCsGtjjtjjtjdtjjtjjtjd|S(sj
    Returns the filename of the resource -- generally in the directory
    resources/DocumentName/fn
    t	resourcesi(R#R'Rtdirnametsysttesting_document_filenametsplitexttbasename(R7((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytresource_filenameds
	"cCst|d}t}tdk	s1tdt|}|jd||f|jdtjdddd|gd	tj	d
tj	dt
}|j\}}t|}tj
|}|j}	x|jD]\}
}|
jdkrt|jd
dkrqn|
jdkr7qn|
jdkr^|jdr^qn|jd|
|fqWg|	jD]}|jr|^q}
x|
D]}|j|dqW|r|jd|n|jd|j}tjj|s4t|d}|j||jnjt|d}|j}|jt||sd|GHddGH|GHddGHdGHddGH|GHndS(Ns.htmlsNo default_app sets9<span class="doctest-url"><a href="%s">%s</a></span><br>
s<div class="doctest-example">
tpastersserve--server=consoles--no-verboses--url=RRR	tstatusiiscontent-typescontent-lengths
set-cookiet_SID_s/<span class="doctest-header">%s: %s</span><br>
s
s$<pre class="doctest-errors">%s</pre>s</div>
twbtrbs'Pages did not match.  Expected from %s:t-i<t=sActual output:(scontent-typescontent-length(RDRR9tNonetAssertionErrorR:twriteRRRRtcommunicatetrfc822tMessageRtitemstlowertinttsplitt
startswithRtstriptgetvalueR#R'texiststopentclosethtml_matches(t	path_infotexample_nameR7toutR<RRterrorstheaderstcontenttheadertvalueRtlinestlinetresulttftexpected((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytshowosf		
	
	
		.	+
	



				cCsPtj|}|jdd}tjdd|}d|}tj||S(Ns\.\.\.s.*s0x[0-9a-f]+s^%s$(tretescapetreplacetsubtsearch(tpatternttexttregex((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyR\s

cCs|jdr|d}n|j}g}x=|D]5}|jdkr]|jdq5|j|q5Wdj|d}|S(Ns
it.R
(RVRtrstriptappendR(RRet	new_linesRf((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytconvert_docstring_strings

cCs*t|}t||t||dS(N(Rwt
write_dataR(R'tversionR((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytcreate_files
cCst|}t|d}|j||j|jdrp|d}tjj|rptj|qpnt	||dd|d|dS(Ntas.pytcRsadded to %sR(
RwRZRNR[RR#R'RYtunlinkR(R'RyRRhtpyc_file((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytappend_to_files


cCstjj|d}|dkrJt|d}|j}|jn|dkrrdtj|tj	}ndt
j|d}d|p||f}tt
d||f|dS(NiRIs.pys!<div class="source-code">%s</div>s!<pre class="source-code">%s</pre>s-<span class="source-filename">%s</span><br>%ss%s.%s.gen.html(R#R'RBRLRZRR[Rtstr2htmltdarktcgiRlRxRD(R'RyRRtextRhthtml((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyRs
cCsZtjddddd|gdtdtj}|j|\}}|}|j|S(Nssource-highlights--out-format=htmls--no-docs
--css=nones
--src-lang=%sRR(RRtFalseRROR(tinputtformatRRRRg((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytcall_source_highlights
cCsjtjjtjj|}tjj|s@tj|nt|d}|j||jdS(NRH(	R#R'R?tabspathRYtmakedirsRZRNR[(R'RR+Rh((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyRxs
cCsttjj|d}|j}|jxh|D]`\}}}|dkrf|g|||+q8|dkrg|||+q8ds8td|q8Wt|d}|jdj||jdS(NRItinserttdeleteisUnknown change_type: %rRHR
(	RZR#R'Rt	readlinesR[RMRNR(R'tchangesRhRetchange_typeRfRq((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytchange_files
	tLongFormDocTestParsercBs?eZdZejdejejBZdZddZ	RS(s
    This parser recognizes some reST comments as commands, without
    prompts or expected output, like:

    .. run:

        do_this(...
        ...)
    s
        # Source consists of a PS1 line followed by zero or more PS2 lines.
        (?: (?P<source>
                (?:^(?P<indent> [ ]*) >>>    .*)    # PS1 line
                (?:\n           [ ]*  \.\.\. .*)*)  # PS2 lines
            \n?
            # Want consists of any non-blank lines that do not start with PS1.
            (?P<want> (?:(?![ ]*$)    # Not a blank line
                         (?![ ]*>>>)  # Not a line starting with PS1
                         .*$\n?       # But any other line
                      )*))
        | 
        (?: # This is for longer commands that are prefixed with a reST
            # comment like '.. run:' (two colons makes that a directive).
            # These commands cannot have any output.

            (?:^\.\.[ ]*(?P<run>run):[ ]*\n) # Leading command/command
            (?:[ ]*\n)?         # Blank line following
            (?P<runsource>
                (?:(?P<runindent> [ ]+)[^ ].*$)
                (?:\n [ ]+ .*)*)
            )
        |
        (?: # This is for shell commands

            (?P<shellsource>
                (?:^(P<shellindent> [ ]*) [$] .*)   # Shell line
                (?:\n               [ ]*  [>] .*)*) # Continuation
            \n?
            # Want consists of any non-blank lines that do not start with $
            (?P<shellwant> (?:(?![ ]*$)
                              (?![ ]*[$]$)
                              .*$\n?
                           )*))
        c	Cs|jdpd}t|jd|}|jd|jd}|rq|j|dd|||n8|j|||||j|dd|d	|||rdjg|D]}||^q}n*djg|D]}||d
^q}|rd}	d}
n|jd}	|	jd}t|dkrgtjd|d
rg|d
=n|j|d|||t|djg|D]}||^q}	|j	j|	}|r|jd}
nd}
|j
|||}
||
|	|
fS(s?
        Given a regular expression match from `_EXAMPLE_RE` (`m`),
        return a pair `(source, want)`, where `source` is the matched
        example's source code (with prompts and indentation stripped);
        and `want` is the example's expected output (with indentation
        stripped).

        `name` is the string's name, and `lineno` is the line number
        where the example starts; both are used for error messages.

        >>> def parseit(s):
        ...     p = LongFormDocTestParser()
        ...     return p._parse_example(p._EXAMPLE_RE.search(s), '<string>', 1)
        >>> parseit('>>> 1\n1')
        ('1', {}, '1', None)
        >>> parseit('>>> (1\n... +1)\n2')
        ('(1\n+1)', {}, '2', None)
        >>> parseit('.. run:\n\n    test1\n    test2\n')
        ('test1\ntest2', {}, '', None)
        RR
s%sindents%ssources
iR.iRsitwants *$itmsgN(tgrouptlenRUt
_check_prefixt_check_prompt_blankRRLRktmatcht
_EXCEPTION_REt
_find_options(tselftmRtlinenotrunnerR0tsource_linestsltsourceRtexc_msgt
want_linestwltoptions((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyt_parse_example2s4!")*	(
&s<string>c
Cs|j}|j|}|dkrYdjg|jdD]}||^q=}ng}d\}}x|jj|D]}|j|||j!||jd||j7}|j	|||\}	}
}}|j
|	s@|jtj|	||d|d|t
|jdp,|jdd|
n||jd|j|j7}|j}q~W|j|||S(s=
        Divide the given string into examples and intervening text,
        and return them as a list of alternating Examples and strings.
        Line numbers for the Examples are 0-based.  The optional
        argument `name` is a name identifying this string, and is only
        used for error messages.
        is
RR0t	runindentR(ii(t
expandtabst_min_indentRRUt_EXAMPLE_REtfinditerRutstarttcountRt_IS_BLANK_OR_COMMENTtdoctesttExampleRRtend(
RtstringRt
min_indentRRtcharnoRRRRRR((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pytparsets(2!(
%(
t__name__t
__module__t__doc__Rktcompilet	MULTILINEtVERBOSERRR(((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyRs

"	Bt__main__iRtmodule_relativetoptionflagstparsers.htmlsrst2html.py %s > %s(8RRRR#R@R)RkRRPt	cStringIORt
paste.utilRR'Rt__file__thereR?R(RRRRRR,RLR5R9R:R=RDRjR\RwRzRRRRxRt
DocTestParserRRtargvttestmodtexitRuR7RAttestfiletELLIPSIStREPORT_ONLY_FIRST_FAILURERBtnewRMtsystem(((sK/opt/alt/python27/lib/python2.7/site-packages/paste/debug/doctest_webapp.pyt<module>sb	!			
				6