Mercurial > hg
diff mercurial/url.py @ 11035:e4f911ce21de stable
schemes: fix // breakage with Python 2.6.5 (issue2111)
Recent Pythons (e.g. 2.6.5 and 3.1) introduce a change that causes
urlparse.urlunparse(urlparse.urlparse('x://')) to return 'x:' instead of 'x://'i and
urlparse.urlunparse(urlparse.urlparse('x:///y')) to return 'x:/y' instead of 'x:///y'.
Fix url.hidepassword() and url.removeauth() to handle these cases.
author | Michael Glassford <glassfordmjg@gmail.com> |
---|---|
date | Thu, 08 Apr 2010 11:00:46 -0400 |
parents | 1148a968a070 |
children | a1e575b48563 |
line wrap: on
line diff
--- a/mercurial/url.py Wed Apr 28 13:36:06 2010 -0500 +++ b/mercurial/url.py Thu Apr 08 11:00:46 2010 -0400 @@ -11,17 +11,28 @@ from i18n import _ import keepalive, util +def _urlunparse(scheme, netloc, path, params, query, fragment, url): + '''Handle cases where urlunparse(urlparse(x://)) doesn't preserve the "//"''' + result = urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) + if (scheme and + result.startswith(scheme + ':') and + not result.startswith(scheme + '://') and + url.startswith(scheme + '://') + ): + result = scheme + '://' + result[len(scheme + ':'):] + return result + def hidepassword(url): '''hide user credential in a url string''' scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) netloc = re.sub('([^:]*):([^@]*)@(.*)', r'\1:***@\3', netloc) - return urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) + return _urlunparse(scheme, netloc, path, params, query, fragment, url) def removeauth(url): '''remove all authentication information from a url string''' scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) netloc = netloc[netloc.find('@')+1:] - return urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) + return _urlunparse(scheme, netloc, path, params, query, fragment, url) def netlocsplit(netloc): '''split [user[:passwd]@]host[:port] into 4-tuple.'''