From 54060ba0df95eb7209dbb94dcf885bb7a85c5007 Mon Sep 17 00:00:00 2001 From: Davide Brunato Date: Wed, 16 Oct 2019 21:14:15 +0200 Subject: [PATCH] Modify resources.fetch_schema_locations() - Now can returns location for another namespace if hints for resource namespace are missing --- xmlschema/resources.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xmlschema/resources.py b/xmlschema/resources.py index 1cf37c1..35478d4 100644 --- a/xmlschema/resources.py +++ b/xmlschema/resources.py @@ -169,12 +169,17 @@ def fetch_schema_locations(source, locations=None, **resource_options): base_url = resource.base_url namespace = resource.namespace locations = resource.get_locations(locations) - for ns, url in filter(lambda x: x[0] == namespace, locations): + if not locations: + msg = "the XML data resource {!r} does not contain any schema location hint." + raise XMLSchemaValueError(msg.format(source)) + + for ns, url in sorted(locations, key=lambda x: x[0] != namespace): try: return fetch_resource(url, base_url, timeout), locations except XMLSchemaURLError: pass - raise XMLSchemaValueError("not found a schema for XML data resource %r (namespace=%r)." % (source, namespace)) + + raise XMLSchemaValueError("not found a schema for XML data resource {!r}.".format(source)) def fetch_schema(source, locations=None, **resource_options):