/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): Gustav Hartvigsson
  • Date: 2021-01-10 18:46:30 UTC
  • mfrom: (7526.1.1 brz-removed-api-doc)
  • mto: This revision was merged to the branch mainline in revision 7532.
  • Revision ID: breezy.the.bot@gmail.com-20210110184630-dxu0g9dqq020uiw6
Drop documentation for removed API API.

Merged from https://code.launchpad.net/~gustav-hartvigsson/brz/removed-api-doc/+merge/396033

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':
73
 
        raise ValueError('not a valid pserver location string')
 
80
    if parts[0] or parts[1] not in ('pserver', 'ssh', 'extssh'):
 
81
        raise ValueError('not a valid CVS 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
    if scheme == 'extssh':
 
89
        scheme = 'ssh'
 
90
    path = parts[3]
 
91
    return (scheme, hostname, username, path)
 
92
 
 
93
 
 
94
def cvs_to_url(location):
 
95
    """Convert a CVS pserver location string to a URL.
 
96
 
 
97
    :param location: pserver URL
 
98
    :return: A cvs+pserver URL
 
99
    """
 
100
    (scheme, host, user, path) = parse_cvs_location(location)
79
101
    return str(urlutils.URL(
80
 
        scheme='cvs+pserver',
81
 
        quoted_user=urlutils.quote(username) if username else None,
82
 
        quoted_host=urlutils.quote(hostname),
 
102
        scheme='cvs+' + scheme,
 
103
        quoted_user=urlutils.quote(user) if user else None,
 
104
        quoted_host=urlutils.quote(host),
83
105
        quoted_password=None,
84
106
        port=None,
85
 
        quoted_path=urlutils.quote(parts[3])))
 
107
        quoted_path=urlutils.quote(path)))
86
108
 
87
109
 
88
110
def location_to_url(location, purpose=None):
99
121
    if not isinstance(location, str):
100
122
        raise AssertionError("location not a byte or unicode string")
101
123
 
102
 
    if location.startswith(':pserver:'):
103
 
        return pserver_to_url(location)
 
124
    if location.startswith(':pserver:') or location.startswith(':extssh:'):
 
125
        return cvs_to_url(location)
104
126
 
105
127
    from .directory_service import directories
106
128
    location = directories.dereference(location, purpose)