[PATCH] Fix Issue 2111, test-schemes unit test failure
Michael Glassford
glassfordmjg at gmail.com
Thu Apr 8 06:29:09 CDT 2010
# HG changeset patch
# User Michael Glassford <glassfordmjg at gmail.com>
# Date 1270726094 14400
# Node ID 443754cce2f168dad8fdc232a1b6bfe90c3380e2
# 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 443754cce2f1 mercurial/url.py
--- a/mercurial/url.py Mon Apr 05 17:48:48 2010 -0500
+++ b/mercurial/url.py Thu Apr 08 07:28:14 2010 -0400
@@ -11,17 +11,28 @@
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 not result.startswith(scheme + '://') and url.startswith(scheme + '://'):
+ result = result.replace(scheme + ':', 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