urllib.urequest: Avoid allocating long semi-duplicate strings.

pull/76/merge
Paul Sokolovsky 2016-06-11 00:05:24 +03:00
rodzic 5cd55818fe
commit 52ac454ef7
1 zmienionych plików z 6 dodań i 4 usunięć

Wyświetl plik

@ -26,11 +26,13 @@ def urlopen(url, data=None, method="GET"):
s.connect(addr)
if proto == "https:":
s = ussl.wrap_socket(s)
if data:
req = b"%s /%s HTTP/1.0\r\nHost: %s\r\nContent-Length: %d\r\n\r\n" % (method, path, host, len(data))
else:
req = b"%s /%s HTTP/1.0\r\nHost: %s\r\n\r\n" % (method, path, host)
req = b"%s /%s HTTP/1.0\r\nHost: %s\r\n" % (method, path, host)
s.write(req)
if data:
req = b"Content-Length: %d\r\n" % len(data)
s.write(b"\r\n")
if data:
s.write(data)