/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/location.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-21 03:58:42 UTC
  • mfrom: (7490.3.4 work)
  • mto: This revision was merged to the branch mainline in revision 7495.
  • Revision ID: jelmer@jelmer.uk-20200221035842-j97r6b74q8cgxb21
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
hooks = LocationHooks()
41
41
 
42
 
def parse_rcp_location(location):
 
42
 
 
43
def rcp_location_to_url(location, scheme='ssh'):
43
44
    """Convert a rcp-style location to a URL.
44
45
 
45
46
    :param location: Location to convert, e.g. "foo:bar"
46
 
    :param scheme: URL scheme to return, defaults to "ssh"
 
47
    :param schenme: URL scheme to return, defaults to "ssh"
47
48
    :return: A URL, e.g. "ssh://foo/bar"
48
49
    :raises ValueError: if this is not a RCP-style URL
49
50
    """
52
53
        raise ValueError("Not a RCP URL")
53
54
    if m.group('path').startswith('//'):
54
55
        raise ValueError("Not a RCP URL: already looks like a URL")
55
 
    return (m.group('host'),
56
 
            m.group('user')[:-1] if m.group('user') else None,
57
 
            m.group('path'))
58
 
 
59
 
 
60
 
def rcp_location_to_url(location, scheme='ssh'):
61
 
    """Convert a rcp-style location to a URL.
62
 
 
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
67
 
    """
68
 
    (host, user, path) = parse_rcp_location(location)
69
 
    quoted_user = urlutils.quote(user) if user else None
 
56
    quoted_user = urlutils.quote(m.group('user')[:-1]) if m.group('user') else None
70
57
    url = urlutils.URL(
71
58
        scheme=scheme, quoted_user=quoted_user,
72
59
        port=None, quoted_password=None,
73
 
        quoted_host=urlutils.quote(host),
74
 
        quoted_path=urlutils.quote(path))
 
60
        quoted_host=urlutils.quote(m.group('host')),
 
61
        quoted_path=urlutils.quote(m.group('path')))
75
62
    return str(url)
76
63
 
77
64
 
78
 
def parse_cvs_location(location):
 
65
def pserver_to_url(location):
 
66
    """Convert a CVS pserver location string to a URL.
 
67
 
 
68
    :param location: pserver URL
 
69
    :return: A cvs+pserver URL
 
70
    """
79
71
    parts = location.split(':')
80
 
    if parts[0] or parts[1] not in ('pserver', 'ssh'):
 
72
    if parts[0] or parts[1] != 'pserver':
81
73
        raise ValueError('not a valid pserver location string')
82
74
    try:
83
75
        (username, hostname) = parts[2].split('@', 1)
84
76
    except IndexError:
85
77
        hostname = parts[2]
86
78
        username = None
87
 
    scheme = parts[1]
88
 
    path = parts[3]
89
 
    return (scheme, hostname, username, path)
90
 
 
91
 
 
92
 
def cvs_to_url(location):
93
 
    """Convert a CVS pserver location string to a URL.
94
 
 
95
 
    :param location: pserver URL
96
 
    :return: A cvs+pserver URL
97
 
    """
98
 
    (scheme, host, user, path) = parse_cvs_location(location)
99
79
    return str(urlutils.URL(
100
 
        scheme='cvs+' + scheme,
101
 
        quoted_user=urlutils.quote(user) if user else None,
102
 
        quoted_host=urlutils.quote(host),
 
80
        scheme='cvs+pserver',
 
81
        quoted_user=urlutils.quote(username) if username else None,
 
82
        quoted_host=urlutils.quote(hostname),
103
83
        quoted_password=None,
104
84
        port=None,
105
 
        quoted_path=urlutils.quote(path)))
 
85
        quoted_path=urlutils.quote(parts[3])))
106
86
 
107
87
 
108
88
def location_to_url(location, purpose=None):
120
100
        raise AssertionError("location not a byte or unicode string")
121
101
 
122
102
    if location.startswith(':pserver:'):
123
 
        return cvs_to_url(location)
 
103
        return pserver_to_url(location)
124
104
 
125
105
    from .directory_service import directories
126
106
    location = directories.dereference(location, purpose)