1
1
import sys
2
2
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
+
3
10
from xmlschema import XMLSchema as _XMLSchema
4
11
from xmlschema .exceptions import XMLSchemaException as XMLSchemaError
5
12
6
13
import saml2 .data .schemas as _data_schemas
7
14
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
13
15
14
16
def _create_xml_schema_validator (source , ** kwargs ):
15
17
kwargs = {
@@ -23,37 +25,34 @@ def _create_xml_schema_validator(source, **kwargs):
23
25
return _XMLSchema (source , ** kwargs )
24
26
25
27
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
+ )
40
42
41
43
_locations = {
42
44
"http://www.w3.org/XML/1998/namespace" : _path_schema_xml ,
43
45
"http://schemas.xmlsoap.org/soap/envelope/" : _path_schema_envelope ,
44
46
"http://www.w3.org/2001/04/xmlenc#" : _path_schema_xenc ,
45
47
"http://www.w3.org/2000/09/xmldsig#" : _path_schema_xmldsig_core ,
46
48
"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 ,
47
50
"urn:oasis:names:tc:SAML:2.0:protocol" : _path_schema_saml_protocol ,
48
51
}
49
52
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 )
57
56
58
57
node_to_schema = {
59
58
# AssertionType
0 commit comments