40
40
hooks = LocationHooks()
43
def rcp_location_to_url(location, scheme='ssh'):
42
def parse_rcp_location(location):
44
43
"""Convert a rcp-style location to a URL.
46
45
:param location: Location to convert, e.g. "foo:bar"
47
:param schenme: URL scheme to return, defaults to "ssh"
46
:param scheme: URL scheme to return, defaults to "ssh"
48
47
:return: A URL, e.g. "ssh://foo/bar"
49
48
:raises ValueError: if this is not a RCP-style URL
53
52
raise ValueError("Not a RCP URL")
54
53
if m.group('path').startswith('//'):
55
54
raise ValueError("Not a RCP URL: already looks like a URL")
56
quoted_user = urlutils.quote(m.group('user')[:-1]) if m.group('user') else None
55
return (m.group('host'),
56
m.group('user')[:-1] if m.group('user') else None,
60
def rcp_location_to_url(location, scheme='ssh'):
61
"""Convert a rcp-style location to a URL.
63
:param location: Location to convert, e.g. "foo:bar"
64
:param scheme: URL scheme to return, defaults to "ssh"
65
:return: A URL, e.g. "ssh://foo/bar"
66
:raises ValueError: if this is not a RCP-style URL
68
(host, user, path) = parse_rcp_location(location)
69
quoted_user = urlutils.quote(user) if user else None
57
70
url = urlutils.URL(
58
71
scheme=scheme, quoted_user=quoted_user,
59
72
port=None, quoted_password=None,
60
quoted_host=urlutils.quote(m.group('host')),
61
quoted_path=urlutils.quote(m.group('path')))
73
quoted_host=urlutils.quote(host),
74
quoted_path=urlutils.quote(path))
65
def pserver_to_url(location):
66
"""Convert a CVS pserver location string to a URL.
68
:param location: pserver URL
69
:return: A cvs+pserver URL
78
def parse_cvs_location(location):
71
79
parts = location.split(':')
72
if parts[0] or parts[1] != 'pserver':
80
if parts[0] or parts[1] not in ('pserver', 'ssh'):
73
81
raise ValueError('not a valid pserver location string')
75
83
(username, hostname) = parts[2].split('@', 1)
77
85
hostname = parts[2]
89
return (scheme, hostname, username, path)
92
def cvs_to_url(location):
93
"""Convert a CVS pserver location string to a URL.
95
:param location: pserver URL
96
:return: A cvs+pserver URL
98
(scheme, host, user, path) = parse_cvs_location(location)
79
99
return str(urlutils.URL(
81
quoted_user=urlutils.quote(username) if username else None,
82
quoted_host=urlutils.quote(hostname),
100
scheme='cvs+' + scheme,
101
quoted_user=urlutils.quote(user) if user else None,
102
quoted_host=urlutils.quote(host),
83
103
quoted_password=None,
85
quoted_path=urlutils.quote(parts[3])))
105
quoted_path=urlutils.quote(path)))
88
108
def location_to_url(location, purpose=None):