Skip to content

Commit 7c6aecb

Browse files
committed
Cleanups for URIDict
1 parent 31a6b98 commit 7c6aecb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

jsonschema.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
import socket
2323
import sys
2424

25+
try:
26+
from collections import MutableMapping
27+
except ImportError:
28+
from collections.abc import MutableMapping
29+
2530
try:
2631
import requests
2732
except ImportError:
@@ -67,19 +72,19 @@ class RefResolutionError(Exception): pass
6772
class UnknownType(Exception): pass
6873

6974

70-
class URIDict(collections.MutableMapping):
75+
class _URIDict(MutableMapping):
7176
"""
7277
Dictionary which uses normalized URIs as keys.
7378
7479
"""
7580

7681
def normalize(self, uri):
77-
return urlparse.urlsplit(uri).geturl()
82+
if uri is not None:
83+
return urlparse.urlsplit(uri).geturl()
7884

7985
def __init__(self, *args, **kwargs):
8086
self.store = dict()
81-
for key, value in iteritems(dict(*args, **kwargs)):
82-
self[key] = value
87+
self.store.update(*args, **kwargs)
8388

8489
def __getitem__(self, uri):
8590
return self.store[self.normalize(uri)]
@@ -100,7 +105,7 @@ def __repr__(self):
100105
return repr(self.store)
101106

102107

103-
meta_schemas = URIDict()
108+
meta_schemas = _URIDict()
104109

105110

106111
def validates(version):
@@ -954,7 +959,7 @@ def __init__(self, base_uri, referrer, store=(), cache_remote=True,
954959
self.base_uri = base_uri
955960
self.resolution_scope = base_uri
956961
self.referrer = referrer
957-
self.store = URIDict(store, **_meta_schemas())
962+
self.store = _URIDict(store, **_meta_schemas())
958963
self.cache_remote = cache_remote
959964
self.handlers = dict(handlers)
960965

@@ -1270,7 +1275,6 @@ def _uniq(container):
12701275

12711276
def validate(instance, schema, cls=None, *args, **kwargs):
12721277
if cls is None:
1273-
cls = meta_schemas.get(schema.get("$schema"),
1274-
Draft4Validator)
1278+
cls = meta_schemas.get(schema.get("$schema"), Draft4Validator)
12751279
cls.check_schema(schema)
12761280
cls(schema, *args, **kwargs).validate(instance)

0 commit comments

Comments
 (0)