[Mpuls-commits] r1197 - wasko/branches/2.0/waskaweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 3 09:23:55 CET 2010


Author: torsten
Date: 2010-02-03 09:23:53 +0100 (Wed, 03 Feb 2010)
New Revision: 1197

Modified:
   wasko/branches/2.0/waskaweb/controllers/error.py
Log:
* waskaweb/controllers/error.py: Iserted fresh error.py controller
from a fresh initiated pylons project of version 0.9.7


Modified: wasko/branches/2.0/waskaweb/controllers/error.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/error.py	2010-02-03 08:19:14 UTC (rev 1196)
+++ wasko/branches/2.0/waskaweb/controllers/error.py	2010-02-03 08:23:53 UTC (rev 1197)
@@ -1,36 +1,15 @@
-# Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-# 
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS - 
-# Web-Anwendungs-Server fuer Kompetenzagenturen).
-# 
-# mpuls WASKA is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the
-# Free Software Foundation, either version 3 of the License, or (at your
-# option) any later version.
-# 
-# mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
-# License for more details.
-# 
-# You should have received a copy of the GNU Affero General Public
-# License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
-# 
-# mpuls WASKA has been developed on behalf of the 
-# Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
-# within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and 
-# European Social Fund resources.
-import os.path
+import cgi
 
-#import paste.fileapp
-from paste.urlparser import StaticURLParser
+from paste.urlparser import PkgResourcesParser
+from pylons import request
+from pylons.controllers.util import forward
+from pylons.middleware import error_document_template
+from webhelpers.html.builder import literal
 
-from pylons.middleware import error_document_template, media_path
+from helloworld.lib.base import BaseController
 
-from waskaweb.lib.base import *
-
 class ErrorController(BaseController):
+
     """Generates error documents as and when they are required.
 
     The ErrorDocuments middleware forwards to ErrorController when error
@@ -38,48 +17,30 @@
 
     This behaviour can be altered by changing the parameters to the
     ErrorDocuments middleware in your config/middleware.py file.
+
     """
 
-    def __before__(self):
-        pass
-
     def document(self):
         """Render the error document"""
+        resp = request.environ.get('pylons.original_response')
+        content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
         page = error_document_template % \
             dict(prefix=request.environ.get('SCRIPT_NAME', ''),
-            code=request.params.get('code', ''),
-            message=request.params.get('message', ''))
+                 code=cgi.escape(request.GET.get('code', str(resp.status_int))),
+                 message=content)
         return page
 
     def img(self, id):
         """Serve Pylons' stock images"""
-        return self._serve_file(os.path.join(media_path, 'img'), id)
+        return self._serve_file('/'.join(['media/img', id]))
 
     def style(self, id):
         """Serve Pylons' stock stylesheets"""
-        return self._serve_file(os.path.join(media_path, 'style'), id)
+        return self._serve_file('/'.join(['media/style', id]))
 
-    def _serve_file(self, root, path):
-        """Call Paste's FileApp (a WSGI application) to serve the file
-        at the specified path
-        """
-        static = StaticURLParser(root)
-        request.environ['PATH_INFO'] = '/%s' % path
-        return static(request.environ, self.start_response)
-
-#   Removed for security reasons: http://wiki.pylonshq.com/display/pylonsdocs/0.9.6.2
-#
-#    def img(self, id):
-#        """Serve Pylons' stock images"""
-#        return self._serve_file(os.path.join(media_path, 'img', id))
-#
-#    def style(self, id):
-#        """Serve Pylons' stock stylesheets"""
-#        return self._serve_file(os.path.join(media_path, 'style', id))
-#
     def _serve_file(self, path):
         """Call Paste's FileApp (a WSGI application) to serve the file
         at the specified path
         """
-        fapp = paste.fileapp.FileApp(path)
-        return fapp(request.environ, self.start_response)
+        request.environ['PATH_INFO'] = '/%s' % path
+        return forward(PkgResourcesParser('pylons', 'pylons'))



More information about the Mpuls-commits mailing list