[PATCH stable] Fix Issue 2111, test-schemes unit test failure
Michael Glassford
glassfordmjg at gmail.com
Thu Apr 8 08:17:29 CDT 2010
# HG changeset patch
# User Michael Glassford <glassfordmjg at gmail.com>
# Date 1270731213 14400
# Node ID ab12040bcec69f9f6bdfab0670bcc22a445a897a
# Parent f97b98db6fd1de6c60c1b60254c9240337dadc01
Fix Issue 2111, test-schemes unit test failure.
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://'.
Fix url.hidepassword() and url.removeauth() to handle this case.
diff -r f97b98db6fd1 -r ab12040bcec6 mercurial/url.py
--- a/mercurial/url.py Mon Apr 05 17:48:48 2010 -0500
+++ b/mercurial/url.py Thu Apr 08 08:53:33 2010 -0400
@@ -11,17 +11,35 @@
from i18n import _
import keepalive, util
+def _urlunparse(scheme, netloc, path, params, query, fragment, url):
+ # 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://' and
+ # urlparse.urlunparse(urlparse.urlparse('x:///y')) to
+ # return 'x:/y' instead of 'x:///y',
+ # unless "x" appears in the list urlparse.uses_netloc.
+ # Since we know the original url, re-add the missing "//"
+ # if the original url had it.
+ 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.'''
More information about the Mercurial-devel
mailing list