4 from paste.urlparser import StaticURLParser
5 from pylons import request
6 from pylons.controllers.util import forward
7 from pylons.middleware import error_document_template, media_path
9 from bluechips.lib.base import BaseController
11 class ErrorController(BaseController):
12 """Generates error documents as and when they are required.
14 The ErrorDocuments middleware forwards to ErrorController when error
15 related status codes are returned from the application.
17 This behaviour can be altered by changing the parameters to the
18 ErrorDocuments middleware in your config/middleware.py file.
22 """Render the error document"""
23 resp = request.environ.get('pylons.original_response')
24 page = error_document_template % \
25 dict(prefix=request.environ.get('SCRIPT_NAME', ''),
26 code=cgi.escape(request.GET.get('code', resp.status)),
27 message=cgi.escape(request.GET.get('message', resp.body)))
31 """Serve Pylons' stock images"""
32 return self._serve_file(os.path.join(media_path, 'img'), id)
35 """Serve Pylons' stock stylesheets"""
36 return self._serve_file(os.path.join(media_path, 'style'), id)
38 def _serve_file(self, root, path):
39 """Call Paste's FileApp (a WSGI application) to serve the file
42 static = StaticURLParser(root)
43 request.environ['PATH_INFO'] = '/%s' % path
44 return static(request.environ, self.start_response)