Ñò ÝÍKc@sàdZddkZddkZddkZddkZddklZddkZddkZddk Z ddk Z ddk l Z l Z lZddklZddklZddklZddklZdd klZdd klZddkZd Zd „Zed „Zd„Zd„Zd„Zd„Zeie e i ƒƒƒZ!d„Z"de#fd„ƒYZ$de#fd„ƒYZ%de i&fd„ƒYZ'd„Z(d„Z)d„Z*d„Z+dZ,dd„Z.dS(sâ Exception-catching middleware that allows interactive debugging. This middleware catches all unexpected exceptions. A normal traceback, like produced by ``paste.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. iÿÿÿÿN(tStringIO(terrormiddlewaret formattert collector(twsgilib(t urlparser(thttpexceptions(tregistry(trequest(tresponseiÈcCs(|djodStit|ƒdƒS(s; Escape HTML characters, plus translate None to '' tiN(tNonetcgitescapetstr(tv((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyt html_quote/s 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((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytpreserve_whitespace7scCsMt|idƒƒdjodS|idƒdt|idƒƒddS(Niis t (tlentgroup(tmatch((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRFscs‡fd†}|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(sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytsimplecatcher_appPs   ((R%R&((R%sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyt simplecatcherKs cCs d„}|S(s= Turns a function or method into a WSGI application. cs‡fd†}t|_|S(Ncs„tˆƒdjo%ˆd}ˆd}ˆdg‰nˆ\}}g‰‡‡fd†}ti|ƒ}t|ƒ}|||ƒS(Niiiics„ti|dtƒ}tihdd6dd6ƒ}||d<||d<ˆˆ|iƒŽ}|idƒ}|||iƒƒ|gS(Ntinclude_get_varss text/htmls content-types200 OKtstatusR!theaders(Rtparse_formvarstTrueR t HeaderDicttmixedtpopt headeritems(R!R"tformR*R$R)(targstfunc(sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyR%ms      (RRtmake_middlewareR'(R2R!R"R%tapp(R3(R2sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytwsgiapp_wrappercs     (R,texposed(R3R6((R3sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyt decoratorbs ((R8((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytwsgiapp^s cs‡fd†}|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). c sÛy¦d|jotdƒ‚n|idƒ}yt|ƒ}Wntj otdƒ‚nX||ijotd|ƒ‚n|i|}ˆ|d||SWn.tj o"}d|ddThere was an error: %s(t ValueErrorR/tintt debug_infosR(tselfR1R:R;te(R3(sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytdebug_info_replacement†s"  ((R3RA((R3sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytget_debug_info€scCs2d|jo |dStiƒ|d<}|SdS(s? Return the unique debug count for the current request spaste.evalexception.debug_countN(t debug_countertnext(R!RD((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytget_debug_count›s  t EvalExceptioncBsÈeZd d d„Zd„Zd„Zd„Zee_d„Z ee _d„Z ee _d„Z ee _d„Z d„Z eƒee ƒƒZ d „ZeƒeeƒƒZd „Zd „ZRS( cCsY||_h|_|djo-|djo d}qL|iddƒ}n||_dS(Nt_t xmlhttp_key(R%R>R tgetRH(R?R%t global_confRH((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyt__init__§s     cCsK||d<|iddƒidƒo|i||ƒS|i||ƒSdS(Nspaste.evalexceptiont PATH_INFOR s/_debug/(RIt startswithtdebugtrespond(R?R!R"((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyt__call__²s cCsŸti|ƒ}t||dƒ}|p3tid|ti|ƒfƒ}|i||ƒSt|dt ƒp$ti d|ƒ}|i||ƒS|||ƒS(Ns%r not found when parsing %rR7s%r not allowed( Rt path_info_poptgetattrR Rt HTTPNotFoundRt construct_urltwsgi_applicationtFalset HTTPForbidden(R?R!R"t next_parttmethodtexc((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRN¼s cCs7titiitiitƒdƒƒ}|||ƒS(s? Static path where images and other files live tmedia(RtStaticURLParsertostpathtjointdirnamet__file__(R?R!R"R5((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyR[Ës$cCs7titiitiitƒdƒƒ}|||ƒS(s2 Static path where MochiKit lives tmochikit(RR\R]R^R_R`Ra(R?R!R"R5((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRbÔs$cCsi|ddgƒg}|iiƒ}|id„ƒg}|D]}||iƒq@~}t|ƒgS(s[ Returns a JSON-format summary of all the cached exception reports s200 OKs Content-types text/x-jsoncSst|i|iƒS((tcmptcreated(tatb((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytås(s Content-types text/x-json(R>tvaluestsorttjsontrepr(R?R!R"tdatatitemst_[1]titem((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytsummaryÝs 'cCs^tti|ƒƒ}||ijo|ddgƒd|gS|i|}|i||ƒS(s, View old exception reports s500 Server Errors Content-types text/htmlsHTraceback by id %s does not exist (maybe the server has been restarted?)(s Content-types text/html(R=RRQR>RU(R?R!R"tidR;((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytviewês   cCs |d|S(Ns/_debug/view/%s((R?R!t base_pathtcount((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyt make_view_urlûscKso|it|ƒƒ}|ii}|o0tii|iƒt|ƒ}tii ƒnd}t ||ƒ|S(Ns No local vars( tframeR=ttb_frametf_localsRtrestorertrestoration_begintcountert make_tabletrestoration_endt input_form(R?ttbidR;tkwRvtvarst local_vars((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyt show_frames  c Ks¿|iƒpdS|iƒd}|it|ƒƒ}|ii}|ii}ti||ƒ}t i i |i ƒ|i |ƒ} t i iƒti|ƒ} dt| dtƒt| ƒfS(NR s sD>>> %s
%sR(tstriptrstripRvR=RwRxt f_globalst evalcontextt EvalContextRRyRzR{t exec_exprR}Rtstr2htmlRRV( R?RR;tinputR€RvRt glob_varstcontexttoutputt input_html((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyt exec_inputs    c s:|idƒo|i|ˆƒSti|dtdtƒ}t|dRHRtparse_querystringtdictRt format_htmltcontent(R?R!R"RsR•t__traceback_supplement__tapp_itert return_iterRtexpectedRttview_uriR*texc_dataR;tget_varsthtml((R"R”sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRO"sX             c Cslt}|io6ti|ƒ}t|ƒi|iƒo t}qFnti||ddtdtd|ƒS(Ns wsgi.errorsR­t debug_modetsimple_html_error( RVRHRR¢R£RIR,Rthandle_exception(R?RR!R¯R¬((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytexception_handler_s  N(t__name__t __module__R RKRPRNR[R,R7RbRpRrRuRƒR9RBRROR±(((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRF¥s&            =R¡cBs>eZd„Zd„Zd„Zd„Zd„Zd„ZRS(c Csã||_||_||_||_||_tiƒ|_|\|_|_|_ d}g|_ d}|i } xj| dj o\t djp |t joB| i iidƒoPn|i i| ƒ| i} |d7}quWdS(Niit__exception_formatter__(R{R«RsR!RªttimeRdtexc_typet exc_valuettbtframesR tlimitRwRxRIR“ttb_next( R?R{RR«RsR!RªR´tnR¸((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRKms$       ' cCsWh|id6tidti|iƒƒd6|id6t|iƒd6t|iƒd6S(s2Return the JSON-able representation of this objectturis%cRdtcreated_timestamptexception_typet exception(RªRµtstrftimetgmtimeRdRR¶R·(R?((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRj‚s   cCsFx?|iD]}t|ƒ|jo|Sq Wtd||if‚dS(NsNo frame by id %s found from %r(R¹RqR<(R?RRv((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRvŒs   cCs|ddgƒ|iƒS(Ns200 OKs content-types text/html(s content-types text/html(R¥(R?R!R"((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRU”scCswt|i|i|iƒ}titi}||iƒ7}t|i ƒ}t h|pdd6|d6|d6}|gS(NR t repost_buttont head_htmltbody( tformat_eval_htmlR«RsR{Rt error_cssthide_display_jsteval_javascripttmake_repost_buttonR!terror_template(R?R­RÄRÃtpage((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyR¥˜s cCs$|id}d||||ifS(Ns/_debugsÙ (RsR{(R?Rs((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRÉ£s (R²R³RKRjRvRUR¥RÉ(((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyR¡ks     tEvalHTMLFormattercBseZd„Zd„ZRS(cKs,tt|ƒi|||_||_dS(N(tsuperRÍRKRsR{(R?RsR{R€((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRK²s cCs0tii|||ƒ}|d|i|ifS(Ns­        (Rt HTMLFormattertformat_source_lineRRs(R?tfilenameRvtline((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRзs  (R²R³RKRÐ(((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRͰs c CsVt|tƒo|iƒ}|iƒng}d}x |D]\}}|d7}tƒ}yti||ƒWn#tj o}|d|IJnXt|iƒƒ}t |ƒdjo0|}|d }|d7}|d|d7}nt i |ƒ}|do d}nd }|i d |t|ƒt |d tƒfƒq=Wd d i|ƒS(Niis Error: %sidsj...s%%sis class="even"s class="odd"s[%s%sRs%s
s (RR£RmRiRtpprintt ExceptionRR RRtmake_wrappableR“RRVR_( RmtrowstitnametvalueR#R@t orig_valuetattr((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyR|Ás8          c CsÈtd|d|dtƒ}|i|ƒ}td|d|dtdtdtƒ}|i|ƒ}ti|dtƒ}|i|iƒ|i|iƒjod|}nd}d||ti |ƒfS( NRsR{R˜tshow_hidden_framesR™s¼
%s
R sú %s %s
( RÍRVtformat_collected_dataR,Rt format_textt filter_framesR¹R R ( R«RsR{tshort_formattertshort_ertlong_formattertlong_erttext_ertfull_traceback_html((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRÆâs$    cCs1ti|ƒ}|ddjo d|SdSdS(NtREQUEST_METHODtGETsB
(RRTR (R!turl((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyRÊ s cCsdh|d6S(Ns~

R((RR;((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pyR~*ssE Server Error %(head_html)s %(repost_button)s %(body)s cCs3|djo|iddƒ}nt|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) RHRGN(R RIRF(R5RJRH((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytmake_eval_exceptionSs (/t__doc__RR]R Rt cStringIORRÓt itertoolsRµRtpaste.exceptionsRRRtpasteRRRRRR R‡RºRR,RRR'R9RBRtR=RCREtobjectRFR¡RÏRÍR|RÆRÊR~RËR Ré(((sB/usr/lib/python2.6/site-packages/paste/evalexception/middleware.pytsF              "  ÆE ! *  '