django-gisserver 1.5.0__py3-none-any.whl → 2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_gisserver-1.5.0.dist-info → django_gisserver-2.0.dist-info}/METADATA +14 -4
- django_gisserver-2.0.dist-info/RECORD +66 -0
- {django_gisserver-1.5.0.dist-info → django_gisserver-2.0.dist-info}/WHEEL +1 -1
- gisserver/__init__.py +1 -1
- gisserver/compat.py +23 -0
- gisserver/conf.py +7 -0
- gisserver/db.py +56 -47
- gisserver/exceptions.py +26 -2
- gisserver/extensions/__init__.py +4 -0
- gisserver/{parsers/fes20 → extensions}/functions.py +10 -4
- gisserver/extensions/queries.py +261 -0
- gisserver/features.py +220 -156
- gisserver/geometries.py +32 -37
- gisserver/management/__init__.py +0 -0
- gisserver/management/commands/__init__.py +0 -0
- gisserver/management/commands/loadgeojson.py +291 -0
- gisserver/operations/base.py +122 -308
- gisserver/operations/wfs20.py +423 -337
- gisserver/output/__init__.py +9 -48
- gisserver/output/base.py +178 -139
- gisserver/output/csv.py +65 -74
- gisserver/output/geojson.py +34 -35
- gisserver/output/gml32.py +254 -246
- gisserver/output/iters.py +207 -0
- gisserver/output/results.py +52 -26
- gisserver/output/stored.py +143 -0
- gisserver/output/utils.py +75 -170
- gisserver/output/xmlschema.py +85 -46
- gisserver/parsers/__init__.py +10 -10
- gisserver/parsers/ast.py +320 -0
- gisserver/parsers/fes20/__init__.py +13 -27
- gisserver/parsers/fes20/expressions.py +82 -38
- gisserver/parsers/fes20/filters.py +111 -43
- gisserver/parsers/fes20/identifiers.py +44 -26
- gisserver/parsers/fes20/lookups.py +144 -0
- gisserver/parsers/fes20/operators.py +331 -127
- gisserver/parsers/fes20/sorting.py +104 -33
- gisserver/parsers/gml/__init__.py +12 -11
- gisserver/parsers/gml/base.py +5 -2
- gisserver/parsers/gml/geometries.py +69 -35
- gisserver/parsers/ows/__init__.py +25 -0
- gisserver/parsers/ows/kvp.py +190 -0
- gisserver/parsers/ows/requests.py +158 -0
- gisserver/parsers/query.py +175 -0
- gisserver/parsers/values.py +26 -0
- gisserver/parsers/wfs20/__init__.py +37 -0
- gisserver/parsers/wfs20/adhoc.py +245 -0
- gisserver/parsers/wfs20/base.py +143 -0
- gisserver/parsers/wfs20/projection.py +103 -0
- gisserver/parsers/wfs20/requests.py +482 -0
- gisserver/parsers/wfs20/stored.py +192 -0
- gisserver/parsers/xml.py +249 -0
- gisserver/projection.py +357 -0
- gisserver/static/gisserver/index.css +12 -1
- gisserver/templates/gisserver/index.html +1 -1
- gisserver/templates/gisserver/service_description.html +2 -2
- gisserver/templates/gisserver/wfs/2.0.0/get_capabilities.xml +9 -9
- gisserver/templates/gisserver/wfs/feature_field.html +2 -2
- gisserver/templatetags/gisserver_tags.py +20 -0
- gisserver/types.py +322 -259
- gisserver/views.py +198 -56
- django_gisserver-1.5.0.dist-info/RECORD +0 -54
- gisserver/parsers/base.py +0 -149
- gisserver/parsers/fes20/query.py +0 -285
- gisserver/parsers/tags.py +0 -102
- gisserver/queries/__init__.py +0 -37
- gisserver/queries/adhoc.py +0 -185
- gisserver/queries/base.py +0 -186
- gisserver/queries/projection.py +0 -240
- gisserver/queries/stored.py +0 -206
- gisserver/templates/gisserver/wfs/2.0.0/describe_stored_queries.xml +0 -20
- gisserver/templates/gisserver/wfs/2.0.0/list_stored_queries.xml +0 -14
- {django_gisserver-1.5.0.dist-info → django_gisserver-2.0.dist-info}/LICENSE +0 -0
- {django_gisserver-1.5.0.dist-info → django_gisserver-2.0.dist-info}/top_level.txt +0 -0
gisserver/operations/base.py
CHANGED
|
@@ -1,141 +1,73 @@
|
|
|
1
1
|
"""The base protocol to implement an operation.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The request itself is parsed by :mod:`gisserver.parsers.wfs20`, and handled here.
|
|
4
|
+
It can be seen as the "controller" that handles the actual request type.
|
|
5
|
+
|
|
6
|
+
All operations extend from an WFSOperation class.
|
|
7
|
+
This defines the metadata for the ``GetCapabilities`` call and possible output formats.
|
|
8
|
+
|
|
9
|
+
Each :class:`WFSOperation` can define a :attr:`~WFSOperation.parser_class`, or let it autodetect.
|
|
6
10
|
"""
|
|
7
11
|
|
|
8
12
|
from __future__ import annotations
|
|
9
13
|
|
|
14
|
+
import logging
|
|
10
15
|
import math
|
|
11
16
|
import re
|
|
12
|
-
|
|
13
|
-
from dataclasses import dataclass
|
|
14
|
-
from
|
|
17
|
+
import typing
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from functools import cached_property
|
|
15
20
|
|
|
16
|
-
from django.core.exceptions import
|
|
21
|
+
from django.core.exceptions import SuspiciousOperation
|
|
17
22
|
from django.http import HttpResponse
|
|
18
23
|
from django.template.loader import render_to_string
|
|
19
24
|
|
|
20
|
-
from gisserver.exceptions import
|
|
21
|
-
ExternalParsingError,
|
|
22
|
-
InvalidParameterValue,
|
|
23
|
-
MissingParameterValue,
|
|
24
|
-
OperationParsingFailed,
|
|
25
|
-
)
|
|
25
|
+
from gisserver.exceptions import InvalidParameterValue
|
|
26
26
|
from gisserver.features import FeatureType
|
|
27
|
+
from gisserver.output.base import OutputRenderer
|
|
28
|
+
from gisserver.parsers import ows
|
|
29
|
+
from gisserver.parsers.values import fix_type_name
|
|
27
30
|
|
|
31
|
+
if typing.TYPE_CHECKING:
|
|
32
|
+
from gisserver.views import WFSView
|
|
33
|
+
|
|
34
|
+
logger = logging.getLogger(__name__)
|
|
28
35
|
NoneType = type(None)
|
|
36
|
+
R = typing.TypeVar("R", bound=OutputRenderer)
|
|
29
37
|
|
|
30
38
|
RE_SAFE_FILENAME = re.compile(r"\A[A-Za-z0-9]+[A-Za-z0-9.]*") # no dot at the start.
|
|
31
39
|
|
|
40
|
+
__all__ = (
|
|
41
|
+
"Parameter",
|
|
42
|
+
"OutputFormat",
|
|
43
|
+
"WFSOperation",
|
|
44
|
+
"OutputFormatMixin",
|
|
45
|
+
"XmlTemplateMixin",
|
|
46
|
+
)
|
|
47
|
+
|
|
32
48
|
|
|
33
49
|
@dataclass(frozen=True)
|
|
34
50
|
class Parameter:
|
|
35
|
-
"""The
|
|
51
|
+
"""The ``<ows:Parameter>`` tag to output in ``GetCapabilities``."""
|
|
36
52
|
|
|
37
|
-
These parameters should be defined in the
|
|
38
|
-
WFSMethod parameters attribute / get_parameters().
|
|
39
|
-
|
|
40
|
-
These fields are used to parse the incoming request.
|
|
41
|
-
The GetCapabilities method also reads the metadata of this value.
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
#: Name of the parameter (using the XML casing style)
|
|
45
53
|
name: str
|
|
54
|
+
allowed_values: list[str]
|
|
46
55
|
|
|
47
|
-
#: Alias name (e.g. typenames/typename)
|
|
48
|
-
alias: str | None = None
|
|
49
|
-
|
|
50
|
-
#: Whether the parameter is required
|
|
51
|
-
required: bool = False
|
|
52
|
-
|
|
53
|
-
#: Optional parser callback to convert the parameter into a Python type
|
|
54
|
-
parser: Callable[[str], Any] = None
|
|
55
|
-
|
|
56
|
-
#: Whether to list this parameter in GetCapabilities
|
|
57
|
-
in_capabilities: bool = False
|
|
58
|
-
|
|
59
|
-
#: List of allowed values (also shown in GetCapabilities)
|
|
60
|
-
allowed_values: list | tuple | set | NoneType = None
|
|
61
|
-
|
|
62
|
-
#: Default value if it's not given
|
|
63
|
-
default: Any = None
|
|
64
|
-
|
|
65
|
-
#: Overridable dict for error messages
|
|
66
|
-
error_messages: dict = field(default_factory=dict)
|
|
67
|
-
|
|
68
|
-
def value_from_query(self, KVP: dict): # noqa: C901
|
|
69
|
-
"""Parse a request variable using the type definition.
|
|
70
|
-
|
|
71
|
-
This uses the dataclass settings to parse the incoming request value.
|
|
72
|
-
"""
|
|
73
|
-
# URL-based key-value-pair parameters use uppercase.
|
|
74
|
-
kvp_name = self.name.upper()
|
|
75
|
-
value = KVP.get(kvp_name)
|
|
76
|
-
if not value and self.alias:
|
|
77
|
-
value = KVP.get(self.alias.upper())
|
|
78
|
-
|
|
79
|
-
# Check required field settings, both empty and missing value are treated the same.
|
|
80
|
-
if not value:
|
|
81
|
-
if not self.required:
|
|
82
|
-
return self.default
|
|
83
|
-
elif value is None:
|
|
84
|
-
raise MissingParameterValue(f"Missing {kvp_name} parameter", locator=self.name)
|
|
85
|
-
else:
|
|
86
|
-
raise InvalidParameterValue(f"Empty {kvp_name} parameter", locator=self.name)
|
|
87
|
-
|
|
88
|
-
# Allow conversion into a python object
|
|
89
|
-
if self.parser is not None:
|
|
90
|
-
try:
|
|
91
|
-
value = self.parser(value)
|
|
92
|
-
except ExternalParsingError as e:
|
|
93
|
-
raise OperationParsingFailed(
|
|
94
|
-
f"Unable to parse {kvp_name} argument: {e}",
|
|
95
|
-
locator=self.name,
|
|
96
|
-
) from None
|
|
97
|
-
except (TypeError, ValueError, NotImplementedError) as e:
|
|
98
|
-
# TypeError/ValueError are raised by most handlers for unexpected data
|
|
99
|
-
# The NotImplementedError can be raised by fes parsing.
|
|
100
|
-
raise InvalidParameterValue(
|
|
101
|
-
f"Invalid {kvp_name} argument: {e}",
|
|
102
|
-
locator=self.name,
|
|
103
|
-
) from None
|
|
104
|
-
|
|
105
|
-
# Validate against value choices
|
|
106
|
-
self.validate_value(value)
|
|
107
|
-
|
|
108
|
-
return value
|
|
109
|
-
|
|
110
|
-
def validate_value(self, value):
|
|
111
|
-
"""Validate the parsed value.
|
|
112
|
-
This method can be overwritten by a subclass if needed.
|
|
113
|
-
"""
|
|
114
|
-
if self.allowed_values is not None and value not in self.allowed_values:
|
|
115
|
-
msg = self.error_messages.get("invalid", "Invalid value for {name}: {value}")
|
|
116
|
-
raise InvalidParameterValue(msg.format(name=self.name, value=value), locator=self.name)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
class UnsupportedParameter(Parameter):
|
|
120
|
-
def value_from_query(self, KVP: dict):
|
|
121
|
-
kvp_name = self.name.upper()
|
|
122
|
-
if kvp_name in KVP:
|
|
123
|
-
raise InvalidParameterValue(
|
|
124
|
-
f"Support for {self.name} is not implemented!", locator=self.name
|
|
125
|
-
)
|
|
126
|
-
return None
|
|
127
56
|
|
|
128
|
-
|
|
129
|
-
class OutputFormat:
|
|
57
|
+
class OutputFormat(typing.Generic[R]):
|
|
130
58
|
"""Declare an output format for the method.
|
|
131
59
|
|
|
132
|
-
These formats
|
|
60
|
+
These formats are used in the :meth:`get_output_formats` for
|
|
61
|
+
any WFSMethod that implements :class:`OutputFormatMixin`.
|
|
62
|
+
This also connects the output format with a :attr:`renderer_class`.
|
|
133
63
|
"""
|
|
134
64
|
|
|
135
65
|
def __init__(
|
|
136
66
|
self,
|
|
137
67
|
content_type,
|
|
138
|
-
|
|
68
|
+
*,
|
|
69
|
+
subtype=None,
|
|
70
|
+
renderer_class: type[R] | None = None, # None is special case for GetCapabilities
|
|
139
71
|
max_page_size=None,
|
|
140
72
|
title=None,
|
|
141
73
|
in_capabilities=True,
|
|
@@ -143,17 +75,16 @@ class OutputFormat:
|
|
|
143
75
|
):
|
|
144
76
|
"""
|
|
145
77
|
:param content_type: The MIME-type used in the request to select this type.
|
|
78
|
+
:param subtype: Shorter alias for the MIME-type.
|
|
146
79
|
:param renderer_class: The class that performs the output rendering.
|
|
147
|
-
If it's not given, the operation renders it's output using an XML template.
|
|
148
80
|
:param max_page_size: Used to override the ``max_page_size`` of the renderer_class.
|
|
149
81
|
:param title: A human-friendly name for an HTML overview page.
|
|
150
82
|
:param in_capabilities: Whether this format needs to be advertised in GetCapabilities.
|
|
151
83
|
:param extra: Any additional key-value pairs for the definition.
|
|
152
|
-
Could include ``subtype`` as a shorter alias for the MIME-type.
|
|
153
84
|
"""
|
|
154
85
|
self.content_type = content_type
|
|
86
|
+
self.subtype = subtype
|
|
155
87
|
self.extra = extra
|
|
156
|
-
self.subtype = self.extra.get("subtype")
|
|
157
88
|
self.renderer_class = renderer_class
|
|
158
89
|
self.title = title
|
|
159
90
|
self.in_capabilities = in_capabilities
|
|
@@ -189,177 +120,101 @@ class OutputFormat:
|
|
|
189
120
|
|
|
190
121
|
def __str__(self):
|
|
191
122
|
extra = "".join(f"; {name}={value}" for name, value in self.extra.items())
|
|
123
|
+
if self.subtype:
|
|
124
|
+
extra = f"; subtype={self.subtype}{extra}"
|
|
192
125
|
return f"{self.content_type}{extra}"
|
|
193
126
|
|
|
194
127
|
def __repr__(self):
|
|
195
128
|
return f"<OutputFormat: {self}>"
|
|
196
129
|
|
|
197
130
|
|
|
198
|
-
class
|
|
131
|
+
class WFSOperation:
|
|
199
132
|
"""Basic interface to implement an WFS method.
|
|
200
133
|
|
|
201
134
|
Each operation in this GIS-server extends from this base class. This class
|
|
202
135
|
also exposes all requires metadata for the GetCapabilities request.
|
|
203
136
|
"""
|
|
204
137
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
parameters: list[Parameter] = []
|
|
209
|
-
|
|
210
|
-
#: List the supported output formats for this method.
|
|
211
|
-
output_formats: list[OutputFormat] = []
|
|
212
|
-
|
|
213
|
-
#: Default template to use for rendering
|
|
214
|
-
xml_template_name = None
|
|
138
|
+
#: Optionally, mention explicitly what the parser class should be used.
|
|
139
|
+
#: Otherwise, it's automatically resolved from the registered types.
|
|
140
|
+
parser_class: type[ows.BaseOwsRequest] = None
|
|
215
141
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
def __init__(self, view):
|
|
220
|
-
self.view = view # an gisserver.views.GISView
|
|
221
|
-
self.namespaces = {
|
|
222
|
-
# Default namespaces for the incoming request:
|
|
223
|
-
"http://www.w3.org/XML/1998/namespace": "xml",
|
|
224
|
-
"http://www.opengis.net/wfs/2.0": "wfs",
|
|
225
|
-
"http://www.opengis.net/gml/3.2": "gml",
|
|
226
|
-
self.view.xml_namespace: "app",
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
def get_parameters(self):
|
|
230
|
-
"""Dynamically return the supported parameters for this method."""
|
|
231
|
-
parameters = [
|
|
232
|
-
# Always add SERVICE and VERSION as required parameters
|
|
233
|
-
# Part of BaseRequest:
|
|
234
|
-
Parameter(
|
|
235
|
-
"service",
|
|
236
|
-
required=not bool(self.view.default_service),
|
|
237
|
-
in_capabilities=True,
|
|
238
|
-
allowed_values=list(self.view.accept_operations.keys()),
|
|
239
|
-
default=self.view.default_service, # can be None or e.g. "WFS"
|
|
240
|
-
error_messages={"invalid": "Unsupported service type: {value}."},
|
|
241
|
-
),
|
|
242
|
-
Parameter(
|
|
243
|
-
"version",
|
|
244
|
-
required=True, # Mandatory except for GetCapabilities
|
|
245
|
-
allowed_values=self.view.accept_versions,
|
|
246
|
-
error_messages={
|
|
247
|
-
"invalid": "WFS Server does not support VERSION {value}.",
|
|
248
|
-
},
|
|
249
|
-
),
|
|
250
|
-
] + self.parameters
|
|
251
|
-
|
|
252
|
-
if self.output_formats:
|
|
253
|
-
parameters += [
|
|
254
|
-
# Part of StandardPresentationParameters:
|
|
255
|
-
Parameter(
|
|
256
|
-
"outputFormat",
|
|
257
|
-
in_capabilities=True,
|
|
258
|
-
allowed_values=self.output_formats,
|
|
259
|
-
parser=self._parse_output_format,
|
|
260
|
-
default=self.output_formats[0],
|
|
261
|
-
)
|
|
262
|
-
]
|
|
142
|
+
def __init__(self, view: WFSView, ows_request: ows.BaseOwsRequest):
|
|
143
|
+
self.view = view
|
|
144
|
+
self.ows_request = ows_request
|
|
263
145
|
|
|
264
|
-
|
|
146
|
+
def get_parameters(self) -> list[Parameter]:
|
|
147
|
+
"""Parameters to advertise in the capabilities for this method."""
|
|
148
|
+
return [
|
|
149
|
+
# Always advertise SERVICE and VERSION as required parameters:
|
|
150
|
+
Parameter("service", allowed_values=list(self.view.accept_operations.keys())),
|
|
151
|
+
Parameter("version", allowed_values=self.view.accept_versions),
|
|
152
|
+
]
|
|
265
153
|
|
|
266
|
-
def
|
|
267
|
-
"""
|
|
268
|
-
# When using ?OUTPUTFORMAT=application/gml+xml", it is actually a URL-encoded space
|
|
269
|
-
# character. Hence, spaces are replaced back to a '+' character to allow such notation
|
|
270
|
-
# instead of forcing it to be ?OUTPUTFORMAT=application/gml%2bxml".
|
|
271
|
-
for v in {value, value.replace(" ", "+")}:
|
|
272
|
-
for o in self.output_formats:
|
|
273
|
-
if o.matches(v):
|
|
274
|
-
return o
|
|
275
|
-
raise InvalidParameterValue(
|
|
276
|
-
f"'{value}' is not a permitted output format for this operation.",
|
|
277
|
-
locator="outputformat",
|
|
278
|
-
) from None
|
|
154
|
+
def validate_request(self, ows_request: ows.BaseOwsRequest):
|
|
155
|
+
"""Validate the request."""
|
|
279
156
|
|
|
280
|
-
def
|
|
281
|
-
"""
|
|
157
|
+
def process_request(self, ows_request: ows.BaseOwsRequest):
|
|
158
|
+
"""Default call implementation: render an XML template."""
|
|
159
|
+
raise NotImplementedError()
|
|
282
160
|
|
|
283
|
-
|
|
284
|
-
|
|
161
|
+
@cached_property
|
|
162
|
+
def all_feature_types_by_name(self) -> dict[str, FeatureType]:
|
|
163
|
+
"""Create a lookup for feature types by name.
|
|
164
|
+
This can be cached as the WFSMethod is instantiated with each request
|
|
285
165
|
"""
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
166
|
+
return {ft.xml_name: ft for ft in self.view.get_bound_feature_types()}
|
|
167
|
+
|
|
168
|
+
def resolve_feature_type(self, type_name: str, locator: str = "typeNames") -> FeatureType:
|
|
169
|
+
"""Find the FeatureType defined in the application that corresponds with the XML type name."""
|
|
170
|
+
alt_type_name = fix_type_name(type_name, self.view.xml_namespace)
|
|
171
|
+
try:
|
|
172
|
+
return self.all_feature_types_by_name[alt_type_name]
|
|
173
|
+
except KeyError:
|
|
174
|
+
if alt_type_name:
|
|
175
|
+
logger.debug(
|
|
176
|
+
"Unable to locate '%s' (nor %s) in the server, options are: %r",
|
|
177
|
+
type_name,
|
|
178
|
+
alt_type_name,
|
|
179
|
+
list(self.all_feature_types_by_name),
|
|
299
180
|
)
|
|
300
|
-
if prefix.endswith(")"):
|
|
301
|
-
# xmlns(http://...)
|
|
302
|
-
prefix = ""
|
|
303
|
-
uri = prefix[6:-1]
|
|
304
181
|
else:
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
namespaces[uri] = prefix
|
|
315
|
-
|
|
316
|
-
return namespaces
|
|
317
|
-
|
|
318
|
-
def parse_request(self, KVP: dict) -> dict[str, Any]:
|
|
319
|
-
"""Parse the parameters of the request"""
|
|
320
|
-
self.namespaces.update(self._parse_namespaces(KVP.get("NAMESPACES")))
|
|
321
|
-
param_values = {param.name: param.value_from_query(KVP) for param in self.get_parameters()}
|
|
322
|
-
param_values["NAMESPACES"] = self.namespaces
|
|
323
|
-
|
|
324
|
-
for param in self.get_parameters():
|
|
325
|
-
param_values[param.name] = param.value_from_query(KVP)
|
|
326
|
-
|
|
327
|
-
# Update version if requested.
|
|
328
|
-
# This is stored on the view, so exceptions also use it.
|
|
329
|
-
if param_values.get("version"):
|
|
330
|
-
self.view.set_version(param_values["version"])
|
|
182
|
+
logger.debug(
|
|
183
|
+
"Unable to locate '%s' in the server, options are: %r",
|
|
184
|
+
type_name,
|
|
185
|
+
list(self.all_feature_types_by_name),
|
|
186
|
+
)
|
|
187
|
+
raise InvalidParameterValue(
|
|
188
|
+
f"Typename '{type_name}' doesn't exist in this server.",
|
|
189
|
+
locator=locator or "typeNames",
|
|
190
|
+
) from None
|
|
331
191
|
|
|
332
|
-
self.validate(**param_values)
|
|
333
|
-
return param_values
|
|
334
192
|
|
|
335
|
-
|
|
336
|
-
|
|
193
|
+
class XmlTemplateMixin:
|
|
194
|
+
"""Mixin to support methods that render using a template."""
|
|
337
195
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
context = self.get_context_data(**params)
|
|
341
|
-
if "outputFormat" in params:
|
|
342
|
-
output_format: OutputFormat = params["outputFormat"]
|
|
196
|
+
#: Default template to use for rendering
|
|
197
|
+
xml_template_name = None
|
|
343
198
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
renderer = output_format.renderer_class(self, **context)
|
|
347
|
-
return renderer.get_response()
|
|
199
|
+
#: Default content-type for render_xml()
|
|
200
|
+
xml_content_type = "text/xml; charset=utf-8"
|
|
348
201
|
|
|
349
|
-
|
|
202
|
+
def process_request(self, ows_request: ows.BaseOwsRequest):
|
|
203
|
+
context = self.get_context_data()
|
|
204
|
+
return self.render_xml(context, ows_request)
|
|
350
205
|
|
|
351
|
-
def get_context_data(self
|
|
206
|
+
def get_context_data(self):
|
|
352
207
|
"""Collect all arguments to use for rendering the XML template"""
|
|
353
208
|
return {}
|
|
354
209
|
|
|
355
|
-
def render_xml(self, context,
|
|
210
|
+
def render_xml(self, context, ows_request: ows.BaseOwsRequest):
|
|
356
211
|
"""Shortcut to render XML.
|
|
357
212
|
|
|
358
213
|
This is the default method when the OutputFormat class doesn't have a renderer_class
|
|
359
214
|
"""
|
|
360
215
|
return HttpResponse(
|
|
361
216
|
render_to_string(
|
|
362
|
-
self._get_xml_template_name(),
|
|
217
|
+
self._get_xml_template_name(ows_request),
|
|
363
218
|
context={
|
|
364
219
|
"view": self.view,
|
|
365
220
|
"app_xml_namespace": self.view.xml_namespace,
|
|
@@ -370,9 +225,9 @@ class WFSMethod:
|
|
|
370
225
|
content_type=self.xml_content_type,
|
|
371
226
|
)
|
|
372
227
|
|
|
373
|
-
def _get_xml_template_name(self):
|
|
228
|
+
def _get_xml_template_name(self, ows_request: ows.BaseOwsRequest) -> str:
|
|
374
229
|
"""Generate the XML template name for this operation, and check its file pattern"""
|
|
375
|
-
service =
|
|
230
|
+
service = ows_request.service.lower()
|
|
376
231
|
template_name = f"gisserver/{service}/{self.view.version}/{self.xml_template_name}"
|
|
377
232
|
|
|
378
233
|
# Since 'service' and 'version' are based on external input,
|
|
@@ -383,66 +238,25 @@ class WFSMethod:
|
|
|
383
238
|
return template_name
|
|
384
239
|
|
|
385
240
|
|
|
386
|
-
class
|
|
387
|
-
"""
|
|
388
|
-
|
|
389
|
-
def __init__(self, *args, **kwargs):
|
|
390
|
-
super().__init__(*args, **kwargs)
|
|
391
|
-
|
|
392
|
-
# Retrieve the feature types directly, as these are needed during parsing.
|
|
393
|
-
# This is not delayed until _parse_type_names() as that wraps any TypeError
|
|
394
|
-
# from view.get_feature_types() as an InvalidParameterValue exception.
|
|
395
|
-
self.all_feature_types = self.view.get_feature_types()
|
|
396
|
-
self.all_feature_types_by_name = _get_feature_types_by_name(self.all_feature_types)
|
|
241
|
+
class OutputFormatMixin:
|
|
242
|
+
"""Mixin to support methods that handle different output formats."""
|
|
397
243
|
|
|
398
|
-
def
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
"typeNames",
|
|
404
|
-
alias="typeName", # WFS 1.0 name, but still needed for CITE tests
|
|
405
|
-
required=False, # sometimes required, depends on other parameters
|
|
406
|
-
parser=self._parse_type_names,
|
|
407
|
-
),
|
|
408
|
-
]
|
|
409
|
-
|
|
410
|
-
def _parse_type_names(self, type_names) -> list[FeatureType]:
|
|
411
|
-
"""Find the requested feature types by name"""
|
|
412
|
-
if "(" in type_names:
|
|
413
|
-
# This allows to perform multiple queries in a single request:
|
|
414
|
-
# TYPENAMES=(A)(B)&FILTER=(filter for A)(filter for B)
|
|
415
|
-
raise OperationParsingFailed(
|
|
416
|
-
"Parameter lists to perform multiple queries are not supported yet.",
|
|
417
|
-
locator="typenames",
|
|
418
|
-
)
|
|
419
|
-
|
|
420
|
-
return [self._parse_type_name(name, locator="typenames") for name in type_names.split(",")]
|
|
421
|
-
|
|
422
|
-
def _parse_type_name(self, name, locator="typename") -> FeatureType:
|
|
423
|
-
"""Find the requested feature type for a type name"""
|
|
424
|
-
app_prefix = self.namespaces[self.view.xml_namespace]
|
|
425
|
-
# strip our XML prefix
|
|
426
|
-
local_name = name[len(app_prefix) + 1 :] if name.startswith(f"{app_prefix}:") else name
|
|
427
|
-
|
|
428
|
-
try:
|
|
429
|
-
return self.all_feature_types_by_name[local_name]
|
|
430
|
-
except KeyError:
|
|
431
|
-
raise InvalidParameterValue(
|
|
432
|
-
f"Typename '{name}' doesn't exist in this server. "
|
|
433
|
-
f"Please check the capabilities and reformulate your request.",
|
|
434
|
-
locator=locator,
|
|
435
|
-
) from None
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
def _get_feature_types_by_name(feature_types) -> dict[str, FeatureType]:
|
|
439
|
-
"""Create a lookup for feature types by name."""
|
|
440
|
-
features_by_name = {ft.name: ft for ft in feature_types}
|
|
441
|
-
|
|
442
|
-
# Check against bad configuration
|
|
443
|
-
if len(features_by_name) != len(feature_types):
|
|
444
|
-
all_names = [ft.name for ft in feature_types]
|
|
445
|
-
duplicates = ", ".join(sorted({n for n in all_names if all_names.count(n) > 1}))
|
|
446
|
-
raise ImproperlyConfigured(f"FeatureType names should be unique: {duplicates}")
|
|
244
|
+
def get_output_formats(self) -> list[OutputFormat]:
|
|
245
|
+
"""List all output formats. This is exposed in GetCapabilities,
|
|
246
|
+
and used for internal rendering.
|
|
247
|
+
"""
|
|
248
|
+
raise NotImplementedError()
|
|
447
249
|
|
|
448
|
-
|
|
250
|
+
def resolve_output_format(self, value, locator="outputFormat") -> OutputFormat:
|
|
251
|
+
"""Select the proper OutputFormat object based on the input value"""
|
|
252
|
+
# When using ?OUTPUTFORMAT=application/gml+xml", it is actually a URL-encoded space
|
|
253
|
+
# character. Hence, spaces are replaced back to a '+' character to allow such notation
|
|
254
|
+
# instead of forcing it to be ?OUTPUTFORMAT=application/gml%2bxml".
|
|
255
|
+
for v in {value, value.replace(" ", "+")}:
|
|
256
|
+
for o in self.get_output_formats():
|
|
257
|
+
if o.matches(v):
|
|
258
|
+
return o
|
|
259
|
+
raise InvalidParameterValue(
|
|
260
|
+
f"'{value}' is not a permitted output format for this operation.",
|
|
261
|
+
locator=locator or "outputFormat",
|
|
262
|
+
) from None
|