Skip to content

Commit cb754df

Browse files
committed
Make url2pathname args compatible with python3
1 parent da751f7 commit cb754df

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

schema_salad/ref_resolver.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import copy
1111
import pprint
1212
from StringIO import StringIO
13-
import pathlib2 as pathlib
13+
try:
14+
# python 3
15+
import pathlib
16+
except:
17+
# python 2
18+
import pathlib2 as pathlib
1419

1520
from . import validate
1621
from .aslist import aslist
@@ -110,7 +115,7 @@ def fetch_text(self, url):
110115
return resp.text
111116
elif scheme == 'file':
112117
try:
113-
with open(urllib.url2pathname(urlparse.urlparse(url).path)) as fp:
118+
with open(urllib.url2pathname(str(urlparse.urlparse(url).path))) as fp:
114119
read = fp.read()
115120
if hasattr(read, "decode"):
116121
return read.decode("utf-8")
@@ -139,7 +144,7 @@ def check_exists(self, url): # type: (unicode) -> bool
139144
return False
140145
return True
141146
elif scheme == 'file':
142-
return os.path.exists(urllib.url2pathname(urlparse.urlparse(url).path))
147+
return os.path.exists(urllib.url2pathname(str(urlparse.urlparse(url).path)))
143148
else:
144149
raise ValueError('Unsupported scheme in url: %s' % url)
145150

0 commit comments

Comments
 (0)