Skip to content

Commit 916aaa1

Browse files
committed
py3: use six.moves.urllib instead of urllib
1 parent 9108c7b commit 916aaa1

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

schema_salad/ref_resolver.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
import six
1010
from six.moves import range
11-
import urllib
12-
1311
from six.moves.urllib import parse
12+
from six.moves import urllib
1413
from six import StringIO
1514

1615
import re
@@ -47,10 +46,10 @@ def file_uri(path, split_frag=False): # type: (str, bool) -> str
4746
return path
4847
if split_frag:
4948
pathsp = path.split("#", 2)
50-
frag = "#" + urllib.quote(str(pathsp[1])) if len(pathsp) == 2 else ""
51-
urlpath = urllib.pathname2url(str(pathsp[0]))
49+
frag = "#" + urllib.parse.quote(str(pathsp[1])) if len(pathsp) == 2 else ""
50+
urlpath = urllib.request.pathname2url(str(pathsp[0]))
5251
else:
53-
urlpath = urllib.pathname2url(path)
52+
urlpath = urllib.request.pathname2url(path)
5453
frag = ""
5554
if urlpath.startswith("//"):
5655
return "file:%s%s" % (urlpath, frag)
@@ -60,8 +59,8 @@ def file_uri(path, split_frag=False): # type: (str, bool) -> str
6059
def uri_file_path(url): # type: (str) -> str
6160
split = parse.urlsplit(url)
6261
if split.scheme == "file":
63-
return urllib.url2pathname(
64-
str(split.path)) + ("#" + urllib.unquote(str(split.fragment))
62+
return urllib.request.url2pathname(
63+
str(split.path)) + ("#" + urllib.parse.unquote(str(split.fragment))
6564
if bool(split.fragment) else "")
6665
else:
6766
raise ValueError("Not a file URI")
@@ -142,7 +141,7 @@ def fetch_text(self, url):
142141
return resp.text
143142
elif scheme == 'file':
144143
try:
145-
with open(urllib.url2pathname(str(path))) as fp:
144+
with open(urllib.request.url2pathname(str(path))) as fp:
146145
read = fp.read()
147146
if hasattr(read, "decode"):
148147
return read.decode("utf-8")
@@ -171,7 +170,7 @@ def check_exists(self, url): # type: (Text) -> bool
171170
return False
172171
return True
173172
elif scheme == 'file':
174-
return os.path.exists(urllib.url2pathname(str(path)))
173+
return os.path.exists(urllib.request.url2pathname(str(path)))
175174
else:
176175
raise ValueError('Unsupported scheme in url: %s' % url)
177176

0 commit comments

Comments
 (0)