From 43234d598d1d72faf0bd266cf2422f0c948e6384 Mon Sep 17 00:00:00 2001 From: Alexander Shorin Date: Wed, 12 Sep 2012 08:41:10 +0400 Subject: Fix compatibility with Python 3.x. --- jsonpointer.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'jsonpointer.py') diff --git a/jsonpointer.py b/jsonpointer.py index 06b9869..58cbdbb 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -40,8 +40,14 @@ __website__ = 'https://github.com/stefankoegl/python-json-pointer' __license__ = 'Modified BSD License' -import urllib -from itertools import tee, izip +try: + from urllib import unquote + from itertools import izip +except ImportError: # Python 3 + from urllib.parse import unquote + izip = zip + +from itertools import tee class JsonPointerException(Exception): @@ -121,7 +127,7 @@ class JsonPointer(object): if parts.pop(0) != '': raise JsonPointerException('location must starts with /') - parts = map(urllib.unquote, parts) + parts = map(unquote, parts) parts = [part.replace('~1', '/') for part in parts] parts = [part.replace('~0', '~') for part in parts] self.parts = parts -- cgit v1.2.1