Changeset 3372 for TI05-delivery


Ignore:
Timestamp:
11/02/08 17:13:05 (12 years ago)
Author:
spascoe
Message:

Removed most of the decorator stuff. Use OwsController? methods to deal with parameters instead.

Location:
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/pylons
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/pylons/decorators.py

    r3257 r3372  
    8383 
    8484 
    85 def ows_operation(requiredParameters, optionalParameters): 
     85def ows_operation(method): 
    8686    """ 
    8787    A decorator which defines a method as a OWS operation. 
     
    9090    interogated during dispatch by OwsController to enforce OWS operation calling 
    9191    behaviour. 
    92  
    93     Parameter names should be lowerCamelCase to that match the method 
    94     signature such that <parameter-x>.lower() == <argument-x>.  This 
    95     is required to support XML request encoding. 
    96  
    97     @param requiredParameters: A sequence of required parameter names in lowerCamelCase 
    98     @param optionalParameters: A sequence of optional parameter names in lowerCamelCase 
    9992     
    10093    """ 
    10194 
    102  
    103     def f(method): 
    104         method._ows_name = method.__name__ 
    105         method._ows_required_parameters = requiredParameters 
    106         method._ows_optional_parameters = optionalParameters 
    107  
    108         return method 
    109  
    110     return f 
    111  
     95    method._ows_name = method.__name__ 
     96 
     97    return method 
    11298 
    11399#----------------------------------------------------------------------------- 
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/pylons/ows_controller.py

    r3368 r3372  
    3535 
    3636class OwsControllerBase(WSGIController): 
     37    """ 
     38    @ivar owsParams: A dictionary of parameters passed to the service.  Initially these 
     39        comes from the query string but could come from a HTTP POST in future. 
     40    """ 
    3741    def __call__(self, environ, start_response): 
    3842 
    39         # All OWS parameter names are case insensitive. 
    40         self.ows_params = {} 
    41         for k in request.params: 
    42             self.ows_params[k.lower()] = request.params[k]         
     43        self._loadOwsParams() 
    4344 
    4445        # If the EXCEPTION_TYPE is 'pylons' let Pylons catch any exceptions. 
     
    5859                return response 
    5960 
     61    def _loadOwsParams(self): 
     62        # All OWS parameter names are case insensitive. 
     63        self._owsParams = {} 
     64        for k in request.params: 
     65            self._owsParams[k.lower()] = request.params[k] 
    6066 
    6167    def _fixOwsAction(self, environ): 
     
    6369         
    6470        # Override the Routes action from the request query parameter 
    65         try: 
    66             action = self.ows_params['request'] 
    67         except KeyError: 
    68             raise OWS_E.MissingParameterValue('REQUEST parameter not specified', 
    69                                               'REQUEST') 
     71        action = self.getOwsParam('request') 
    7072 
    7173        # Check action is a method in self and is defined as an OWS operation 
     
    7678            raise OWS_E.InvalidParameterValue('request=%s not supported' % action, 
    7779                                              'REQUEST') 
     80        rdict['action'] = action 
    7881 
    79         # Check all required parameters are present 
    80         for param in op._ows_required_parameters: 
    81             if param.lower() not in self.ows_params: 
    82                 raise OWS_E.MissingParameterValue('%s parameter not specified'%param, 
     82    def getOwsParam(self, param, **kwargs): 
     83        """ 
     84        Returns the value of a OWS parameter passed to the operation. 
     85        If argv['default'] is given it is taken to be the default 
     86        value otherwise the parameter is treated as manditory and an 
     87        exception is raised if the parameter is not present. 
     88 
     89        """ 
     90        try: 
     91            return self._owsParams[param.lower()] 
     92        except KeyError: 
     93            if 'default' in kwargs: 
     94                return kwargs['default'] 
     95            else: 
     96                raise OWS_E.MissingParameterValue('%s parameter is not specified' % param, 
    8397                                                  param) 
    84  
    85  
    86         # override routes action with request 
    87         rdict['action'] = action 
    88         del self.ows_params['request'] 
    89  
    90         # Add ows parameters to routes 
    91         for param in self.ows_params: 
    92             rdict[param] = self.ows_params[param] 
    93  
    9498 
    9599 
     
    123127 
    124128     
    125     @ows_operation(['service'], ['version', 'format', 'updateSequence']) 
     129    @ows_operation 
    126130    def GetCapabilities(self, url, service, version=None, format='text/xml', 
    127131                        updatesequence=None): 
     132 
     133        # Retrieve Operation parameters 
     134        service = self.getOwsParam('service') 
     135        version = self.getOwsParam('version', default=None) 
     136        format = self.getOwsParam('format', default='text/xml') 
     137        updatesequence = self.getOwsParam('updatesequence', default=None) 
    128138 
    129139        # Check update sequence 
Note: See TracChangeset for help on using the changeset viewer.