summaryrefslogtreecommitdiff
path: root/jsonschema/_utils.py
diff options
context:
space:
mode:
authorColin Dunklau <colin.dunklau@gmail.com>2013-05-12 15:44:24 -0500
committerColin Dunklau <colin.dunklau@gmail.com>2013-05-12 15:44:24 -0500
commitef819b6a42f317bce07e343f50b804f273688798 (patch)
treef14e54d47cb47a998246ee989132bfcb66735b3c /jsonschema/_utils.py
parentfeb3e38a1435d3e9ead6ad5160e72e7476f9f33d (diff)
downloadjsonschema-ef819b6a42f317bce07e343f50b804f273688798.tar.gz
URIDict to _utils, fixed naming, package test
Diffstat (limited to 'jsonschema/_utils.py')
-rw-r--r--jsonschema/_utils.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py
index d55c9a9..44d0852 100644
--- a/jsonschema/_utils.py
+++ b/jsonschema/_utils.py
@@ -1,7 +1,39 @@
import itertools
import re
-from .compat import basestring
+from .compat import basestring, urlparse, MutableMapping
+
+
+class URIDict(MutableMapping):
+ """
+ Dictionary which uses normalized URIs as keys.
+
+ """
+
+ def normalize(self, uri):
+ return urlparse.urlsplit(uri).geturl()
+
+ def __init__(self, *args, **kwargs):
+ self.store = dict()
+ self.store.update(*args, **kwargs)
+
+ def __getitem__(self, uri):
+ return self.store[self.normalize(uri)]
+
+ def __setitem__(self, uri, value):
+ self.store[self.normalize(uri)] = value
+
+ def __delitem__(self, uri):
+ del self.store[self.normalize(uri)]
+
+ def __iter__(self):
+ return iter(self.store)
+
+ def __len__(self):
+ return len(self.store)
+
+ def __repr__(self):
+ return repr(self.store)
def indent(string, times=1):
@@ -104,7 +136,7 @@ def flatten(suitable_for_isinstance):
return tuple(types)
-def mklist(thing):
+def list_wrap_str(thing):
"""
Wrap ``thing`` in a list if it's a single str.