##// END OF EJS Templates
url: use url.url in hidepassword() and removeauth()
Brodie Rao -
r13772:463aca32 default
parent child Browse files
Show More
@@ -12,17 +12,6 b' import __builtin__'
12 from i18n import _
12 from i18n import _
13 import keepalive, util
13 import keepalive, util
14
14
15 def _urlunparse(scheme, netloc, path, params, query, fragment, url):
16 '''Handle cases where urlunparse(urlparse(x://)) doesn't preserve the "//"'''
17 result = urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
18 if (scheme and
19 result.startswith(scheme + ':') and
20 not result.startswith(scheme + '://') and
21 url.startswith(scheme + '://')
22 ):
23 result = scheme + '://' + result[len(scheme + ':'):]
24 return result
25
26 class url(object):
15 class url(object):
27 """Reliable URL parser.
16 """Reliable URL parser.
28
17
@@ -215,17 +204,18 b' class url(object):'
215 def has_scheme(path):
204 def has_scheme(path):
216 return bool(url(path).scheme)
205 return bool(url(path).scheme)
217
206
218 def hidepassword(url):
207 def hidepassword(u):
219 '''hide user credential in a url string'''
208 '''hide user credential in a url string'''
220 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
209 u = url(u)
221 netloc = re.sub('([^:]*):([^@]*)@(.*)', r'\1:***@\3', netloc)
210 if u.passwd:
222 return _urlunparse(scheme, netloc, path, params, query, fragment, url)
211 u.passwd = '***'
212 return str(u)
223
213
224 def removeauth(url):
214 def removeauth(u):
225 '''remove all authentication information from a url string'''
215 '''remove all authentication information from a url string'''
226 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
216 u = url(u)
227 netloc = netloc[netloc.find('@')+1:]
217 u.user = u.passwd = None
228 return _urlunparse(scheme, netloc, path, params, query, fragment, url)
218 return str(u)
229
219
230 def netlocsplit(netloc):
220 def netlocsplit(netloc):
231 '''split [user[:passwd]@]host[:port] into 4-tuple.'''
221 '''split [user[:passwd]@]host[:port] into 4-tuple.'''
General Comments 0
You need to be logged in to leave comments. Login now