Ignore:
Timestamp:
22/05/07 14:37:01 (12 years ago)
Author:
spascoe
Message:

Some bug fixes to ows_common. OwsController?._load_capabilities implements
discovery of capabilities from a controller definition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/base.py

    r2494 r2502  
    88import ows_server.lib.helpers as h 
    99 
    10 from ows_common.exception_report import OwsError 
     10from ows_common import exceptions as OWS_E 
     11from ows_common.operations_metadata import OperationsMetadata, Operation 
     12from ows_common.get_capabilities import ServiceMetadata 
    1113 
    1214class BaseController(WSGIController): 
     
    1618        # the action or route vars here 
    1719        return WSGIController.__call__(self, environ, start_response) 
    18  
     20     
    1921class OwsController(BaseController): 
    2022    def __call__(self, environ, start_response): 
     23 
     24        # Ensure the capabilities document is loaded 
     25        self._load_capabilities() 
    2126 
    2227        # All OWS parameter names are case insensitive. 
     
    3944            action = self.ows_params['request'] 
    4045        except KeyError: 
    41             raise OwsError('MissingParameterValue', 'request parameter not specified', 'request') 
     46            raise OWS_E.MissingParameterValue('REQUEST parameter not specified', 'REQUEST') 
    4247 
    4348        # Check action is a method in self 
    4449        if not getattr(self, action): 
    45             raise OwsError('InvalidParameterValue', 'request=%s not supported' % action, 'request') 
     50            raise OWS_E.InvalidParameterValue('request=%s not supported' % action, 'REQUEST') 
    4651 
    4752        # override routes action with request 
     
    5055 
    5156    def _get_method_args(self): 
    52         """Extends Controller._get_method_args to retrieve arguments from the query string. 
     57        """Extends Controller._get_method_args to retrieve arguments 
     58        from the query string. 
    5359 
    5460        See the docstring for Controller._get_method_args for details. 
     
    6268        return kargs 
    6369 
     70    def _load_capabilities(self, ows_endpoint): 
     71        """ 
     72        creates an ows_common.get_capabilities.ServiceMetadata object 
     73        by consulting the paste configuration and annotations in the 
     74        controller definition.  The endpoint must be supplied to allow 
     75        a controller to serve multiple ows endpoints. 
     76 
     77        @param ows_endpoint: The URI of the OWS endpoint being served 
     78            by this controller. 
     79 
     80        """ 
     81        if hasattr(self, '_ows_service_metadata'): 
     82            return 
     83 
     84        parameters = getattr(self, '_ows_parameters', {}) 
     85        constraints = getattr(self, '_ows_constraints', {}) 
     86 
     87        od = {} 
     88        for attr in dir(self): 
     89            op = getattr(self, attr) 
     90            if hasattr(op, '_ows_name'): 
     91                p = getattr(op, '_ows_parameters', {}) 
     92                c = getattr(op, '_ows_constraints', {}) 
     93                od[op._ows_name] = Operation(get=ows_endpoint, 
     94                                                    post=None, 
     95                                                    parameters=p, 
     96                                                    constraints=c) 
     97         
     98        om = OperationsMetadata(od, constraints, parameters) 
     99        return ServiceMetadata(operationsMetadata=om) 
     100 
    64101# Include the '_' function in the public names 
    65102__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \ 
Note: See TracChangeset for help on using the changeset viewer.