[Python-checkins] r80101 - in python/trunk: Lib/test/test_urlparse.py Lib/urlparse.py Misc/NEWS
R. David Murray
rdmurray at bitdance.com
Sat Apr 17 18:39:24 CEST 2010
On Fri, 16 Apr 2010 04:46:46 +0200, senthil.kumaran <python-checkins at python.org> wrote:
> + for invalid_url in [
> + 'http://::12.34.56.78]/',
> + 'http://[::1/foo/',
> + 'http://[::ffff:12.34.56.78']:
> + self.assertRaises(ValueError, lambda : urlparse.urlparse(invalid_url).hostname)
> + self.assertRaises(ValueError, lambda : urlparse.urlparse(invalid_url))
> +
[...]
> @property
> def hostname(self):
> - netloc = self.netloc
> - if "@" in netloc:
> - netloc = netloc.rsplit("@", 1)[1]
> - if ":" in netloc:
> - netloc = netloc.split(":", 1)[0]
> - return netloc.lower() or None
> + netloc = self.netloc.split('@')[-1]
> + if '[' in netloc and ']' in netloc:
> + return netloc.split(']')[0][1:].lower()
> + elif '[' in netloc or ']' in netloc:
> + raise ValueError("Invalid IPv6 hostname")
> + elif ':' in netloc:
> + return netloc.split(':')[0].lower()
> + elif netloc == '':
> + return None
> + else:
> + return netloc.lower()
Senthil, what should happen to this URL:
'http://[::1/foo/bar]/bad'
Currently it produces:
ParseResult(scheme='http', netloc='[::1', path='/foo/bar]/bad', params='', query='', fragment='')
--
R. David Murray www.bitdance.com
More information about the Python-checkins
mailing list