##// END OF EJS Templates
url: nuke some newly-introduced underbars in identifiers
Matt Mackall -
r13827:f1823b9f default
parent child Browse files
Show More
@@ -71,7 +71,7 b' class ShortRepository(object):'
71 url = ''.join(self.templater.process(self.url, context)) + tail
71 url = ''.join(self.templater.process(self.url, context)) + tail
72 return hg._lookup(url).instance(ui, url, create)
72 return hg._lookup(url).instance(ui, url, create)
73
73
74 def has_drive_letter(orig, path):
74 def hasdriveletter(orig, path):
75 for scheme in schemes:
75 for scheme in schemes:
76 if path.startswith(scheme + ':'):
76 if path.startswith(scheme + ':'):
77 return False
77 return False
@@ -95,4 +95,4 b' def extsetup(ui):'
95 'letter %s:\\\n') % (scheme, scheme.upper()))
95 'letter %s:\\\n') % (scheme, scheme.upper()))
96 hg.schemes[scheme] = ShortRepository(url, scheme, t)
96 hg.schemes[scheme] = ShortRepository(url, scheme, t)
97
97
98 extensions.wrapfunction(urlmod, 'has_drive_letter', has_drive_letter)
98 extensions.wrapfunction(urlmod, 'hasdriveletter', hasdriveletter)
@@ -23,7 +23,7 b' class sshrepository(wireproto.wirereposi'
23 self._url = path
23 self._url = path
24 self.ui = ui
24 self.ui = ui
25
25
26 u = url.url(path, parse_query=False, parse_fragment=False)
26 u = url.url(path, parsequery=False, parsefragment=False)
27 if u.scheme != 'ssh' or not u.host or u.path is None:
27 if u.scheme != 'ssh' or not u.host or u.path is None:
28 self._abort(error.RepoError(_("couldn't parse location %s") % path))
28 self._abort(error.RepoError(_("couldn't parse location %s") % path))
29
29
@@ -111,7 +111,7 b' class ui(object):'
111 % (n, p, self.configsource('paths', n)))
111 % (n, p, self.configsource('paths', n)))
112 p = p.replace('%%', '%')
112 p = p.replace('%%', '%')
113 p = util.expandpath(p)
113 p = util.expandpath(p)
114 if not url.has_scheme(p) and not os.path.isabs(p):
114 if not url.hasscheme(p) and not os.path.isabs(p):
115 p = os.path.normpath(os.path.join(root, p))
115 p = os.path.normpath(os.path.join(root, p))
116 c.set("paths", n, p)
116 c.set("paths", n, p)
117
117
@@ -325,7 +325,7 b' class ui(object):'
325
325
326 def expandpath(self, loc, default=None):
326 def expandpath(self, loc, default=None):
327 """Return repository location relative to cwd or from [paths]"""
327 """Return repository location relative to cwd or from [paths]"""
328 if url.has_scheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
328 if url.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
329 return loc
329 return loc
330
330
331 path = self.config('paths', loc)
331 path = self.config('paths', loc)
@@ -23,8 +23,8 b' class url(object):'
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.
@@ -58,14 +58,14 b' class url(object):'
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
@@ -74,7 +74,7 b' class url(object):'
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
@@ -100,7 +100,7 b' class url(object):'
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
@@ -108,7 +108,7 b' class url(object):'
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
@@ -239,26 +239,26 b' class url(object):'
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'''
@@ -71,11 +71,11 b' def test_url():'
71 <url scheme: 'http', host: 'host', path: 'a', fragment: 'b?c'>
71 <url scheme: 'http', host: 'host', path: 'a', fragment: 'b?c'>
72 >>> url('http://host/?a#b')
72 >>> url('http://host/?a#b')
73 <url scheme: 'http', host: 'host', path: '', query: 'a', fragment: 'b'>
73 <url scheme: 'http', host: 'host', path: '', query: 'a', fragment: 'b'>
74 >>> url('http://host/?a#b', parse_query=False)
74 >>> url('http://host/?a#b', parsequery=False)
75 <url scheme: 'http', host: 'host', path: '?a', fragment: 'b'>
75 <url scheme: 'http', host: 'host', path: '?a', fragment: 'b'>
76 >>> url('http://host/?a#b', parse_fragment=False)
76 >>> url('http://host/?a#b', parsefragment=False)
77 <url scheme: 'http', host: 'host', path: '', query: 'a#b'>
77 <url scheme: 'http', host: 'host', path: '', query: 'a#b'>
78 >>> url('http://host/?a#b', parse_query=False, parse_fragment=False)
78 >>> url('http://host/?a#b', parsequery=False, parsefragment=False)
79 <url scheme: 'http', host: 'host', path: '?a#b'>
79 <url scheme: 'http', host: 'host', path: '?a#b'>
80
80
81 IPv6 addresses:
81 IPv6 addresses:
General Comments 0
You need to be logged in to leave comments. Login now