Skip to content

Commit

Permalink
Fixing Python3-related issue (urllib) for SlicerProstate/SliceTracker…
Browse files Browse the repository at this point in the history
  • Loading branch information
tokjun committed Oct 9, 2020
1 parent 74cbfbf commit 808dc3c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions SlicerDevelopmentToolboxUtils/helpers.py
Expand Up @@ -2,7 +2,7 @@
import logging
import os
import sys
import urllib
import urllib.request
from urllib.request import FancyURLopener

import vtk
Expand Down Expand Up @@ -113,16 +113,16 @@ def retrieve(self, url, filename=None, reporthook=None, data=None):
urllib.URLopener
"""
self._canceled=False
url = urllib.unwrap(urllib.toBytes(url))
url = urllib.request.unwrap(urllib.request.to_bytes(url))
if self.tempcache and url in self.tempcache:
return self.tempcache[url]
type, url1 = urllib.splittype(url)
type, url1 = urllib.request.splittype(url)
if filename is None and (not type or type == 'file'):
try:
fp = self.open_local_file(url1)
hdrs = fp.info()
fp.close()
return urllib.url2pathname(urllib.splithost(url1)[1]), hdrs
return urllib.request.url2pathname(urllib.request.splithost(url1)[1]), hdrs
except IOError:
pass
fp = self.open(url, data)
Expand All @@ -132,10 +132,10 @@ def retrieve(self, url, filename=None, reporthook=None, data=None):
tfp = open(filename, 'wb')
else:
import tempfile
garbage, path = urllib.splittype(url)
garbage, path = urllib.splithost(path or "")
path, garbage = urllib.splitquery(path or "")
path, garbage = urllib.splitattr(path or "")
garbage, path = urllib.request.splittype(url)
garbage, path = urllib.request.splithost(path or "")
path, garbage = urllib.request.splitquery(path or "")
path, garbage = urllib.request.splitattr(path or "")
suffix = os.path.splitext(path)[1]
(fd, filename) = tempfile.mkstemp(suffix)
self.__tempfiles.append(filename)
Expand All @@ -154,7 +154,7 @@ def retrieve(self, url, filename=None, reporthook=None, data=None):
reporthook(blocknum, bs, size)
while not self._canceled:
block = fp.read(bs)
if block == "":
if not block:
break
read += len(block)
tfp.write(block)
Expand All @@ -168,7 +168,7 @@ def retrieve(self, url, filename=None, reporthook=None, data=None):

# raise exception if actual size does not match content-length header
if size >= 0 and read < size:
raise urllib.ContentTooShortError("retrieval incomplete: got only %i out "
raise urllib.request.ContentTooShortError("retrieval incomplete: got only %i out "
"of %i bytes" % (read, size), result)

if self._canceled and os.path.exists(filename):
Expand Down

0 comments on commit 808dc3c

Please sign in to comment.