Ñò ô†³Kc@sµdZddklZlZlZddklZlZlZddkl Z l Z l Z l Z ddkl Z lZlZddklZddkZddklZddkZdd klZddkZd d d d ddddddddddddddddgZd efd„ƒYZd efd„ƒYZdefd „ƒYZdefd!„ƒYZdd"„Z d#efd$„ƒYZ!de"d%„Z#d&efd'„ƒYZ$d(e%d)„Z&d*efd+„ƒYZ'd,„Z(de(_)d-„Z*d.„Z+d/„Z,ddd0„Z-d1e fd2„ƒYZ.d3„Z/xVeD]NZ0e1ƒe0Z2e3e2d4ƒo+e2i4d5e5joe/e2ƒe1ƒe0eZdZdd„Zd„Zd„Zd„Zd„ZRS(s“ An an iterable that iterates over app_iter, calls start_func before the first item is returned, then calls close_func at the end. cCs@||_t|ƒ|_t|_||_||_t|_dS(N( RRRR'tfirstt start_funcRR R!(R"RR0R((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR#Ds     cCs|S(N((R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR$LscCs.|io|iƒt|_n|iiƒS(N(R/R0R RR%(R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR%Os   cCsOt|_t|idƒo|iiƒn|idj o|iƒndS(NR&(R'R!R(RR&RtNone(R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR&Us  cCs&|iptid|iIJndS(NsgError: app_iter.close() was not called when finishing WSGI request. finalization function %s not called(R!R)R*R(R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR+\s N( R,R-R.R1R#R$R%R&R+(((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR=s     cBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(sZ Chains several app_iters together, also delegating .close() to each of them. cGs@||_g}|D]}|t|ƒq~|_t|_dS(N(t app_itersRtchainedR R!(R"R3t_[1]titem((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR#ks *cCs|S(N((R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR$pscCsnt|iƒdjo|idiƒSy|idiƒSWn*tj o|iidƒ|iƒSXdS(Nii(tlenR3R%t StopIterationtpop(R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR%sscCs‚t|_d}xI|iD]>}y"t|dƒo|iƒnWqtiƒ}qXqW|o|d|d|d‚ndS(NR&iii(R'R!R1R2R(R&R)texc_info(R"tgot_excR((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR&}s  cCs&|iptid|iIJndS(NsgError: app_iter.close() was not called when finishing WSGI request. finalization function %s not called(R!R)R*R(R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR+‰s (R,R-R.R#R$R%R&R+(((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRds    cBs>eZdZeiƒdd„Zd„Zd„Zd„ZRS(s@ Encodes an app_iterable's unicode responses as strings tstrictcCs.||_t|ƒ|_||_||_dS(N(RRRtencodingterrors(R"RR<R=((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR#–s  cCs|S(N((R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR$scCs?|iiƒ}t|tƒo|i|i|iƒ}n|S(N(RR%t isinstancetunicodetencodeR<R=(R"tcontent((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR% scCs(t|idƒo|iiƒndS(NR&(R(RR&(R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR&¦s( R,R-R.R)tgetdefaultencodingR#R$R%R&(((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR‘s     cCsty|||ƒ}Wn|tiƒƒ‚nXt|ƒttfjo|o |ƒn|St|||ƒSdS(s& Runs the application, and returns the application iterator (which should be passed upstream). If an error occurs then error_callback will be called with exc_info as its sole argument. If no errors occur and ok_callback is given, then it will be called with no arguments. N(R)R9ttypetlistttuplet_wrap_app_iter(t applicationtenvirontstart_responseterror_callbackt ok_callbackR((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRªs RFcBs#eZd„Zd„Zd„ZRS(cCsT||_t|ƒ|_||_||_t|idƒo|ii|_ndS(NR&(RRRRJRKR(R&(R"RRJRK((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR#Ás    cCs|S(N((R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR$ÉscCsby|iiƒSWnJtj o"|io|iƒn‚n|itiƒƒ‚nXdS(N(RR%R7RKRJR)R9(R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR%Ìs (R,R-R#R$R%(((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRF¿s  c Cs’y|||ƒ}Wn&|j o|||tiƒƒSXt|ƒttfjo|dj o |ƒn|St|||||d|ƒSdS(s Like ``catch_errors``, except error_callback_app should be a callable that will receive *three* arguments -- ``environ``, ``start_response``, and ``exc_info``. It should call ``start_response`` (*with* the exc_info argument!) and return an iterator. tcatchN(R)R9RCRDRER1t_wrap_app_iter_app(RGRHRIterror_callback_appRKRLR((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR×s    RMcBs&eZed„Zd„Zd„ZRS(cCso||_||_||_t|ƒ|_||_||_||_t|idƒo|ii |_ ndS(NR&( RHRIRRRRNRKRLR(R&(R"RHRIRRNRKRL((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR#ðs      cCs|S(N((R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR$üscCsíy|iiƒSWnÕtj o"|io|iƒn‚n©|ij o™t|idƒoy|iiƒWq„q„Xn|i|i |i t i ƒƒ}t |ƒ}t|dƒo|i|_n|i|_|iƒSXdS(NR&(RR%R7RKRLR(RR&RNRHRIR)R9R(R"tnew_app_iterableR((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR%ÿs&   (R,R-t ExceptionR#R$R%(((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRMîs tc sÔ|o tƒ}n tƒ}h dd6dd6dd6dd6dd 6d d 6d#d6dd6tdƒd6|d6td6td6td6}|oltt|ƒƒ\}}}}} ti|ƒ}t|ƒt|ƒ}}||d<|o||dtj o2}|id d|f|id |_‚nXWdt|d ƒo|iƒnXˆd!ˆd"diˆƒ|iƒfS($s5 Runs the application in a fake environment. tGETtREQUEST_METHODRQt SCRIPT_NAMEt PATH_INFOt localhostt SERVER_NAMEt80t SERVER_PORTsHTTP/1.0tSERVER_PROTOCOLiis wsgi.versionthttpswsgi.url_schemes wsgi.inputs wsgi.errorsswsgi.multithreadswsgi.multiprocesss wsgi.run_oncet QUERY_STRINGt__t.t HTTP_HOSTtCONTENT_LENGTHcs{|o5z'ˆo|d|d|d‚nWdd}Xnˆotdƒ‚nˆitƒ|ˆd<|ˆd<ˆiS(Niiis$Headers already set and no exc_info!tstatustheaders(R1tAssertionErrortappendR'(RaRbR9(t headers_sett headers_senttdatatoutput(s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRIFs     sAThe app_iter response can only contain str (not unicode); got: %rsContent sent w/o headers!s iterable: %rNR&RaRb(ii(t ErrorRaiserRR RtstrturllibtunquotetitemstreplaceR>R6R1t ValueErrorRdR'Rct TypeErrortargsR(R&tjointgetvalue(RGtpathtraise_on_wsgi_errorRHR=t basic_environt_t path_infotquerytfragmenttnametvaluetistreamRIRtste((ReRfRgRhs1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRsx    !      & RicBs,eZd„Zd„Zd„Zd„ZRS(cCsdS(N((R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pytflushpscCs |pdStd|ƒ‚dS(Ns%No errors should be written (got: %r)(Rc(R"R|((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pytwritesscCstdt|ƒƒ‚dS(Ns+No errors should be written (got lines: %s)(RcRD(R"tseq((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyt writelinesyscCsdS(NRQ((R"((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRs}s(R,R-R€RRƒRs(((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRins   c Os¿t||Ž\}}}}tƒ}|o1|idƒ|i|iƒƒ|idƒn|i|dƒx+|D]#\}}|id||fƒqtW|idƒ|i|ƒ|iƒS(sx Runs the application interatively, wrapping `raw_interactive` but returning the output in a formatted way. sErrors: s ----------end errors s s%s: %s (RRRtstripRs( RqtkwRaRbRAR=tfullR{R|((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR€s     cCsøg}|iƒ}|iƒxA|D]9}t||ƒiddƒ}|id||fƒq#W|idƒ|iddƒ}|o1|i|dit|ƒƒƒ|idƒndi|ƒ}d d tt |ƒƒfg}|d |ƒ|gS( sl Application which simply dumps the current environment variables out as a plain text response. s s s%s: %s R`RQs wsgi.inputs Content-Types text/plainsContent-Lengths200 OK(s Content-Types text/plain( tkeystsortRjRnRdtgettreadtintRrR6(RHRIRhR‡tktvtcontent_lengthRb((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR“s"     cCs0tidtdƒddkl}|i|ƒS(Ns9wsgilib.send_file has been moved to paste.fileapp.FileAppiiÿÿÿÿ(tfileapp(twarningstwarntDeprecationWarningtpasteRtFileApp(tfilenameR((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR©s  c sàtidtdƒg‰tƒ‰d‡‡‡fd†}|||ƒ}z"x|D]}ˆi|ƒqSWWdt|dƒo|iƒnXˆpˆidƒnt ˆƒdjoˆidƒnˆiˆi ƒƒˆS(s Runs application with environ and start_response, and captures status, headers, and body. Sends status and header, but *not* body. Returns (status, headers, body). Typically this is used like: .. code-block:: python def dehtmlifying_middleware(application): def replacement_app(environ, start_response): status, headers, body = capture_output( environ, start_response, application) content_type = header_value(headers, 'content-type') if (not content_type or not content_type.startswith('text/html')): return [body] body = re.sub(r'<.*?>', '', body) return [body] return replacement_app sOwsgilib.capture_output has been deprecated in favor of wsgilib.intercept_outputicsCˆo gˆ(nˆi|ƒˆi|ƒˆ|||ƒˆiS(N(RdR(RaRbR9(RIRhRg(s1/usr/lib/python2.6/site-packages/paste/wsgilib.pytreplacement_start_responseÍs    NR&( RR‘R’RR1RR(R&RdR6Rs(RHRIRGR–RR5((RIRhRgs1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR°s&  c sˆdj oˆdjotdƒ‚ng‰tƒ‰d‡‡‡‡fd†}|||ƒ}ˆddjodd|fSz"x|D]}ˆi|ƒqŒWWdt|dƒo|iƒnXˆpˆidƒntˆƒdjoˆidƒnˆiˆiƒƒˆS(sç Runs application with environ and captures status, headers, and body. None are sent on; you must send them on yourself (unlike ``capture_output``) Typically this is used like: .. code-block:: python def dehtmlifying_middleware(application): def replacement_app(environ, start_response): status, headers, body = intercept_output( environ, application) start_response(status, headers) content_type = header_value(headers, 'content-type') if (not content_type or not content_type.startswith('text/html')): return [body] body = re.sub(r'<.*?>', '', body) return [body] return replacement_app A third optional argument ``conditional`` should be a function that takes ``conditional(status, headers)`` and returns False if the request should not be intercepted. In that case ``start_response`` will be called and ``(None, None, app_iter)`` will be returned. You must detect that in your code and return the app_iter, like: .. code-block:: python def dehtmlifying_middleware(application): def replacement_app(environ, start_response): status, headers, body = intercept_output( environ, application, lambda s, h: header_value(headers, 'content-type').startswith('text/html'), start_response) if status is None: return body start_response(status, headers) body = re.sub(r'<.*?>', '', body) return [body] return replacement_app s?If you provide conditional you must also provide start_responsecsoˆdj o/ˆ||ƒ oˆidƒˆ|||ƒSˆo gˆ(nˆi|ƒˆi|ƒˆiS(N(R1RdR(RaRbR9(RIt conditionalRhRg(s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR–s    iNR&i( R1RpRRR(R&RdR6Rs(RHRGR—RIR–RR5((RIR—RhRgs1/usr/lib/python2.6/site-packages/paste/wsgilib.pyRâs*.   tResponseHeaderDictcBseZd„ZRS(cOs*tidtdƒti|||ŽdS(NsPThe class wsgilib.ResponseHeaderDict has been moved to paste.response.HeaderDicti(RR‘R’RR#(R"RqR…((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR#3s (R,R-R#(((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyR˜1scsQˆi‰ˆiddˆ‰‡‡‡fd†}yˆi|_WnnX|S(NR,R^cs*tidˆˆftdƒˆ||ŽS(Ns,The function wsgilib.%s has been moved to %si(RR‘R’(RqR…(tnew_nametnew_pathtnew_func(s1/usr/lib/python2.6/site-packages/paste/wsgilib.pyt replacement=s   (t func_namet func_globals(R›Rœ((R™R›Ršs1/usr/lib/python2.6/site-packages/paste/wsgilib.pyt_warn_deprecated:s RžR,t__main__(8R.t paste.requestRRRRRRtpaste.responseRRRR R R R t tracebackR Rkt cStringIORR)turlparseRRt__all__tobjectRRRRR1RRFRPRRMR RRiRtproxyRRRRR˜RŸt_nametglobalst_funcR(RžR,tdoctestttestmod(((s1/usr/lib/python2.6/site-packages/paste/wsgilib.pytsX"         '- 'Y     2 N