Skip to content

Commit

Permalink
Fix Python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan committed Nov 18, 2014
1 parent fc2dd98 commit afe54c4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion prismic/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import sys
import platform
import pkg_resources
from copy import copy, deepcopy
Expand All @@ -23,6 +24,7 @@
import urllib2 as urlrequest
import urllib as urlparse
import urllib2 as urlerror

import json
import re

Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit afe54c4

Please sign in to comment.