Changeset 2479 for TI05-delivery


Ignore:
Timestamp:
15/05/07 16:04:20 (13 years ago)
Author:
spascoe
Message:

Implemented basic query string handling by editing base.BaseController?.
Created an exception report template.
Disabled error document middleware.

Location:
TI05-delivery/ows_framework/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/trunk/ows_common/exception_report.py

    r2475 r2479  
    1818 
    1919    """ 
    20     def __init__(self, version, exceptions, lang=None): 
     20    def __init__(self, exceptions, version, lang=None): 
    2121        self.version = version 
    2222        self.exceptions = exceptions 
     
    3333 
    3434    """ 
    35     def ___init__(self, code, text=None, locator=None): 
     35    def __init__(self, code, text=None, locator=None): 
    3636        self.code = code 
    3737        self.text = text 
    3838        self.locator = locator 
     39 
     40class OwsError(Exception): 
     41    """Wrapper for triggering ExceptionReports via raise. 
     42 
     43    @todo: Design an elegant way of setting the version framework-wide. 
     44    @ivar report: The ExceptionReport describing the error. 
     45     
     46    """ 
     47    def __init__(self, code, text=None, locator=None, version='1.1.0', lang=None): 
     48        self.report = ExceptionReport([OwsException(code, text, locator)], version, lang) 
     49 
     50    def __str__(self): 
     51        """A concise non-XML representation of the error 
     52        """ 
     53        e = self.report.exceptions[0] 
     54        return '%s: %s (%s)' % (e.code, e.text, e.locator) 
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/config/middleware.py

    r2476 r2479  
    5454        # Display error documents for 401, 403, 404 status codes (if debug is disabled also 
    5555        # intercepts 500) 
    56         app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) 
     56        #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) 
    5757     
    5858    # Establish the Registry for this application 
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/base.py

    r2476 r2479  
    88import ows_server.lib.helpers as h 
    99 
     10from ows_common.exception_report import OwsError 
     11 
    1012class BaseController(WSGIController): 
    1113    def __call__(self, environ, start_response): 
    12         # Insert any code to be run per request here. The Routes match 
    13         # is under environ['pylons.routes_dict'] should you want to check 
    14         # the action or route vars here 
    15         return WSGIController.__call__(self, environ, start_response) 
     14 
     15        try: 
     16            self._fix_ows_action(environ) 
     17            return WSGIController.__call__(self, environ, start_response)   
     18        except OwsError, e: 
     19            return render_response('exception_report', report=e.report) 
     20             
     21  
     22    def _fix_ows_action(self, environ): 
     23        # Override the Routes action from the REQUEST query parameter 
     24        req = pylons.request._current_obj() 
     25        try: 
     26            action = req.params['REQUEST'] 
     27        except KeyError: 
     28            raise OwsError('MissingParameterValue', 'REQUEST parameter not specified', 'REQUEST') 
     29 
     30        # Check action is a method in self 
     31        if not getattr(self, action): 
     32            raise OwsError('InvalidParameterValue', 'REQUEST=%s not supported' % action, 'REQUEST') 
     33 
     34        # override routes action with REQUEST 
     35        environ['pylons.routes_dict'] = action 
     36        del req.params['REQUEST'] 
     37 
     38    def _get_method_args(self): 
     39        """Extends Controller._get_method_args to retrieve arguments from the query string. 
     40        Each query string parameter is converted to lower case before adding it to the method arguments. 
     41 
     42        See the docstring for Controller._get_method_args for details. 
     43 
     44        """ 
     45 
     46        # extract query string arguments 
     47        req = pylons.request._current_obj() 
     48        D = {} 
     49        for key in req.params: 
     50            D[key.lower()] = req.params[key] 
     51 
     52        # Get the method arguments and add the query string arguments 
     53        kargs = WSGIController._get_method_args(self) 
     54        kargs.update(D) 
     55 
     56        return kargs 
    1657 
    1758# Include the '_' function in the public names 
Note: See TracChangeset for help on using the changeset viewer.