Mercurial > hg
comparison mercurial/url.py @ 13827:f1823b9f073b
url: nuke some newly-introduced underbars in identifiers
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 31 Mar 2011 10:43:53 -0500 |
parents | e574207e3bcd |
children | b2798c1defff |
comparison
equal
deleted
inserted
replaced
13826:e574207e3bcd | 13827:f1823b9f073b |
---|---|
21 <scheme>://<user>:<passwd>@<host>:<port>/<path>?<query>#<fragment> | 21 <scheme>://<user>:<passwd>@<host>:<port>/<path>?<query>#<fragment> |
22 | 22 |
23 Missing components are set to None. The only exception is | 23 Missing components are set to None. The only exception is |
24 fragment, which is set to '' if present but empty. | 24 fragment, which is set to '' if present but empty. |
25 | 25 |
26 If parse_fragment is False, fragment is included in query. If | 26 If parsefragment is False, fragment is included in query. If |
27 parse_query is False, query is included in path. If both are | 27 parsequery is False, query is included in path. If both are |
28 False, both fragment and query are included in path. | 28 False, both fragment and query are included in path. |
29 | 29 |
30 See http://www.ietf.org/rfc/rfc2396.txt for more information. | 30 See http://www.ietf.org/rfc/rfc2396.txt for more information. |
31 | 31 |
32 Note that for backward compatibility reasons, bundle URLs do not | 32 Note that for backward compatibility reasons, bundle URLs do not |
56 | 56 |
57 Query strings and fragments: | 57 Query strings and fragments: |
58 | 58 |
59 >>> url('http://host/a?b#c') | 59 >>> url('http://host/a?b#c') |
60 <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'> | 60 <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'> |
61 >>> url('http://host/a?b#c', parse_query=False, parse_fragment=False) | 61 >>> url('http://host/a?b#c', parsequery=False, parsefragment=False) |
62 <url scheme: 'http', host: 'host', path: 'a?b#c'> | 62 <url scheme: 'http', host: 'host', path: 'a?b#c'> |
63 """ | 63 """ |
64 | 64 |
65 _safechars = "!~*'()+" | 65 _safechars = "!~*'()+" |
66 _safepchars = "/!~*'()+" | 66 _safepchars = "/!~*'()+" |
67 | 67 |
68 def __init__(self, path, parse_query=True, parse_fragment=True): | 68 def __init__(self, path, parsequery=True, parsefragment=True): |
69 # We slowly chomp away at path until we have only the path left | 69 # We slowly chomp away at path until we have only the path left |
70 self.scheme = self.user = self.passwd = self.host = None | 70 self.scheme = self.user = self.passwd = self.host = None |
71 self.port = self.path = self.query = self.fragment = None | 71 self.port = self.path = self.query = self.fragment = None |
72 self._localpath = True | 72 self._localpath = True |
73 self._hostport = '' | 73 self._hostport = '' |
74 self._origpath = path | 74 self._origpath = path |
75 | 75 |
76 # special case for Windows drive letters | 76 # special case for Windows drive letters |
77 if has_drive_letter(path): | 77 if hasdriveletter(path): |
78 self.path = path | 78 self.path = path |
79 return | 79 return |
80 | 80 |
81 # For compatibility reasons, we can't handle bundle paths as | 81 # For compatibility reasons, we can't handle bundle paths as |
82 # normal URLS | 82 # normal URLS |
98 path = None | 98 path = None |
99 if self._localpath: | 99 if self._localpath: |
100 self.path = '' | 100 self.path = '' |
101 return | 101 return |
102 else: | 102 else: |
103 if parse_fragment and '#' in path: | 103 if parsefragment and '#' in path: |
104 path, self.fragment = path.split('#', 1) | 104 path, self.fragment = path.split('#', 1) |
105 if not path: | 105 if not path: |
106 path = None | 106 path = None |
107 if self._localpath: | 107 if self._localpath: |
108 self.path = path | 108 self.path = path |
109 return | 109 return |
110 | 110 |
111 if parse_query and '?' in path: | 111 if parsequery and '?' in path: |
112 path, self.query = path.split('?', 1) | 112 path, self.query = path.split('?', 1) |
113 if not path: | 113 if not path: |
114 path = None | 114 path = None |
115 if not self.query: | 115 if not self.query: |
116 self.query = None | 116 self.query = None |
237 def localpath(self): | 237 def localpath(self): |
238 if self.scheme == 'file' or self.scheme == 'bundle': | 238 if self.scheme == 'file' or self.scheme == 'bundle': |
239 path = self.path or '/' | 239 path = self.path or '/' |
240 # For Windows, we need to promote hosts containing drive | 240 # For Windows, we need to promote hosts containing drive |
241 # letters to paths with drive letters. | 241 # letters to paths with drive letters. |
242 if has_drive_letter(self._hostport): | 242 if hasdriveletter(self._hostport): |
243 path = self._hostport + '/' + self.path | 243 path = self._hostport + '/' + self.path |
244 elif self.host is not None and self.path: | 244 elif self.host is not None and self.path: |
245 path = '/' + path | 245 path = '/' + path |
246 # We also need to handle the case of file:///C:/, which | 246 # We also need to handle the case of file:///C:/, which |
247 # should return C:/, not /C:/. | 247 # should return C:/, not /C:/. |
248 elif has_drive_letter(path): | 248 elif hasdriveletter(path): |
249 # Strip leading slash from paths with drive names | 249 # Strip leading slash from paths with drive names |
250 return path[1:] | 250 return path[1:] |
251 return path | 251 return path |
252 return self._origpath | 252 return self._origpath |
253 | 253 |
254 def has_scheme(path): | 254 def hasscheme(path): |
255 return bool(url(path).scheme) | 255 return bool(url(path).scheme) |
256 | 256 |
257 def has_drive_letter(path): | 257 def hasdriveletter(path): |
258 return path[1:2] == ':' and path[0:1].isalpha() | 258 return path[1:2] == ':' and path[0:1].isalpha() |
259 | 259 |
260 def localpath(path): | 260 def localpath(path): |
261 return url(path, parse_query=False, parse_fragment=False).localpath() | 261 return url(path, parsequery=False, parsefragment=False).localpath() |
262 | 262 |
263 def hidepassword(u): | 263 def hidepassword(u): |
264 '''hide user credential in a url string''' | 264 '''hide user credential in a url string''' |
265 u = url(u) | 265 u = url(u) |
266 if u.passwd: | 266 if u.passwd: |