upip: url_open: Reworking error handling to guaranteedly close socket.

pull/68/merge
Paul Sokolovsky 2017-05-05 03:25:07 +03:00
rodzic 024d6bc2b1
commit 91d9c168b8
1 zmienionych plików z 28 dodań i 26 usunięć

Wyświetl plik

@ -117,6 +117,7 @@ def url_open(url):
addr = ai[0][4]
s = usocket.socket(ai[0][0])
try:
#print("Connect address:", addr)
s.connect(addr)
@ -131,18 +132,18 @@ def url_open(url):
l = s.readline()
protover, status, msg = l.split(None, 2)
if status != b"200":
s.close()
exc = ValueError(status)
if status == b"404" or status == b"301":
fatal("Package not found", exc)
fatal("Unexpected error querying for package", exc)
raise NotFoundError("Package not found")
raise ValueError(status)
while 1:
l = s.readline()
if not l:
s.close()
fatal("Unexpected EOF in HTTP headers", ValueError())
raise ValueError("Unexpected EOF in HTTP headers")
if l == b'\r\n':
break
except Exception as e:
s.close()
raise e
return s
@ -215,9 +216,10 @@ def install(to_install, install_path=None):
if deps:
deps = deps.decode("utf-8").split("\n")
to_install.extend(deps)
except NotFoundError:
print("Error: cannot find '%s' package (or server error), packages may be partially installed" \
% pkg_spec, file=sys.stderr)
except Exception as e:
print("Error installing '{}': {}, packages may be partially installed".format(
pkg_spec, e),
file=sys.stderr)
def get_install_path():
global install_path