summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-04-22 12:10:13 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2010-04-22 12:10:13 (GMT)
commit398246169cfcfeaaab60fc047edbdbcf668ca24b (patch)
treeb3dfd4c918b84dd746693e8caebec23f43d0f4a9
parent19c06739c5a294538a9b233dd4de9301871d0b60 (diff)
downloadcpython-398246169cfcfeaaab60fc047edbdbcf668ca24b.zip
cpython-398246169cfcfeaaab60fc047edbdbcf668ca24b.tar.gz
cpython-398246169cfcfeaaab60fc047edbdbcf668ca24b.tar.bz2
Changed tests to only urlparse one, which was enough, addressed Ezio's comment
on Invalid url check statement and versionchanged string in docs.
-rw-r--r--Doc/library/urlparse.rst6
-rw-r--r--Lib/test/test_urlparse.py4
-rw-r--r--Lib/urlparse.py14
3 files changed, 13 insertions, 11 deletions
diff --git a/Doc/library/urlparse.rst b/Doc/library/urlparse.rst
index 31137cb..135f46c 100644
--- a/Doc/library/urlparse.rst
+++ b/Doc/library/urlparse.rst
@@ -101,6 +101,10 @@ The :mod:`urlparse` module defines the following functions:
.. versionchanged:: 2.5
Added attributes to return value.
+ .. versionchanged:: 2.7
+ Added IPv6 URL parsing capabilities.
+
+
.. function:: parse_qs(qs[, keep_blank_values[, strict_parsing]])
Parse a query string given as a string argument (data of type
@@ -254,7 +258,7 @@ The :mod:`urlparse` module defines the following functions:
:rfc:`3986` - Uniform Resource Identifiers
This is the current standard (STD66). Any changes to urlparse module
should conform to this. Certain deviations could be observed, which are
- mostly due backward compatiblity purposes and for certain to de-facto
+ mostly due backward compatiblity purposes and for certain de-facto
parsing requirements as commonly observed in major browsers.
:rfc:`2732` - Format for Literal IPv6 Addresses in URL's.
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index c25b6e0..efbdd1e 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -272,10 +272,10 @@ class UrlParseTestCase(unittest.TestCase):
for invalid_url in [
'http://::12.34.56.78]/',
'http://[::1/foo/',
+ 'ftp://[::1/foo/bad]/bad',
'http://[::1/foo/bad]/bad',
'http://[::ffff:12.34.56.78']:
- self.assertRaises(ValueError, lambda : urlparse.urlparse(invalid_url).hostname)
- self.assertRaises(ValueError, lambda : urlparse.urlparse(invalid_url))
+ self.assertRaises(ValueError, urlparse.urlparse, invalid_url)
def test_urldefrag(self):
for url, defrag, frag in [
diff --git a/Lib/urlparse.py b/Lib/urlparse.py
index 1a81518..f1e54d3 100644
--- a/Lib/urlparse.py
+++ b/Lib/urlparse.py
@@ -176,10 +176,9 @@ def urlsplit(url, scheme='', allow_fragments=True):
url = url[i+1:]
if url[:2] == '//':
netloc, url = _splitnetloc(url, 2)
- if '[' in netloc :
- if not ']' in netloc: raise ValueError("Invalid IPv6 URL")
- if ']' in netloc:
- if not '[' in netloc: raise ValueError("Invalid IPv6 URL")
+ if (('[' in netloc and ']' not in netloc) or
+ (']' in netloc and '[' not in netloc)):
+ raise ValueError("Invalid IPv6 URL")
if allow_fragments and '#' in url:
url, fragment = url.split('#', 1)
if '?' in url:
@@ -195,10 +194,9 @@ def urlsplit(url, scheme='', allow_fragments=True):
if url[:2] == '//':
netloc, url = _splitnetloc(url, 2)
- if '[' in netloc:
- if not ']' in netloc: raise ValueError("Invalid IPv6 URL")
- if ']' in netloc:
- if not '[' in netloc: raise ValueError("Invalid IPv6 URL")
+ if (('[' in netloc and ']' not in netloc) or
+ (']' in netloc and '[' not in netloc)):
+ raise ValueError("Invalid IPv6 URL")
if allow_fragments and scheme in uses_fragment and '#' in url:
url, fragment = url.split('#', 1)
if scheme in uses_query and '?' in url: