Show More
@@ -11,17 +11,28 b' import urllib, urllib2, urlparse, httpli' | |||
|
11 | 11 | from i18n import _ |
|
12 | 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 | 25 | def hidepassword(url): |
|
15 | 26 | '''hide user credential in a url string''' |
|
16 | 27 | scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) |
|
17 | 28 | netloc = re.sub('([^:]*):([^@]*)@(.*)', r'\1:***@\3', netloc) |
|
18 |
return |
|
|
29 | return _urlunparse(scheme, netloc, path, params, query, fragment, url) | |
|
19 | 30 | |
|
20 | 31 | def removeauth(url): |
|
21 | 32 | '''remove all authentication information from a url string''' |
|
22 | 33 | scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) |
|
23 | 34 | netloc = netloc[netloc.find('@')+1:] |
|
24 |
return |
|
|
35 | return _urlunparse(scheme, netloc, path, params, query, fragment, url) | |
|
25 | 36 | |
|
26 | 37 | def netlocsplit(netloc): |
|
27 | 38 | '''split [user[:passwd]@]host[:port] into 4-tuple.''' |
General Comments 0
You need to be logged in to leave comments.
Login now