source: TI12-security/trunk/NDGSecurity/python/Tests/openid-provider/op/op/controllers/error.py @ 7080

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/openid-provider/op/op/controllers/error.py@7080
Revision 7080, 1.3 KB checked in by pjkersha, 9 years ago (diff)
  • Property svn:keywords set to Id
Line 
1import os.path
2
3import paste.fileapp
4from pylons.middleware import error_document_template, media_path
5
6from op.lib.base import *
7
8class ErrorController(BaseController):
9    """Generates error documents as and when they are required.
10
11    The ErrorDocuments middleware forwards to ErrorController when error
12    related status codes are returned from the application.
13
14    This behaviour can be altered by changing the parameters to the
15    ErrorDocuments middleware in your config/middleware.py file.
16    """
17
18    def document(self):
19        """Render the error document"""
20        page = error_document_template % \
21            dict(prefix=request.environ.get('SCRIPT_NAME', ''),
22                 code=request.params.get('code', ''),
23                 message=request.params.get('message', ''))
24        return page
25
26    def img(self, id):
27        """Serve Pylons' stock images"""
28        return self._serve_file(os.path.join(media_path, 'img', id))
29
30    def style(self, id):
31        """Serve Pylons' stock stylesheets"""
32        return self._serve_file(os.path.join(media_path, 'style', id))
33
34    def _serve_file(self, path):
35        """Call Paste's FileApp (a WSGI application) to serve the file
36        at the specified path
37        """
38        fapp = paste.fileapp.FileApp(path)
39        return fapp(request.environ, self.start_response)
Note: See TracBrowser for help on using the repository browser.