Skip to content

Commit 8cd38e2

Browse files
committed
Fix issue with empty xsd:import statements on Python 2.7 (#930)
1 parent 7b3a839 commit 8cd38e2

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
3.3.1 (2019-03-10)
2+
------------------
3+
- Fix issue with empty xsd:import statements on Python 2.7 (#930)
4+
5+
16
3.3.0 (2019-03-08)
27
------------------
38
- Extend the force_https flag to also force loading xsd files from https when

src/zeep/loader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def normalize_location(settings, url, base_url):
8383
enabled.
8484
8585
"""
86+
# Python 2.7 doesn't accept None to urlparse() calls, but Python 3 does.
87+
# So as a guard convert None to '' here so that we can't introduce errors in
88+
# Python 2.7 like #930. Can be removed when we drop Python 2 support.
89+
if url is None:
90+
url = ''
91+
8692
if base_url:
8793
url = absolute_location(url, base_url)
8894

src/zeep/xsd/visitor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ def visit_import(self, node, parent):
166166
namespace = node.get('namespace')
167167
location = node.get('schemaLocation')
168168
if location:
169-
location = absolute_location(location, self.document._base_url)
169+
location = normalize_location(
170+
self.schema.settings, location, self.document._location
171+
)
170172

171173
if not namespace and not self.document._target_namespace:
172174
raise XMLParseError(
@@ -185,8 +187,6 @@ def visit_import(self, node, parent):
185187
if not namespace and not location:
186188
self.document._has_empty_import = True
187189

188-
location = normalize_location(self.schema.settings, location, self.document._location)
189-
190190
# Check if the schema is already imported before based on the
191191
# namespace. Schema's without namespace are registered as 'None'
192192
document = self.schema.documents.get_by_namespace_and_location(namespace, location)

tests/test_wsdl.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,3 +1222,44 @@ def test_import_cyclic():
12221222

12231223
document = wsdl.Document(
12241224
wsdl_content, transport, 'https://tests.python-zeep.org/content.wsdl')
1225+
1226+
1227+
def test_import_no_location():
1228+
node_a = etree.fromstring("""
1229+
<?xml version="1.0"?>
1230+
<xs:schema
1231+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
1232+
xmlns:tns="http://tests.python-zeep.org/a"
1233+
targetNamespace="http://tests.python-zeep.org/a"
1234+
xmlns:b="http://tests.python-zeep.org/b"
1235+
elementFormDefault="qualified">
1236+
1237+
</xs:schema>
1238+
""".strip())
1239+
1240+
wsdl_content = StringIO("""
1241+
<?xml version='1.0'?>
1242+
<definitions
1243+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
1244+
xmlns:tns="http://tests.python-zeep.org/root"
1245+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1246+
xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tests.python-zeep.org/root" name="root">
1247+
<types>
1248+
<xsd:schema
1249+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
1250+
xmlns:tns="http://tests.python-zeep.org/b"
1251+
targetNamespace="http://tests.python-zeep.org/b"
1252+
elementFormDefault="qualified">
1253+
1254+
<xs:import namespace="http://tests.python-zeep.org/a"/>
1255+
<xs:element name="foo" type="xs:string"/>
1256+
</xsd:schema>
1257+
</types>
1258+
</definitions>
1259+
""".strip())
1260+
1261+
transport = DummyTransport()
1262+
transport.bind('https://tests.python-zeep.org/a.xsd', node_a)
1263+
1264+
document = wsdl.Document(
1265+
wsdl_content, transport, 'https://tests.python-zeep.org/content.wsdl')

0 commit comments

Comments
 (0)