Ñò ;V Lc @sÑdZddkZddklZddklZlZddklZddkl Z d„Z de fd „ƒYZ d e fd „ƒYZ d „Zd dddd gZdd„Zde fd„ƒYZdS(s Middleware to display error documents for certain status codes The middleware in this module can be used to intercept responses with specified status codes and internally forward the request to an appropriate URL where the content can be displayed to the user as an error document. iÿÿÿÿN(turlparse(tForwardRequestExceptiontRecursiveMiddleware(t converters(treplace_headercCs]x8|D]0}t|tƒptdt|ƒƒ‚qqWd„}tt||d|ƒƒS(sç Intercepts a response with a particular status code and returns the content from a specified URL instead. The arguments are: ``app`` The WSGI application or middleware chain. ``codes`` A dictionary of integer status codes and the URL to be displayed if the response uses that code. For example, you might want to create a static file to display a "File Not Found" message at the URL ``/error404.html`` and then use ``forward`` middleware to catch all 404 status codes and display the page you created. In this example ``app`` is your exisiting WSGI applicaiton:: from paste.errordocument import forward app = forward(app, codes={404:'/error404.html'}) s4All status codes should be type int. %s is not validcSs!|i|ƒo ||SdSdS(N(thas_keytNone(tcodetmessagetenviront global_conftcodes((s7/usr/lib/python2.6/site-packages/paste/errordocument.pyterror_codes_mapper/s R (t isinstancetintt TypeErrortreprRtStatusBasedForward(tappR RR ((s7/usr/lib/python2.6/site-packages/paste/errordocument.pytforwards t StatusKeepercBseZd„Zd„ZRS(cCs(||_||_||_||_dS(N(Rtstatusturltheaders(tselfRRRR((s7/usr/lib/python2.6/site-packages/paste/errordocument.pyt__init__?s   cstd‡‡fd†}ˆiidƒ}|d|ds RcBs#eZdZdd„Zd„ZRS(s¤ Middleware that lets you test a response against a custom mapper object to programatically determine whether to internally forward to another URL and if so, which URL to forward to. If you don't need the full power of this middleware you might choose to use the simpler ``forward`` middleware instead. The arguments are: ``app`` The WSGI application or middleware chain. ``mapper`` A callable that takes a status code as the first parameter, a message as the second, and accepts optional environ, global_conf and named argments afterwards. It should return a URL to forward to or ``None`` if the code is not to be intercepted. ``global_conf`` Optional default configuration from your config file. If ``debug`` is set to ``true`` a message will be written to ``wsgi.errors`` on each internal forward stating the URL forwarded to. ``**params`` Optional, any other configuration and extra arguments you wish to pass which will in turn be passed back to the custom mapper object. Here is an example where a ``404 File Not Found`` status response would be redirected to the URL ``/error?code=404&message=File%20Not%20Found``. This could be useful for passing the status code and message into another application to display an error document: .. code-block:: python from paste.errordocument import StatusBasedForward from paste.recursive import RecursiveMiddleware from urllib import urlencode def error_mapper(code, message, environ, global_conf, kw) if code in [404, 500]: params = urlencode({'message':message, 'code':code}) url = '/error?'%(params) return url else: return None app = RecursiveMiddleware( StatusBasedForward(app, mapper=error_mapper), ) cKsq|djo h}n|o"ti|idtƒƒ|_n t|_||_||_||_||_ dS(Ntdebug( RRtasbooltgettFalseR+t applicationtmapperR tparams(RRR0R R1((s7/usr/lib/python2.6/site-packages/paste/errordocument.pyRŒs  "    cs‚g‰d‡‡‡‡fd†}ˆiˆ|ƒ}ˆo@t|dƒo|iƒn‡fd†}td|ƒ‚n|SdS(Nc sù|idƒ}yt|dƒ}Wn3ttfj o!tdt|dƒƒ‚nXdi|dƒ}ˆi||ˆˆiˆi }|djp t |t ƒptdt|ƒƒ‚n|oˆi |||gƒnˆ|||ƒSdS(Nt is@StatusBasedForward middleware received an invalid status code %sisiExpected the url to internally redirect to in the StatusBasedForward mapperto be a string or None, not %s(R%Rt ValueErrorRt ExceptionRtjoinR0R R1RR tstrR(RRRt status_codeRRtnew_url(RRR R(s7/usr/lib/python2.6/site-packages/paste/errordocument.pytchange_responses* tclosec s4t|dˆdddˆdddˆddƒS(NRiiRRi(R(R(R(s7/usr/lib/python2.6/site-packages/paste/errordocument.pytfactory¾s%R;(RR/thasattrR:R(RR RR9tapp_iterR;((RRRR s7/usr/lib/python2.6/site-packages/paste/errordocument.pyR(šsN(R)R*t__doc__RRR((((s7/usr/lib/python2.6/site-packages/paste/errordocument.pyRVs4 cKsvh}xZ|iƒD]L\}}yt|ƒ}Wn#tj otd|ƒ‚nX||| Error %(code)s

Error %(code)s

%(message)s


Additionally an error occurred trying to produce an error document. A description of the error was logged to wsgi.errors.

( RGRHRIRR/R0R R@tfallback_template(RRR0R R@((s7/usr/lib/python2.6/site-packages/paste/errordocument.pyRøs       c sg‰g‰y4d‡‡‡‡‡fd†}ˆiˆ|ƒ}Wnœy&ddk}t|iƒdƒ}Wn d}nXyˆd\}}Wndd}}nXˆdidt|ƒƒˆih|d6|d 6gSXˆo'ˆd‰h} xIˆiƒD];\} } | d jotˆƒd | d RRR((((s7/usr/lib/python2.6/site-packages/paste/errordocument.pyRJôs (R>RGRtpaste.recursiveRRt paste.utilRtpaste.responseRRtobjectRRRDt __pudge_all__RRKRJ(((s7/usr/lib/python2.6/site-packages/paste/errordocument.pyt s   ,o