Ignore:
Timestamp:
08/01/08 12:00:54 (12 years ago)
Author:
spascoe
Message:

Moving OwsController? to it's own module

Location:
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_server/ows_server/lib
Files:
1 added
1 edited

Legend:

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

    r2959 r3183  
    99from pylons.i18n import N_, _, ungettext 
    1010from paste.request import construct_url 
    11 import ows_server.models as model 
    12 import ows_server.lib.helpers as h 
    13 from ows_server.lib.security_util import setSecuritySession, LoginServiceQuery 
    14 from ows_common import exceptions as OWS_E 
    15 from ows_common.operations_metadata import OperationsMetadata, Operation, RequestMethod 
    16 from ows_common.get_capabilities import ServiceMetadata 
    17 import ows_common.xml 
    1811 
    1912 
    20 try: 
    21     from xml.etree import ElementTree as ET 
    22 except ImportError: 
    23     from elementtree import ElementTree as ET 
    24  
    25 import logging 
    26 logger = logging.getLogger(__name__) 
    27  
    28 # Configure 
    29 EXCEPTION_TYPE = request.environ['ndgConfig'].get('OWS_SERVER', 'exception_type', 'ogc').lower() 
    30  
    31  
     13# OwsController is now in a separate module.  Eventually it might be loaded from 
     14# a separate egg. 
     15from ows_controller import OwsController 
    3216 
    3317class BaseController(WSGIController): 
     
    9983        return WSGIController.__call__(self, environ, start_response) 
    10084     
    101 class OwsController(BaseController): 
    102     def __call__(self, environ, start_response): 
    103  
    104         # All OWS parameter names are case insensitive. 
    105         req = request._current_obj() 
    106         self.ows_params = {} 
    107         for k in req.params: 
    108             self.ows_params[k.lower()] = req.params[k]         
    109  
    110         # If the EXCEPTION_TYPE is 'pylons' let Pylons catch any exceptions. 
    111         # Otherwise send an OGC exception report for any OWS_E.OwsError 
    112         if 'pylons' in EXCEPTION_TYPE: 
    113             self._fixOwsAction(environ) 
    114             return super(OwsController, self).__call__(environ, start_response) 
    115         else: 
    116             try: 
    117                 self._fixOwsAction(environ) 
    118                 return super(OwsController, self).__call__(environ, start_response) 
    119             except OWS_E.OwsError, e: 
    120                 logger.exception(e) 
    121  
    122                 r=render_response('exception_report', report=e.report, format='xml') 
    123                 r.headers['content-type'] = 'text/xml' 
    124                 return r 
    125  
    126  
    127     def _fixOwsAction(self, environ): 
    128         # Override the Routes action from the request query parameter 
    129         try: 
    130             action = self.ows_params['request'] 
    131         except KeyError: 
    132             raise OWS_E.MissingParameterValue('REQUEST parameter not specified', 'REQUEST') 
    133  
    134         # Check action is a method in self 
    135         if not getattr(self, action): 
    136             raise OWS_E.InvalidParameterValue('request=%s not supported' % action, 'REQUEST') 
    137  
    138         # override routes action with request 
    139         environ['pylons.routes_dict']['action'] = action 
    140         del self.ows_params['request'] 
    141  
    142     def _loadCapabilities(self): 
    143         """ 
    144         creates an ows_common.get_capabilities.ServiceMetadata object 
    145         by consulting the paste configuration and annotations in the 
    146         controller definition. 
    147  
    148         """ 
    149         # Deduce ows_endpoint from routes 
    150         ows_endpoint = h.url_for(controller=request.environ['pylons.routes_dict']['controller']) 
    151          
    152         #Deduce base_url from config 
    153         base_url =request.environ['ndgConfig'].get('DEFAULT','server') 
    154  
    155          
    156         # Get the server-level configuration data from an XML file 
    157         config = request.environ['paste.config'] 
    158         sm_tree = ET.parse(config['ows_common_config']) 
    159         sm = ows_common.xml.service_metadata(sm_tree.getroot()) 
    160          
    161         # Extract service-level parameters and constraint 
    162         parameters = getattr(self, '_ows_parameters', {}) 
    163         constraints = getattr(self, '_ows_constraints', {}) 
    164         versions = getattr(self, '_ows_versions', []) 
    165          
    166         # Extract operation-level parameters and constraints 
    167         od = {} 
    168         for attr in dir(self): 
    169             op = getattr(self, attr) 
    170             if hasattr(op, '_ows_name'): 
    171                 p = getattr(op, '_ows_parameters', {}) 
    172                 c = getattr(op, '_ows_constraints', {}) 
    173                 od[op._ows_name] = Operation(get=RequestMethod(href=base_url+ows_endpoint), 
    174                                              post=None, 
    175                                              parameters=p, 
    176                                              constraints=c, 
    177                                              name=op._ows_name) 
    178          
    179         sm.operationsMetadata = OperationsMetadata(od, constraints, parameters) 
    180         sm.serviceIdentification.serviceTypeVersions = versions 
    181         return sm 
    182  
    183     def _renderCapabilities(self, template='ows/get_capabilities'): 
    184         """ 
    185         The standard way of returning a Capabilities document. 
    186  
    187         Each subclass should implement self._load_capabilities() and call 
    188         this method to return a response object. 
    189  
    190         """ 
    191         c.service_metadata = self._loadCapabilities()         
    192         r = render_response(template, format='xml') 
    193         r.headers['content-type'] = 'text/xml' 
    194         return r 
    195  
    19685 
    19786# Include the '_' function in the public names 
Note: See TracChangeset for help on using the changeset viewer.