/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-20 02:17:05 UTC
  • mfrom: (7518.1.2 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200720021705-5f11tmo1hdqjxm6x
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/387628

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
hooks = LocationHooks()
41
41
 
42
 
 
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.
45
44
 
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
50
49
    """
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,
 
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
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))
62
75
    return str(url)
63
76
 
64
77
 
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
 
    """
 
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')
74
82
    try:
75
83
        (username, hostname) = parts[2].split('@', 1)
76
84
    except IndexError:
77
85
        hostname = parts[2]
78
86
        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)
79
99
    return str(urlutils.URL(
80
 
        scheme='cvs+pserver',
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,
84
104
        port=None,
85
 
        quoted_path=urlutils.quote(parts[3])))
 
105
        quoted_path=urlutils.quote(path)))
86
106
 
87
107
 
88
108
def location_to_url(location, purpose=None):
100
120
        raise AssertionError("location not a byte or unicode string")
101
121
 
102
122
    if location.startswith(':pserver:'):
103
 
        return pserver_to_url(location)
 
123
        return cvs_to_url(location)
104
124
 
105
125
    from .directory_service import directories
106
126
    location = directories.dereference(location, purpose)