source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/error.py @ 3536

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/error.py@3536
Revision 3536, 1.1 KB checked in by cbyrom, 14 years ago (diff)

Upgrade the server code to make consistent with newer pylons codebase - v0.9.6.1.
This mainly involves the replacement of the Response object, and associated methods,
with the inbuild, default response object. Typical changes include:

render_response -> render - with required settings on the response object
made before the render call against the response object

Response(...) -> response.write() - for content + response.headers.. = .. for headers info

  • also included the replacement of depricated functions, as highlighted by

the server logging

Line 
1import os.path
2from paste import fileapp
3from pylons.middleware import media_path, error_document_template
4from pylons.util import get_prefix
5from ows_server.lib.base import *
6
7class ErrorController(BaseController):
8    """
9    Class to generate error documents as and when they are required. This behaviour of this
10    class can be altered by changing the parameters to the ErrorDocuments middleware in
11    your config/middleware.py file.
12    """
13
14    def document(self):
15        """
16        Change this method to change how error documents are displayed
17        """
18        page = error_document_template % {
19            'prefix': get_prefix(request.environ),
20            'code': request.params.get('code', ''),
21            'message': request.params.get('message', ''),
22        }
23        return response.write(page)
24
25    def img(self, id):
26        return self._serve_file(os.path.join(media_path, 'img', id))
27       
28    def style(self, id):
29        return self._serve_file(os.path.join(media_path, 'style', id))
30
31    def _serve_file(self, path):
32        fapp = fileapp.FileApp(path)
33        return fapp(request.environ, self.start_response)
Note: See TracBrowser for help on using the repository browser.