Changeset 3408
- Timestamp:
- 13/02/08 12:20:50 (13 years ago)
- 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 13 13 14 14 from ows_common import exceptions as OWS_E 15 from ows_common.util import negotiate_version 16 from ows_common.pylons.decorators import ows_operation 15 from ows_common.util import negotiate_version, check_updatesequence 17 16 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 17 from genshi.template import TemplateLoader 21 18 22 19 try: … … 28 25 logger = logging.getLogger(__name__) 29 26 27 # Instantiate Genshi template loader 28 genshiLoader = TemplateLoader( 29 resource_filename('ows_common.pylons', 'templates') 30 auto_reload=True 31 ) 32 30 33 # Configure 31 34 #!TODO: rename this configuration object to something non-NDG specific … … 34 37 35 38 39 36 40 class OwsControllerBase(WSGIController): 37 41 """ 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 40 47 """ 48 49 owsOperations = {} 50 41 51 def __call__(self, environ, start_response): 42 52 … … 55 65 logger.exception(e) 56 66 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')) 58 69 response.headers['content-type'] = 'text/xml' 59 70 return response … … 73 84 # Check action is a method in self and is defined as an OWS operation 74 85 try: 75 op = getattr(self, action) 76 name = op._ows_name 86 self.opConfig = self.owsOperations[action] 77 87 except AttributeError: 78 88 raise OWS_E.InvalidParameterValue('request=%s not supported' % action, … … 102 112 Adds basic GetCapabilities response to OwsControllerBase. 103 113 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. 105 120 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. 106 124 """ 107 125 126 # Override these attributes to control how OwsController responds to 127 # GetCapabilities 128 service = None 108 129 validVersions = NotImplemented 109 130 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): 111 138 """ 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. 120 141 121 142 @param version: the version as a sequence of numbers 122 143 @param format: the format as a string 123 144 124 @return: a template as expected 145 @return: a template as expected by pylons.render() 125 146 """ 126 147 raise NotImplementedError 127 128 148 129 @ows_operation 130 def GetCapabilities(self, url, service, version=None, format='text/xml', 131 updatesequence=None): 149 def GetCapabilities(self): 132 150 133 151 # Retrieve Operation parameters … … 138 156 139 157 # 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) 146 159 147 160 # Do version negotiation 148 161 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 151 167 response.headers['content-type'] = format 152 return render(self.getCapabilitiesTemplate(version, format), 153 format='xml') 168 return self.renderCapabilities(version, format) 154 169 155 170 -
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/util.py
r3257 r3408 10 10 11 11 from ows_common.domain import Domain, PossibleValues 12 from ows_common import exceptions as OWS_E 12 13 13 14 def make_domain(value=None, possibleValues=None, **kwargs): … … 55 56 56 57 58 def 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 57 66 #----------------------------------------------------------------------------- 58 67
Note: See TracChangeset
for help on using the changeset viewer.