factory: Fix urllib, urllib2, urlparse module
These three modules are medged into `urllib` module, and we should
import `urllib.request`, `urllib.error`, `urllib.parse` when needed.
BUG=chromium:999876
TEST=make test
Change-Id: Ib223a5dc648beb40d1e099c2ca55468ec909bfd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory/+/1991199
Tested-by: Yilin Yang (kerker) <kerker@chromium.org>
Commit-Queue: Yilin Yang (kerker) <kerker@chromium.org>
Reviewed-by: Yong Hong <yhong@chromium.org>
diff --git a/py/tools/ghost.py b/py/tools/ghost.py
index e10fc56..51ae891 100755
--- a/py/tools/ghost.py
+++ b/py/tools/ghost.py
@@ -31,13 +31,14 @@
import time
import traceback
import tty
-import urllib2
+import urllib.request
import uuid
import jsonrpclib
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
from six import PY2
+
_GHOST_RPC_PORT = int(os.getenv('GHOST_RPC_PORT', 4499))
_OVERLORD_PORT = int(os.getenv('OVERLORD_PORT', 4455))
@@ -301,8 +302,8 @@
# Download sha1sum for ghost.py for verification
try:
with contextlib.closing(
- urllib2.urlopen(url + '.sha1', timeout=_CONNECT_TIMEOUT,
- context=self._tls_settings.Context())) as f:
+ urllib.request.urlopen(url + '.sha1', timeout=_CONNECT_TIMEOUT,
+ context=self._tls_settings.Context())) as f:
if f.getcode() != 200:
raise RuntimeError('HTTP status %d' % f.getcode())
sha1sum = f.read().strip()
@@ -320,8 +321,8 @@
# Download upgrade version of ghost.py
try:
with contextlib.closing(
- urllib2.urlopen(url, timeout=_CONNECT_TIMEOUT,
- context=self._tls_settings.Context())) as f:
+ urllib.request.urlopen(url, timeout=_CONNECT_TIMEOUT,
+ context=self._tls_settings.Context())) as f:
if f.getcode() != 200:
raise RuntimeError('HTTP status %d' % f.getcode())
data = f.read()