diff --git a/owslib/feature/__init__.py b/owslib/feature/__init__.py index 9f3de0f1..b46ff951 100644 --- a/owslib/feature/__init__.py +++ b/owslib/feature/__init__.py @@ -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 @@ -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"} @@ -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, diff --git a/owslib/util.py b/owslib/util.py index 5e1e560e..dfc16b32 100644 --- a/owslib/util.py +++ b/owslib/util.py @@ -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? @@ -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 diff --git a/tests/test_util.py b/tests/test_util.py index 975822b4..70a9148d 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -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'}) == \ @@ -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():