11import sys
22
3+ # importlib.resources was introduced in python 3.7
4+ # files API from importlib.resources introduced in python 3.9
5+ if sys .version_info [:2 ] >= (3 , 9 ):
6+ from importlib .resources import files as _resource_files
7+ else :
8+ from importlib_resources import files as _resource_files
9+
310from xmlschema import XMLSchema as _XMLSchema
411from xmlschema .exceptions import XMLSchemaException as XMLSchemaError
512
613import saml2 .data .schemas as _data_schemas
714
8- # importlib.resources was introduced in python 3.7
9- if sys .version_info [:2 ] >= (3 , 7 ):
10- from importlib .resources import path as _resource_path
11- else :
12- from importlib_resources import path as _resource_path
1315
1416def _create_xml_schema_validator (source , ** kwargs ):
1517 kwargs = {
@@ -23,37 +25,34 @@ def _create_xml_schema_validator(source, **kwargs):
2325 return _XMLSchema (source , ** kwargs )
2426
2527
26- with _resource_path (_data_schemas , "xml.xsd" ) as fp :
27- _path_schema_xml = str (fp )
28- with _resource_path ( _data_schemas , "envelope.xsd" ) as fp :
29- _path_schema_envelope = str (fp )
30- with _resource_path ( _data_schemas , "xenc- schema.xsd" ) as fp :
31- _path_schema_xenc = str (fp )
32- with _resource_path ( _data_schemas , "xmldsig-core- schema. xsd" ) as fp :
33- _path_schema_xmldsig_core = str ( fp )
34- with _resource_path ( _data_schemas , "saml-schema-assertion-2.0.xsd" ) as fp :
35- _path_schema_saml_assertion = str ( fp )
36- with _resource_path ( _data_schemas , "saml-schema-metadata-2.0.xsd" ) as fp :
37- _path_schema_saml_metadata = str (fp )
38- with _resource_path ( _data_schemas , "saml-schema-protocol-2.0.xsd" ) as fp :
39- _path_schema_saml_protocol = str ( fp )
28+ _schema_resources = _resource_files (_data_schemas )
29+ _path_schema_xml = str (_schema_resources . joinpath ( "xml.xsd" ) )
30+ _path_schema_envelope = str ( _schema_resources . joinpath ( "envelope.xsd" ))
31+ _path_schema_xenc = str (_schema_resources . joinpath ( "xenc-schema.xsd" ) )
32+ _path_schema_xmldsig_core = str ( _schema_resources . joinpath ( "xmldsig-core- schema.xsd" ))
33+ _path_schema_saml_assertion = str (
34+ _schema_resources . joinpath ( "saml- schema-assertion-2.0. xsd" )
35+ )
36+ _path_schema_saml_metadata = str (
37+ _schema_resources . joinpath ( "saml-schema-metadata-2.0.xsd" )
38+ )
39+ _path_schema_saml_protocol = str (
40+ _schema_resources . joinpath ( "saml-schema-protocol-2.0.xsd" )
41+ )
4042
4143_locations = {
4244 "http://www.w3.org/XML/1998/namespace" : _path_schema_xml ,
4345 "http://schemas.xmlsoap.org/soap/envelope/" : _path_schema_envelope ,
4446 "http://www.w3.org/2001/04/xmlenc#" : _path_schema_xenc ,
4547 "http://www.w3.org/2000/09/xmldsig#" : _path_schema_xmldsig_core ,
4648 "urn:oasis:names:tc:SAML:2.0:assertion" : _path_schema_saml_assertion ,
49+ "urn:oasis:names:tc:SAML:2.0:metadata" : _path_schema_saml_metadata ,
4750 "urn:oasis:names:tc:SAML:2.0:protocol" : _path_schema_saml_protocol ,
4851}
4952
50- with _resource_path (_data_schemas , "saml-schema-assertion-2.0.xsd" ) as fp :
51- schema_saml_assertion = _create_xml_schema_validator (str (fp ))
52- with _resource_path (_data_schemas , "saml-schema-metadata-2.0.xsd" ) as fp :
53- schema_saml_metadata = _create_xml_schema_validator (str (fp ))
54- with _resource_path (_data_schemas , "saml-schema-protocol-2.0.xsd" ) as fp :
55- schema_saml_protocol = _create_xml_schema_validator (str (fp ))
56-
53+ schema_saml_assertion = _create_xml_schema_validator (_path_schema_saml_assertion )
54+ schema_saml_metadata = _create_xml_schema_validator (_path_schema_saml_metadata )
55+ schema_saml_protocol = _create_xml_schema_validator (_path_schema_saml_protocol )
5756
5857node_to_schema = {
5958 # AssertionType
0 commit comments