22
22
import socket
23
23
import sys
24
24
25
+ try :
26
+ from collections import MutableMapping
27
+ except ImportError :
28
+ from collections .abc import MutableMapping
29
+
25
30
try :
26
31
import requests
27
32
except ImportError :
@@ -67,19 +72,19 @@ class RefResolutionError(Exception): pass
67
72
class UnknownType (Exception ): pass
68
73
69
74
70
- class URIDict ( collections . MutableMapping ):
75
+ class _URIDict ( MutableMapping ):
71
76
"""
72
77
Dictionary which uses normalized URIs as keys.
73
78
74
79
"""
75
80
76
81
def normalize (self , uri ):
77
- return urlparse .urlsplit (uri ).geturl ()
82
+ if uri is not None :
83
+ return urlparse .urlsplit (uri ).geturl ()
78
84
79
85
def __init__ (self , * args , ** kwargs ):
80
86
self .store = dict ()
81
- for key , value in iteritems (dict (* args , ** kwargs )):
82
- self [key ] = value
87
+ self .store .update (* args , ** kwargs )
83
88
84
89
def __getitem__ (self , uri ):
85
90
return self .store [self .normalize (uri )]
@@ -100,7 +105,7 @@ def __repr__(self):
100
105
return repr (self .store )
101
106
102
107
103
- meta_schemas = URIDict ()
108
+ meta_schemas = _URIDict ()
104
109
105
110
106
111
def validates (version ):
@@ -954,7 +959,7 @@ def __init__(self, base_uri, referrer, store=(), cache_remote=True,
954
959
self .base_uri = base_uri
955
960
self .resolution_scope = base_uri
956
961
self .referrer = referrer
957
- self .store = URIDict (store , ** _meta_schemas ())
962
+ self .store = _URIDict (store , ** _meta_schemas ())
958
963
self .cache_remote = cache_remote
959
964
self .handlers = dict (handlers )
960
965
@@ -1270,7 +1275,6 @@ def _uniq(container):
1270
1275
1271
1276
def validate (instance , schema , cls = None , * args , ** kwargs ):
1272
1277
if cls is None :
1273
- cls = meta_schemas .get (schema .get ("$schema" ),
1274
- Draft4Validator )
1278
+ cls = meta_schemas .get (schema .get ("$schema" ), Draft4Validator )
1275
1279
cls .check_schema (schema )
1276
1280
cls (schema , * args , ** kwargs ).validate (instance )
0 commit comments