~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/urlutils.py

  • Committer: Aaron Bentley
  • Date: 2009-03-24 15:47:32 UTC
  • mto: This revision was merged to the branch mainline in revision 4241.
  • Revision ID: aaron@aaronbentley.com-20090324154732-bwkvi4dx3o90a7dq
Add output, emit minimal inventory delta.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Bazaar -- distributed version control
 
2
#
 
3
# Copyright (C) 2006 Canonical Ltd
2
4
#
3
5
# This program is free software; you can redistribute it and/or modify
4
6
# it under the terms of the GNU General Public License as published by
75
77
    This assumes that both paths are already fully specified file:// URLs.
76
78
    """
77
79
    if len(base) < MIN_ABS_FILEURL_LENGTH:
78
 
        raise ValueError('Length of base (%r) must equal or'
 
80
        raise ValueError('Length of base must be equal or'
79
81
            ' exceed the platform minimum url length (which is %d)' %
80
 
            (base, MIN_ABS_FILEURL_LENGTH))
 
82
            MIN_ABS_FILEURL_LENGTH)
81
83
    base = local_path_from_url(base)
82
84
    path = local_path_from_url(path)
83
85
    return escape(osutils.relpath(base, path))
217
219
# jam 20060502 Sorted to 'l' because the final target is 'local_path_from_url'
218
220
def _posix_local_path_from_url(url):
219
221
    """Convert a url like file:///path/to/foo into /path/to/foo"""
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/')
226
 
    else:
227
 
        path = url[len('file://'):]
 
222
    if not url.startswith('file:///'):
 
223
        raise errors.InvalidURL(url, 'local urls must start with file:///')
228
224
    # We only strip off 2 slashes
229
 
    return unescape(path)
 
225
    return unescape(url[len('file://'):])
230
226
 
231
227
 
232
228
def _posix_local_path_to_url(path):
691
687
    if len(segments) == 0:
692
688
        return '.'
693
689
    return osutils.pathjoin(*segments)
694
 
 
695
 
 
696
 
 
697
 
def parse_url(url):
698
 
    """Extract the server address, the credentials and the path from the url.
699
 
 
700
 
    user, password, host and path should be quoted if they contain reserved
701
 
    chars.
702
 
 
703
 
    :param url: an quoted url
704
 
 
705
 
    :return: (scheme, user, password, host, port, path) tuple, all fields
706
 
        are unquoted.
707
 
    """
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
714
 
    if '@' in netloc:
715
 
        user, host = netloc.rsplit('@', 1)
716
 
        if ':' in user:
717
 
            user, password = user.split(':', 1)
718
 
            password = urllib.unquote(password)
719
 
        user = urllib.unquote(user)
720
 
    else:
721
 
        host = netloc
722
 
 
723
 
    if ':' in host and not (host[0] == '[' and host[-1] == ']'): #there *is* port
724
 
        host, port = host.rsplit(':',1)
725
 
        try:
726
 
            port = int(port)
727
 
        except ValueError:
728
 
            raise errors.InvalidURL('invalid port number %s in url:\n%s' %
729
 
                                    (port, url))
730
 
    if host != "" and host[0] == '[' and host[-1] == ']': #IPv6
731
 
        host = host[1:-1]
732
 
 
733
 
    host = urllib.unquote(host)
734
 
    path = urllib.unquote(path)
735
 
 
736
 
    return (scheme, user, password, host, port, path)