[Python-checkins] cpython (merge 3.2 -> default): Merged fix for #10860 from 3.2
lukasz.langa
python-checkins at python.org
Wed Oct 19 02:07:15 CEST 2011
http://hg.python.org/cpython/rev/18dc3811f2b8
changeset: 72982:18dc3811f2b8
parent: 72980:cade7c20c728
parent: 72981:6ac59218c049
user: Łukasz Langa <lukasz at langa.pl>
date: Wed Oct 19 02:04:46 2011 +0200
summary:
Merged fix for #10860 from 3.2
files:
Lib/http/client.py | 5 ++++-
Lib/test/test_httplib.py | 24 ++++++++++++++++++++++--
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/Lib/http/client.py b/Lib/http/client.py
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -678,7 +678,10 @@
try:
port = int(host[i+1:])
except ValueError:
- raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
+ if host[i+1:] == "": # http://foo.com:/ == http://foo.com/
+ port = self.default_port
+ else:
+ raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
host = host[:i]
else:
port = self.default_port
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -161,14 +161,16 @@
def test_host_port(self):
# Check invalid host_port
- for hp in ("www.python.org:abc", "www.python.org:"):
+ for hp in ("www.python.org:abc", "user:password at www.python.org"):
self.assertRaises(client.InvalidURL, client.HTTPConnection, hp)
for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000",
"fe80::207:e9ff:fe9b", 8000),
("www.python.org:80", "www.python.org", 80),
+ ("www.python.org:", "www.python.org", 80),
("www.python.org", "www.python.org", 80),
- ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80)):
+ ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80),
+ ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 80)):
c = client.HTTPConnection(hp)
self.assertEqual(h, c.host)
self.assertEqual(p, c.port)
@@ -539,6 +541,24 @@
self.assertEqual(resp.status, 404)
del server
+ def test_host_port(self):
+ # Check invalid host_port
+
+ for hp in ("www.python.org:abc", "user:password at www.python.org"):
+ self.assertRaises(client.InvalidURL, client.HTTPSConnection, hp)
+
+ for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000",
+ "fe80::207:e9ff:fe9b", 8000),
+ ("www.python.org:443", "www.python.org", 443),
+ ("www.python.org:", "www.python.org", 443),
+ ("www.python.org", "www.python.org", 443),
+ ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443),
+ ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b",
+ 443)):
+ c = client.HTTPSConnection(hp)
+ self.assertEqual(h, c.host)
+ self.assertEqual(p, c.port)
+
class RequestBodyTest(TestCase):
"""Test cases where a request includes a message body."""
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list