##// END OF EJS Templates
schemes: fix // breakage with Python 2.6.5 (issue2111)...
Michael Glassford -
r11035:e4f911ce stable
parent child Browse files
Show More
@@ -11,17 +11,28 b' import urllib, urllib2, urlparse, httpli'
11 from i18n import _
11 from i18n import _
12 import keepalive, util
12 import keepalive, util
13
13
14 def _urlunparse(scheme, netloc, path, params, query, fragment, url):
15 '''Handle cases where urlunparse(urlparse(x://)) doesn't preserve the "//"'''
16 result = urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
17 if (scheme and
18 result.startswith(scheme + ':') and
19 not result.startswith(scheme + '://') and
20 url.startswith(scheme + '://')
21 ):
22 result = scheme + '://' + result[len(scheme + ':'):]
23 return result
24
14 def hidepassword(url):
25 def hidepassword(url):
15 '''hide user credential in a url string'''
26 '''hide user credential in a url string'''
16 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
27 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
17 netloc = re.sub('([^:]*):([^@]*)@(.*)', r'\1:***@\3', netloc)
28 netloc = re.sub('([^:]*):([^@]*)@(.*)', r'\1:***@\3', netloc)
18 return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
29 return _urlunparse(scheme, netloc, path, params, query, fragment, url)
19
30
20 def removeauth(url):
31 def removeauth(url):
21 '''remove all authentication information from a url string'''
32 '''remove all authentication information from a url string'''
22 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
33 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
23 netloc = netloc[netloc.find('@')+1:]
34 netloc = netloc[netloc.find('@')+1:]
24 return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
35 return _urlunparse(scheme, netloc, path, params, query, fragment, url)
25
36
26 def netlocsplit(netloc):
37 def netlocsplit(netloc):
27 '''split [user[:passwd]@]host[:port] into 4-tuple.'''
38 '''split [user[:passwd]@]host[:port] into 4-tuple.'''
General Comments 0
You need to be logged in to leave comments. Login now