From afe54c46e576aeea3d6ba79d326cb8a4f235d24c Mon Sep 17 00:00:00 2001 From: Erwan Loisant Date: Tue, 18 Nov 2014 23:42:12 +0100 Subject: [PATCH] Fix Python 3 compatibility --- prismic/api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/prismic/api.py b/prismic/api.py index 38f34c2..316f0b6 100644 --- a/prismic/api.py +++ b/prismic/api.py @@ -8,6 +8,7 @@ """ +import sys import platform import pkg_resources from copy import copy, deepcopy @@ -23,6 +24,7 @@ import urllib2 as urlrequest import urllib as urlparse import urllib2 as urlerror + import json import re @@ -371,7 +373,14 @@ def __init__(self, data): self.slugs = ["-"] if data.get("slugs") is not None: - self.slugs = [urlparse.unquote(slug.encode('ASCII')).decode('utf8') for slug in data.get("slugs")] + self.slugs = [Document.__unquote(slug) for slug in data.get("slugs")] + + @staticmethod + def __unquote(s): + if sys.version_info >= (3, 0): + return urlparse.unquote(s) + else: + return urlparse.unquote(s.encode('utf8')).decode('utf8') def as_link(self): return Fragment.DocumentLink({