1
# Bazaar -- distributed version control
3
# Copyright (C) 2006 Canonical Ltd
1
# Copyright (C) 2006-2010 Canonical Ltd
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
77
75
This assumes that both paths are already fully specified file:// URLs.
79
77
if len(base) < MIN_ABS_FILEURL_LENGTH:
80
raise ValueError('Length of base must be equal or'
78
raise ValueError('Length of base (%r) must equal or'
81
79
' exceed the platform minimum url length (which is %d)' %
82
MIN_ABS_FILEURL_LENGTH)
80
(base, MIN_ABS_FILEURL_LENGTH))
83
81
base = local_path_from_url(base)
84
82
path = local_path_from_url(path)
85
83
return escape(osutils.relpath(base, path))
219
217
# jam 20060502 Sorted to 'l' because the final target is 'local_path_from_url'
220
218
def _posix_local_path_from_url(url):
221
219
"""Convert a url like file:///path/to/foo into /path/to/foo"""
222
if not url.startswith('file:///'):
223
raise errors.InvalidURL(url, 'local urls must start with file:///')
220
file_localhost_prefix = 'file://localhost/'
221
if url.startswith(file_localhost_prefix):
222
path = url[len(file_localhost_prefix) - 1:]
223
elif not url.startswith('file:///'):
224
raise errors.InvalidURL(
225
url, 'local urls must start with file:/// or file://localhost/')
227
path = url[len('file://'):]
224
228
# We only strip off 2 slashes
225
return unescape(url[len('file://'):])
229
return unescape(path)
228
232
def _posix_local_path_to_url(path):
687
691
if len(segments) == 0:
689
693
return osutils.pathjoin(*segments)
698
"""Extract the server address, the credentials and the path from the url.
700
user, password, host and path should be quoted if they contain reserved
703
:param url: an quoted url
705
:return: (scheme, user, password, host, port, path) tuple, all fields
708
if isinstance(url, unicode):
709
raise errors.InvalidURL('should be ascii:\n%r' % url)
710
url = url.encode('utf-8')
711
(scheme, netloc, path, params,
712
query, fragment) = urlparse.urlparse(url, allow_fragments=False)
713
user = password = host = port = None
715
user, host = netloc.rsplit('@', 1)
717
user, password = user.split(':', 1)
718
password = urllib.unquote(password)
719
user = urllib.unquote(user)
723
if ':' in host and not (host[0] == '[' and host[-1] == ']'): #there *is* port
724
host, port = host.rsplit(':',1)
728
raise errors.InvalidURL('invalid port number %s in url:\n%s' %
730
if host != "" and host[0] == '[' and host[-1] == ']': #IPv6
733
host = urllib.unquote(host)
734
path = urllib.unquote(path)
736
return (scheme, user, password, host, port, path)