Skip to content

Add None guard for extract_xml_list #1000

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

Merged
merged 1 commit into from
May 29, 2025
Merged
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
5 changes: 4 additions & 1 deletion owslib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,12 @@ def extract_time(element):

def extract_xml_list(elements):
"""
Some people don't have seperate tags for their keywords and seperate them with
Some people don't have separate tags for their keywords and separate them with
a newline. This will extract out all of the keywords correctly.
"""
if elements is None:
return []

keywords = (re.split(r'[\n\r]+', f.text) for f in elements if f.text)
flattened = (item.strip() for sublist in keywords for item in sublist)
remove_blank = [_f for _f in flattened if _f]
Expand Down
103 changes: 103 additions & 0 deletions tests/resources/wfs_mapserver_demo_getcapabilities_100.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<WFS_Capabilities version="1.0.0" updateSequence="0" xmlns="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd">
<Service>
<Name>MapServer WFS</Name>
<Title>WFS Demo Server for MapServer</Title>
<Abstract>This demonstration server showcases MapServer (www.mapserver.org) and its OGC support</Abstract>
<OnlineResource>https://demo.mapserver.org/cgi-bin/wfs?</OnlineResource>
</Service>

<Capability>
<Request>
<GetCapabilities>
<DCPType>
<HTTP>
<Get onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
</HTTP>
</DCPType>
<DCPType>
<HTTP>
<Post onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
</HTTP>
</DCPType>
</GetCapabilities>
<DescribeFeatureType>
<SchemaDescriptionLanguage>
<XMLSCHEMA/>
</SchemaDescriptionLanguage>
<DCPType>
<HTTP>
<Get onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
</HTTP>
</DCPType>
<DCPType>
<HTTP>
<Post onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
</HTTP>
</DCPType>
</DescribeFeatureType>
<GetFeature>
<ResultFormat>
<GML2/>
<geojson/>
</ResultFormat>
<DCPType>
<HTTP>
<Get onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
</HTTP>
</DCPType>
<DCPType>
<HTTP>
<Post onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
</HTTP>
</DCPType>
</GetFeature>
</Request>
</Capability>

<FeatureTypeList>
<Operations>
<Query/>
</Operations>
<FeatureType>
<Name>continents</Name>
<Title>World continents</Title>
<SRS>EPSG:4326</SRS>
<LatLongBoundingBox minx="-180.000000" miny="-90.000000" maxx="180.000000" maxy="83.627419"/>
<MetadataURL type="TC211" format="text/xml">https://demo.mapserver.org/cgi-bin/wfs?request=GetMetadata&amp;layer=continents</MetadataURL>
</FeatureType>
<FeatureType>
<Name>cities</Name>
<Title>World cities</Title>
<SRS>EPSG:4326</SRS>
<LatLongBoundingBox minx="-178.166667" miny="-54.800000" maxx="179.383333" maxy="78.933333"/>
<MetadataURL type="TC211" format="text/xml">https://demo.mapserver.org/cgi-bin/wfs?request=GetMetadata&amp;layer=cities</MetadataURL>
</FeatureType>
</FeatureTypeList>

<ogc:Filter_Capabilities>
<ogc:Spatial_Capabilities>
<ogc:Spatial_Operators>
<ogc:Equals/>
<ogc:Disjoint/>
<ogc:Touches/>
<ogc:Within/>
<ogc:Overlaps/>
<ogc:Crosses/>
<ogc:Intersect/>
<ogc:Contains/>
<ogc:DWithin/>
<ogc:BBOX/>
</ogc:Spatial_Operators>
</ogc:Spatial_Capabilities>
<ogc:Scalar_Capabilities>
<ogc:Logical_Operators/>
<ogc:Comparison_Operators>
<ogc:Simple_Comparisons/>
<ogc:Like/>
<ogc:Between/>
</ogc:Comparison_Operators>
</ogc:Scalar_Capabilities>
</ogc:Filter_Capabilities>

</WFS_Capabilities>
39 changes: 38 additions & 1 deletion tests/test_wfs_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@
WFS_SERVICE_URL = 'https://www.dov.vlaanderen.be/geoserver/wfs?request=GetCapabilities'


@pytest.fixture
def mp_wfs_100(monkeypatch):
"""Monkeypatch the call to the remote GetCapabilities request of WFS
version 1.0.0.

Parameters
----------
monkeypatch : pytest.fixture
PyTest monkeypatch fixture.

"""
def read(*args, **kwargs):
with open('tests/resources/wfs_mapserver_demo_getcapabilities_100.xml', 'r') as f:
data = f.read()
if type(data) is not bytes:
data = data.encode('utf-8')
data = etree.fromstring(data)
return data

monkeypatch.setattr(
owslib.feature.common.WFSCapabilitiesReader, 'read', read)


@pytest.fixture
def mp_wfs_110(monkeypatch):
"""Monkeypatch the call to the remote GetCapabilities request of WFS
Expand Down Expand Up @@ -122,7 +145,21 @@ def test_schema_result(self, wfs_version):

class TestOffline(object):
"""Class grouping offline tests for the WFS get_schema method."""
def test_get_schema(self, mp_wfs_110, mp_remote_describefeaturetype):
def test_get_schema_100(self, mp_wfs_100):
"""Test the get_schema method for a standard schema.

Parameters
----------
mp_wfs_100 : pytest.fixture
Monkeypatch the call to the remote GetCapabilities request.
"""
wfs100 = WebFeatureService(WFS_SERVICE_URL, version='1.0.0')
assert wfs100.identification.title == 'WFS Demo Server for MapServer'
assert wfs100.identification.keywords == []
assert list(wfs100.contents) == ['continents', 'cities']


def test_get_schema(self, mp_wfs_100, mp_remote_describefeaturetype):
"""Test the get_schema method for a standard schema.

Parameters
Expand Down