mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 18:06:29 +03:00
Add compat helpers for urllib
This commit is contained in:
parent
ac88c72c9a
commit
da1f200362
|
@ -33,11 +33,23 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from thinc.neural.optimizers import Adam as Optimizer
|
from thinc.neural.optimizers import Adam as Optimizer
|
||||||
|
|
||||||
|
try:
|
||||||
|
import urllib
|
||||||
|
except ImportError:
|
||||||
|
import urllib2 as urllib
|
||||||
|
|
||||||
|
try:
|
||||||
|
from urllib.error import HTTPError as url_error
|
||||||
|
except ImportError:
|
||||||
|
from urllib2 import HTTPError as url_error
|
||||||
|
|
||||||
pickle = pickle
|
pickle = pickle
|
||||||
copy_reg = copy_reg
|
copy_reg = copy_reg
|
||||||
CudaStream = CudaStream
|
CudaStream = CudaStream
|
||||||
cupy = cupy
|
cupy = cupy
|
||||||
copy_array = copy_array
|
copy_array = copy_array
|
||||||
|
urllib = urllib
|
||||||
|
url_error = url_error
|
||||||
izip = getattr(itertools, 'izip', zip)
|
izip = getattr(itertools, 'izip', zip)
|
||||||
|
|
||||||
is_windows = sys.platform.startswith('win')
|
is_windows = sys.platform.startswith('win')
|
||||||
|
@ -56,6 +68,7 @@ if is_python2:
|
||||||
input_ = raw_input # noqa: F821
|
input_ = raw_input # noqa: F821
|
||||||
json_dumps = lambda data: ujson.dumps(data, indent=2, escape_forward_slashes=False).decode('utf8')
|
json_dumps = lambda data: ujson.dumps(data, indent=2, escape_forward_slashes=False).decode('utf8')
|
||||||
path2str = lambda path: str(path).decode('utf8')
|
path2str = lambda path: str(path).decode('utf8')
|
||||||
|
url_open = lambda url: urllib.urlopen(url)
|
||||||
|
|
||||||
elif is_python3:
|
elif is_python3:
|
||||||
bytes_ = bytes
|
bytes_ = bytes
|
||||||
|
@ -64,6 +77,7 @@ elif is_python3:
|
||||||
input_ = input
|
input_ = input
|
||||||
json_dumps = lambda data: ujson.dumps(data, indent=2, escape_forward_slashes=False)
|
json_dumps = lambda data: ujson.dumps(data, indent=2, escape_forward_slashes=False)
|
||||||
path2str = lambda path: str(path)
|
path2str = lambda path: str(path)
|
||||||
|
url_open = lambda url: urllib.request.urlopen(url)
|
||||||
|
|
||||||
|
|
||||||
def b_to_str(b_str):
|
def b_to_str(b_str):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user