Skip to content

Commit

Permalink
WFS 2.0 URL building (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
geographika authored Oct 6, 2024
1 parent f620405 commit b9cd08b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 2 additions & 5 deletions owslib/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from urllib.parse import urlencode
from owslib.crs import Crs
from owslib.util import Authentication
from owslib.util import Authentication, build_get_url
from owslib.feature.schema import get_schema
from owslib.feature.postrequest import PostRequest_1_1_0, PostRequest_2_0_0

Expand Down Expand Up @@ -209,7 +209,6 @@ def getGETGetFeatureRequest(
if m.get("type").lower() == method.lower()
)
)
base_url = base_url if base_url.endswith("?") else base_url + "?"

request = {"service": "WFS", "version": self.version, "request": "GetFeature"}

Expand Down Expand Up @@ -248,9 +247,7 @@ def getGETGetFeatureRequest(
if outputFormat is not None:
request["outputFormat"] = outputFormat

data = urlencode(request, doseq=True)

return base_url + data
return build_get_url(base_url, request)

def getPOSTGetFeatureRequest(
self,
Expand Down
4 changes: 2 additions & 2 deletions owslib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def getNamespace(element):
return ""


def build_get_url(base_url, params, overwrite=False):
def build_get_url(base_url, params, overwrite=False, doseq=False):
''' Utility function to build a full HTTP GET URL from the service base URL and a dictionary of HTTP parameters.
TODO: handle parameters case-insensitive?
Expand Down Expand Up @@ -598,7 +598,7 @@ def build_get_url(base_url, params, overwrite=False):
if key not in pars:
qs.append((key, value))

urlqs = urlencode(tuple(qs))
urlqs = urlencode(tuple(qs), doseq=doseq)
return base_url.split('?')[0] + '?' + urlqs


Expand Down
7 changes: 7 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_clean_ows_url():
def test_build_get_url():
assert build_get_url("http://example.org/wps", {'service': 'WPS'}) == 'http://example.org/wps?service=WPS'
assert build_get_url("http://example.org/wms", {'SERVICE': 'wms'}) == 'http://example.org/wms?SERVICE=wms'
assert build_get_url("http://example.org/wms?map=/path/to/foo.map&", {'SERVICE': 'wms'}) == 'http://example.org/wms?map=%2Fpath%2Fto%2Ffoo.map&SERVICE=wms'
assert build_get_url("http://example.org/wps?service=WPS", {'request': 'GetCapabilities'}) == \
'http://example.org/wps?service=WPS&request=GetCapabilities'
assert build_get_url("http://example.org/wps?service=WPS", {'request': 'GetCapabilities'}) == \
Expand All @@ -38,6 +39,12 @@ def test_build_get_url():
# Parameter is case-senstive
assert build_get_url("http://example.org/ows?SERVICE=WPS", {'service': 'WMS'}) == \
'http://example.org/ows?SERVICE=WPS&service=WMS'
# Test with trailing ampersand and doseq False (default)
assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1,2]}, doseq=False) == \
'http://example.org/ows?SERVICE=WFS&typename=test&keys=%5B1%2C+2%5D'
# Test with trailing ampersand and doseq True
assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1,2]}, doseq=True) == \
'http://example.org/ows?SERVICE=WFS&typename=test&keys=1&keys=2'


def test_build_get_url_overwrite():
Expand Down

0 comments on commit b9cd08b

Please sign in to comment.