source: TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/integration/pylonsapp/pylonsapp/controllers/error.py @ 7077

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg-security/TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/integration/pylonsapp/pylonsapp/controllers/error.py@7077
Revision 7077, 1.6 KB checked in by pjkersha, 11 years ago (diff)
  • Property svn:keywords set to Id
Line 
1import cgi
2
3from paste.urlparser import PkgResourcesParser
4from pylons import request
5from pylons.controllers.util import forward
6from pylons.middleware import error_document_template
7from webhelpers.html.builder import literal
8
9from pylonsapp.lib.base import BaseController
10
11class ErrorController(BaseController):
12
13    """Generates error documents as and when they are required.
14
15    The ErrorDocuments middleware forwards to ErrorController when error
16    related status codes are returned from the application.
17
18    This behaviour can be altered by changing the parameters to the
19    ErrorDocuments middleware in your config/middleware.py file.
20
21    """
22
23    def document(self):
24        """Render the error document"""
25        resp = request.environ.get('pylons.original_response')
26        content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
27        page = error_document_template % \
28            dict(prefix=request.environ.get('SCRIPT_NAME', ''),
29                 code=cgi.escape(request.GET.get('code', str(resp.status_int))),
30                 message=content)
31        return page
32
33    def img(self, id):
34        """Serve Pylons' stock images"""
35        return self._serve_file('/'.join(['media/img', id]))
36
37    def style(self, id):
38        """Serve Pylons' stock stylesheets"""
39        return self._serve_file('/'.join(['media/style', id]))
40
41    def _serve_file(self, path):
42        """Call Paste's FileApp (a WSGI application) to serve the file
43        at the specified path
44        """
45        request.environ['PATH_INFO'] = '/%s' % path
46        return forward(PkgResourcesParser('pylons', 'pylons'))
Note: See TracBrowser for help on using the repository browser.