Changeset 3408 for TI05-delivery


Ignore:
Timestamp:
13/02/08 12:20:50 (12 years ago)
Author:
spascoe
Message:

Trying without any decorators

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

Legend:

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

    r3372 r3408  
    1313 
    1414from ows_common import exceptions as OWS_E 
    15 from ows_common.util import negotiate_version 
    16 from ows_common.pylons.decorators import ows_operation 
     15from ows_common.util import negotiate_version, check_updatesequence 
    1716 
    18 # Import exceptions template 
    19 # This won't work if you haven't enabled Kid importing (already done by pylons) 
    20 from ows_common.pylons.templates import exception_report 
     17from genshi.template import TemplateLoader 
    2118 
    2219try: 
     
    2825logger = logging.getLogger(__name__) 
    2926 
     27# Instantiate Genshi template loader 
     28genshiLoader = TemplateLoader( 
     29    resource_filename('ows_common.pylons', 'templates') 
     30    auto_reload=True 
     31    ) 
     32 
    3033# Configure 
    3134#!TODO: rename this configuration object to something non-NDG specific 
     
    3437 
    3538 
     39 
    3640class OwsControllerBase(WSGIController): 
    3741    """ 
    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. 
     42    @ivar owsParams: A dictionary of parameters passed to the service. 
     43        Initially these comes from the query string but could come from 
     44        a HTTP POST in future. 
     45    @cvar owsOperations: A dictionary of operation configuration options. 
     46    
    4047    """ 
     48 
     49    owsOperations = {} 
     50     
    4151    def __call__(self, environ, start_response): 
    4252 
     
    5565                logger.exception(e) 
    5666 
    57                 response.write(exception_report.serialize(report=e.report)) 
     67                tmpl = genshiLoader.load('exception_report.xml') 
     68                response.write(tmpl.generate(report=e.report).render('xml')) 
    5869                response.headers['content-type'] = 'text/xml' 
    5970                return response 
     
    7384        # Check action is a method in self and is defined as an OWS operation 
    7485        try: 
    75             op = getattr(self, action) 
    76             name = op._ows_name 
     86            self.opConfig = self.owsOperations[action] 
    7787        except AttributeError: 
    7888            raise OWS_E.InvalidParameterValue('request=%s not supported' % action, 
     
    102112    Adds basic GetCapabilities response to OwsControllerBase. 
    103113 
    104     @cvar validVersions: A list of version numbers supported bu this OWS. 
     114    @ivar service: If None does not enforce the SERVICE parameter.  Otherwise 
     115        raises exception if SERVICE is not correct on GetCapabilities request. 
     116    @ivar validCapabilitiesFormats: Sequence of supported Capabilities 
     117        mime-types. 
     118    @cvar validVersions: A list of supported version numbers.  Automatic 
     119        version negotiation is performed according to this attribute. 
    105120     
     121    @ivar updateSequence: None if cache-control is not supported or an 
     122        updateSequence identifier.  This attribute should be set in the 
     123        controller's __before__() method. 
    106124    """ 
    107125 
     126    # Override these attributes to control how OwsController responds to 
     127    # GetCapabilities 
     128    service = None 
    108129    validVersions = NotImplemented 
    109130 
    110     def getUpdateSequence(self, uri): 
     131    owsOperations = dict( 
     132        GetCapabilities = dict(formats=('text/xml',)) 
     133        ) 
     134 
     135    updateSequence = None 
     136 
     137    def renderCapabilities(self, version, format): 
    111138        """ 
    112         Override in subclasses to return a valid updateSequence for the uri. 
    113         """ 
    114         return None 
    115  
    116     def getCapabilitiesTemplate(self, version, format): 
    117         """ 
    118         Get the capabilities template. 
    119         Override in subclases to return a valid template name. 
     139        Override in subclases to render the capabilities document. 
     140        The response mime-type will already have been set. 
    120141 
    121142        @param version: the version as a sequence of numbers 
    122143        @param format: the format as a string 
    123144         
    124         @return: a template as expected  by pylons.render() 
     145        @return: a template as expected by pylons.render() 
    125146        """ 
    126147        raise NotImplementedError 
    127  
    128148     
    129     @ows_operation 
    130     def GetCapabilities(self, url, service, version=None, format='text/xml', 
    131                         updatesequence=None): 
     149    def GetCapabilities(self): 
    132150 
    133151        # Retrieve Operation parameters 
     
    138156 
    139157        # Check update sequence 
    140         serverUpdateSequence = self.getUpdateSequence(uri) 
    141         if updatesequence and serverUpdateSequence: 
    142             if updatesequence == serverUpdateSequence: 
    143                 raise OWS_E.CurrentUpdateSequence 
    144             elif updatesequence > serverUpdateSequence: 
    145                 raise OWS_E.InvalidUpdateSequence 
     158        check_updatesequence(self.updateSequence, updateSequence) 
    146159 
    147160        # Do version negotiation 
    148161        version = negotiate_version(version, self.validVersions) 
    149              
    150         # Render the capabilities document 
     162 
     163        # Get information required for the capabilities document 
     164         
     165         
     166        # Render the capabilities document         
    151167        response.headers['content-type'] = format 
    152         return render(self.getCapabilitiesTemplate(version, format), 
    153                       format='xml') 
     168        return self.renderCapabilities(version, format) 
    154169         
    155170 
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/util.py

    r3257 r3408  
    1010 
    1111from ows_common.domain import Domain, PossibleValues 
     12from ows_common import exceptions as OWS_E 
    1213 
    1314def make_domain(value=None, possibleValues=None, **kwargs): 
     
    5556 
    5657 
     58def check_updatesequence(clientUpdateSequence, serverUpdateSequence): 
     59    if clientUpdateSequence and serverUpdateSequence: 
     60        if client_updatesequence == serverUpdateSequence: 
     61            raise OWS_E.CurrentUpdateSequence 
     62        elif client_updatesequence > serverUpdateSequence: 
     63            raise OWS_E.InvalidUpdateSequence 
     64     
     65 
    5766#----------------------------------------------------------------------------- 
    5867 
Note: See TracChangeset for help on using the changeset viewer.