comparison mercurial/url.py @ 13816:2540f8087e02

url: special case bundle URL parsing to preserve backwards compatibility This allows bundle://../foo to continue to refer to the relative path ../foo (bundle URLs do not take host names).
author Brodie Rao <brodie@bitheap.org>
date Wed, 30 Mar 2011 20:00:24 -0700
parents d066d8d652c8
children 7f18bab2c0b0
comparison
equal deleted inserted replaced
13815:d066d8d652c8 13816:2540f8087e02
27 parse_query is False, query is included in path. If both are 27 parse_query 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
33 take host names. That means 'bundle://../' has a path of '../'.
34
32 Examples: 35 Examples:
33 36
34 >>> url('http://www.ietf.org/rfc/rfc2396.txt') 37 >>> url('http://www.ietf.org/rfc/rfc2396.txt')
35 <url scheme: 'http', host: 'www.ietf.org', path: 'rfc/rfc2396.txt'> 38 <url scheme: 'http', host: 'www.ietf.org', path: 'rfc/rfc2396.txt'>
36 >>> url('ssh://[::1]:2200//home/joe/repo') 39 >>> url('ssh://[::1]:2200//home/joe/repo')
37 <url scheme: 'ssh', host: '[::1]', port: '2200', path: '/home/joe/repo'> 40 <url scheme: 'ssh', host: '[::1]', port: '2200', path: '/home/joe/repo'>
38 >>> url('file:///home/joe/repo') 41 >>> url('file:///home/joe/repo')
39 <url scheme: 'file', path: '/home/joe/repo'> 42 <url scheme: 'file', path: '/home/joe/repo'>
40 >>> url('bundle:foo') 43 >>> url('bundle:foo')
41 <url scheme: 'bundle', path: 'foo'> 44 <url scheme: 'bundle', path: 'foo'>
45 >>> url('bundle://../foo')
46 <url scheme: 'bundle', path: '../foo'>
42 >>> url('c:\\\\foo\\\\bar') 47 >>> url('c:\\\\foo\\\\bar')
43 <url path: 'c:\\\\foo\\\\bar'> 48 <url path: 'c:\\\\foo\\\\bar'>
44 49
45 Authentication credentials: 50 Authentication credentials:
46 51
66 self.port = self.path = self.query = self.fragment = None 71 self.port = self.path = self.query = self.fragment = None
67 self._localpath = True 72 self._localpath = True
68 73
69 # special case for Windows drive letters 74 # special case for Windows drive letters
70 if has_drive_letter(path): 75 if has_drive_letter(path):
76 self.path = path
77 return
78
79 # For compatibility reasons, we can't handle bundle paths as
80 # normal URLS
81 if path.startswith('bundle:'):
82 self.scheme = 'bundle'
83 path = path[7:]
84 if path.startswith('//'):
85 path = path[2:]
71 self.path = path 86 self.path = path
72 return 87 return
73 88
74 if not path.startswith('/') and ':' in path: 89 if not path.startswith('/') and ':' in path:
75 parts = path.split(':', 1) 90 parts = path.split(':', 1)
157 'http://localhost:80/' 172 'http://localhost:80/'
158 >>> str(url('http://localhost:80')) 173 >>> str(url('http://localhost:80'))
159 'http://localhost:80/' 174 'http://localhost:80/'
160 >>> str(url('bundle:foo')) 175 >>> str(url('bundle:foo'))
161 'bundle:foo' 176 'bundle:foo'
177 >>> str(url('bundle://../foo'))
178 'bundle:../foo'
162 >>> str(url('path')) 179 >>> str(url('path'))
163 'path' 180 'path'
164 """ 181 """
165 if self._localpath: 182 if self._localpath:
166 s = self.path 183 s = self.path
184 if self.scheme == 'bundle':
185 s = 'bundle:' + s
167 if self.fragment: 186 if self.fragment:
168 s += '#' + self.fragment 187 s += '#' + self.fragment
169 return s 188 return s
170 189
171 s = self.scheme + ':' 190 s = self.scheme + ':'