qbIc@sdZddkZddkZddkZddkZddkZddklZddkZddk Z ddk Z ddk Z ddk Z ddk Z ddklZddklZddklZddklZddklZdd klZddkZdd klZlZlZdd klZdd klZdd k l!Z!l"Z"ddk l#Z#dZ$dZ%e&dZ'dZ(dZ)dZ*dZ+e i,e-e i Z.dZ/de0fdYZ1de2fdYZ3de2fdYZ4dei5fdYZ6dZ7ed d!d"Z8e9d#Z:d$Z;d%Z<ed&d!d'Z=e>e>d(Z?e9d)Z@dS(*sException-catching middleware that allows interactive debugging. This middleware catches all unexpected exceptions. A normal traceback, like produced by ``weberror.exceptions.errormiddleware.ErrorMiddleware`` is given, plus controls to see local variables and evaluate expressions in a local context. This can only be used in single-process environments, because subsequent requests must go back to the same process that the exception originally occurred in. Threaded or non-concurrent environments both work. This shouldn't be used in production in any way. That would just be silly. If calling from an XMLHttpRequest call, if the GET variable ``_`` is given then it will make the response more compact (and less Javascripty), since if you use innerHTML it'll kill your browser. You can look for the header X-Debug-URL in your 500 responses if you want to see the full debuggable traceback. Also, this URL is printed to ``wsgi.errors``, so you can open it up in another browser window. iN(tStringIO(tresource_filename(tfileapp(tregistry(trequest(t urlparser(t import_string(terrormiddlewaret formattert collector(tescaping(t HTMLTemplate(tRequesttResponse(texcicCs(|djodStit|dS(s; Escape HTML characters, plus translate None to '' tiN(tNonetcgitescapetstr(tv((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyt html_quote7s cCsp|ot|}n|idd}tidt|}tidt|}tidt|}d|S(s Quote a value for HTML, preserving whitespace (translating newlines to ``
`` and multiple spaces to use `` ``). If ``quote`` is true, then the value will be HTML quoted first. s s
s()( +)s(\n)( +)s^()( +)s%s(Rtreplacetretsubt _repl_nbsp(Rtquote((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytpreserve_whitespace?scCsMt|iddjodS|iddt|idddS(Niis t (tlentgroup(tmatch((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyROscsfd}|S(s\ A simple middleware that catches errors and turns them into simple tracebacks. csky||SWnSt}tid||ddgti|i}dt|gSXdS(Ntfiles500 Server Errors content-types text/htmls

Error

%s
(s content-types text/html(Rt tracebackt print_exctsystexc_infotgetvalueR(tenvirontstart_responsetouttres(t application(s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytsimplecatcher_appZs   ((R*R+((R*s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyt simplecatcherUs cCs d}|S(s= Turns a function or method into a WSGI application. csfd}t|_|S(Ncsutdjo%d}d}dgn\}}gfd}t|}|||S(Niiiicsti|dt}d}||dThere was an error: %ss content-types text/html(s content-types text/html(Rtparse_formvarstTruetmixedt ValueErrorR(R&R'tformtstatusR)tve(targstfunc(s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyR*xs   (RR,(R5R&R'R*tapp(R6(R5s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytwsgiapp_wrapperns    (R/texposed(R6R8((R6s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyt decoratorms ((R:((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytwsgiappis csfd}t|_|S(s A decorator (meant to be used under ``wsgiapp()``) that resolves the ``debugcount`` variable to a ``DebugInfo`` object (or gives an error if it can't be found). csd|ijotidS|id}yt|}Wn)tj o}tid||fSX||ijotid|S|i||_||S(Nt debugcounts'You must provide a debugcount parameters%Invalid value for debugcount (%r): %ssFDebug %s not found (maybe it has expired, or the server was restarted)(tparamsRtHTTPBadRequesttintR1t debug_infostHTTPServerErrort debug_info(tselftreqR<te(R6(s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytdebug_info_replacements   (R/R9(R6RF((R6s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytget_debug_infos cCswt|do |i}n|}d|jo |dSd|jo |dSti}||d<||d<|SdS(s? Return the unique debug count for the current request R&spaste.evalexception.debug_counts"weberror.evalexception.debug_countN(thasattrR&t debug_countertnext(RDR&RJ((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytget_debug_counts        tInvalidTemplatecBseZRS((t__name__t __module__(((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyRLst EvalExceptionc BseZdZdddddddddd ZdZdZdZee_ dZ e e Z dZ ee _ dZ ee _ d Zee_ d Zd Ze eZd Ze eZd Zee_ dZRS(sXHandles capturing an exception and turning it into an interactive exception explorerRc Ks| pg|_||_h|_|pg|_t||_t||_|djotdd}n|djo-|djo d}q|i dd}n||_ |ph|_ ti ||_ | djo g} n| |_dS(Ntweberrorseval_template.htmlt_t xmlhttp_key(t librariesR*R@ttemplating_formattersR t head_htmlt footer_htmlRRtgetRRt media_pathst from_filenameterror_templatet reporters( RCR*t global_confterror_template_filenameRRRXRTRURVR[RSR=((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyt__init__s&          cCs\||d<|d=s(R R@tvaluestsorttjsontreprRw(RCRDR)tdatatitemst_[1]titem((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytsummary5s'cCsHt|i}||ijotid|S|i|}|iS(s, View old exception reports sHTraceback by id %s does not exist (maybe the server has been restarted?)(R?RdR@RRAtwsgi_application(RCRDtidRB((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytviewCs  cCs |d|S(Ns/view/%s((RCR&t base_pathtcount((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyt make_view_urlPscCst|id}|ii|}|ii}|o;tii|ii zt |}Wdtii Xnd}t dd}t id|d|i||_|S(Nttbids No local varsRs text/htmlRB(R?R=RBtframettb_frametf_localsRtrestorertrestoration_begintcountert make_tabletrestoration_endR t input_formt substituteRw(RCRDRRtvarst local_varsR)((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyt show_frameTs "c Cs|iid}|ipdS|id}|iit|id}|ii}|ii }t i ||}t i i|iiz|i|}Wdt i iXti|}tdd} | idt|dtt|f| S( NtinputRs RRs text/htmls7>>> %s
%sR(R=RWtstriptrstripRBRR?RRt f_globalst evalcontextt EvalContextRRRRt exec_exprRRtstr2htmlR twriteRRg( RCRDRRRt glob_varstcontexttoutputt input_htmlR)((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyt exec_inputgs&   c Cs]|id}|idd\}}tii|}|djo'tdddd}d||_|S|i}|d djo|d }n#|i d od|d }nt |d}|i } |i d||t ift i|| dt} t| i} | djo| dd| 7} ntdddd}| |_|S(Ntlocationt:iRs text/htmltcharsettutf8s@The module %s does not have an entry in sys.modulesis.pycs.pyois $py.classs%s.pyitrbsF
Module: %s file: %s
tlinenosi<s
(s.pycs.pyo(R=tsplitR#tmodulesRWRR Rwt__file__tendswithtopenR{tcloseRt pygments_csst highlightR/Rt splitlinest unicode_body( RCRDRt module_nametlinenotmoduleR)tfilenametftsourcethtmlt source_lines((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyt source_codes0        csht|}|iido|i|S|id}t|idNo Template information available.

ttraceback_datat template_dataiRtlatin1thtmlentityreplaces

s

s

sRMRUtprefixRRVt repost_buttonRttraceback_bodyRtexc_nametformatted_exc_valuet extra_datatset_tabR(tformat_eval_htmlRRRRStmake_repost_buttonR&RTRtexception_valueRRRtdecodetsource_encodingtencodeRRRHRRMRZRRURRRV( RCRRRRttabttmpl_formattertresultRt last_frameRtpage((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyRsL           (RMRNR^RRRR(((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyRs    tEvalHTMLFormattercBseZdZdZRS(cKs,tt|i|||_||_dS(N(tsuperRR^RR(RCRRtkw((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyR^Hs cCsItii|||}d|i|if}|d|i|i|fS(Ns%s:%ss         view(Rt HTMLFormattertformat_source_linetmodnameRRR(RCRRtlineR((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyRMs  (RMRNR^R(((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyRFs c CsUt|do|i}|intidtd|dtdtidt S(NRRRtmake_wrappablet pprint_format( RHRRttable_templateRRRRRR(R((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyR[s   s {{py:i = 0}} {{for name, value in items:}} {{py:i += 1}} {{py: value_html = html_quote(pprint_format(value, safe=True)) value_html = make_wrappable(value_html) if len(value_html) > 100: ## FIXME: This can break HTML; truncate before quoting? value_html, expand_html = value_html[:100], value_html[100:] else: expand_html = '' }} {{endfor}}
{{name}} {{preserve_whitespace(value_html, quote=False)|html}}{{if expand_html}} ... {{expand_html|html}} {{endif}}
tnameRcCs^t}yti||Wn4tj o(}|o|id|qTnX|iS(Ns Error: %s(Rtpprintt ExceptionRR%(RtsafeR(RE((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyRs c Cstd|d|dt}|i|\}}ti|dt\}}td|d|dtdtdt} | i|\} } ti|dtdtd} ti|dtdtd|d} ti|dtdtd|d}|i|i| i|ijo2t i | } d| t | i | f}nd }t i |}t | i }|d jo d }nt |i }|d jo d }nd |t |i ||t i | |t i ||f|fS( NRRRRRiRSs
%s
Ri2s
%s
%s ( RRgtformat_collected_dataRt format_textR/Rt filter_framesRRRRR(RRRRStshort_formattertshort_erRt short_text_erttext_extra_datatlong_formattertlong_ertextra_data_nonet long_text_erRt short_xml_ertfull_traceback_htmlt long_xml_lengtshort_xml_leng((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyR sF   #    cCs1ti|}|ddjo d|SdSdS(NtREQUEST_METHODRmsB
(Rt construct_urlR(R&turl((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyR s sb

RcCs|djo|idd}n|djo|id}n|oyt|toi|i}g}xT|D]H}ti|}t|tti fo |}n|i |qsWnt |d|d|S(s Wraps the application in an interactive debugger. This debugger is a major security hole, and should only be used during development. xmlhttp_key is a string that, if present in QUERY_STRING, indicates that the request is an XMLHttp request, and the Javascript/interactive debugger should not be returned. (If you try to put the debugger somewhere with innerHTML, you will often crash the browser) RRRQterror_reportersR[N( RRWRt basestringRRt eval_importttypettypest ClassTypeRRO(R7R\RRR[treporter_stringstreporter_stringR((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytmake_eval_exceptions    cKsXddkl}||}|ot|||Sddkl}||||SdS(s Creates an error-catching middleware. If `interactive` is true then it will be the interactive exception catcher, otherwise it will be the static exception catcher. i(tasbool(tmake_error_middlewareN(tpaste.deploy.convertersR=R<tweberror.errormiddlewareR>(R7R\t interactiveRR=R>((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pytmake_general_exceptions  (ARRrR#tosRR!t cStringIORRt itertoolsRRR8Rut pkg_resourcesRtpasteRRRRt paste.utilRRRPRRR t weberror.utilR ttempitaR twebobR R RRRR/RRR,R;RGRR?RIRKR RLtobjectRORRRRRRgRR R RRR<RB(((s:/usr/lib/python2.6/site-packages/weberror/evalexception.pyts`                 #  '`  B