Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up code in WFS classes #892

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 10 additions & 37 deletions owslib/feature/wfs100.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,26 @@ class WebFeatureService_1_0_0(object):
Implements IWebFeatureService.
"""

def __new__(
def __getitem__(self, name):
""" check contents dictionary to allow dict like access to service layers"""
if name in list(self.__getattribute__("contents").keys()):
return self.__getattribute__("contents")[name]
else:
raise KeyError("No content named %s" % name)

def __init__(
self,
url,
version,
xml,
xml=None,
parse_remote_metadata=False,
timeout=30,
headers=None,
username=None,
password=None,
auth=None,
):
""" overridden __new__ method
"""Initialize.

@type url: string
@param url: url of WFS capabilities document
Expand All @@ -102,40 +109,6 @@ def __new__(
@param auth: instance of owslib.util.Authentication
@return: initialized WebFeatureService_1_0_0 object
"""
obj = object.__new__(self)
obj.__init__(
url,
version,
xml,
parse_remote_metadata,
timeout,
headers=headers,
username=username,
password=password,
auth=auth,
)
return obj

def __getitem__(self, name):
""" check contents dictionary to allow dict like access to service layers"""
if name in list(self.__getattribute__("contents").keys()):
return self.__getattribute__("contents")[name]
else:
raise KeyError("No content named %s" % name)

def __init__(
self,
url,
version,
xml=None,
parse_remote_metadata=False,
timeout=30,
headers=None,
username=None,
password=None,
auth=None,
):
"""Initialize."""
if auth:
if username:
auth.username = username
Expand Down
47 changes: 10 additions & 37 deletions owslib/feature/wfs110.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,26 @@ class WebFeatureService_1_1_0(WebFeatureService_):
Implements IWebFeatureService.
"""

def __new__(
def __getitem__(self, name):
""" check contents dictionary to allow dict like access to service layers"""
if name in list(self.__getattribute__("contents").keys()):
return self.__getattribute__("contents")[name]
else:
raise KeyError("No content named %s" % name)

def __init__(
self,
url,
version,
xml,
xml=None,
parse_remote_metadata=False,
timeout=30,
headers=None,
username=None,
password=None,
auth=None,
):
""" overridden __new__ method
"""Initialize.

@type url: string
@param url: url of WFS capabilities document
Expand All @@ -80,40 +87,6 @@ def __new__(
@param auth: instance of owslib.util.Authentication
@return: initialized WebFeatureService_1_1_0 object
"""
obj = object.__new__(self)
obj.__init__(
url,
version,
xml,
parse_remote_metadata,
timeout,
headers=headers,
username=username,
password=password,
auth=auth,
)
return obj

def __getitem__(self, name):
""" check contents dictionary to allow dict like access to service layers"""
if name in list(self.__getattribute__("contents").keys()):
return self.__getattribute__("contents")[name]
else:
raise KeyError("No content named %s" % name)

def __init__(
self,
url,
version,
xml=None,
parse_remote_metadata=False,
timeout=30,
headers=None,
username=None,
password=None,
auth=None,
):
"""Initialize."""
if auth:
if username:
auth.username = username
Expand Down
47 changes: 10 additions & 37 deletions owslib/feature/wfs200.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,26 @@ class WebFeatureService_2_0_0(WebFeatureService_):
Implements IWebFeatureService.
"""

def __new__(
def __getitem__(self, name):
""" check contents dictionary to allow dict like access to service layers"""
if name in list(self.__getattribute__("contents").keys()):
return self.__getattribute__("contents")[name]
else:
raise KeyError("No content named %s" % name)

def __init__(
self,
url,
version,
xml,
xml=None,
parse_remote_metadata=False,
timeout=30,
headers=None,
username=None,
password=None,
auth=None,
):
""" overridden __new__ method
"""Initialize.

@type url: string
@param url: url of WFS capabilities document
Expand All @@ -73,40 +80,6 @@ def __new__(
@param auth: instance of owslib.util.Authentication
@return: initialized WebFeatureService_2_0_0 object
"""
obj = object.__new__(self)
obj.__init__(
url,
version,
xml,
parse_remote_metadata,
timeout,
headers=headers,
username=username,
password=password,
auth=auth,
)
return obj

def __getitem__(self, name):
""" check contents dictionary to allow dict like access to service layers"""
if name in list(self.__getattribute__("contents").keys()):
return self.__getattribute__("contents")[name]
else:
raise KeyError("No content named %s" % name)

def __init__(
self,
url,
version,
xml=None,
parse_remote_metadata=False,
timeout=30,
headers=None,
username=None,
password=None,
auth=None,
):
"""Initialize."""
if auth:
if username:
auth.username = username
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ogcapi_records_pycsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_ogcapi_records_pycsw():
assert paths['/collections/{collectionId}'] is not None

conformance = w.conformance()
assert len(conformance['conformsTo']) == 18
assert len(conformance['conformsTo']) == 14

collections = w.collections()
assert len(collections) > 0
Expand All @@ -40,7 +40,7 @@ def test_ogcapi_records_pycsw():
assert isinstance(w.response, dict)

pycsw_cite_demo_queryables = w.collection_queryables('metadata:main')
assert len(pycsw_cite_demo_queryables['properties'].keys()) == 12
assert len(pycsw_cite_demo_queryables['properties'].keys()) == 13

# Minimum of limit param is 1
with pytest.raises(RuntimeError):
Expand Down
Loading