Rev 4290: (stlman, mbp, jelmer) Support IPv6 literals in URLs. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Apr 15 02:34:03 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4290
revision-id: pqm at pqm.ubuntu.com-20090415013357-4e1qhuragbp9b8qu
parent: pqm at pqm.ubuntu.com-20090414031543-gqbs23oebd68p7h7
parent: jelmer at samba.org-20090411003125-1cr9fxb9z7b359gg
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-04-15 02:33:57 +0100
message:
  (stlman, mbp, jelmer) Support IPv6 literals in URLs.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
    ------------------------------------------------------------
    revno: 4253.4.4
    revision-id: jelmer at samba.org-20090411003125-1cr9fxb9z7b359gg
    parent: jelmer at samba.org-20090411002914-3w0nzogzhl9yq408
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: ipv6
    timestamp: Sat 2009-04-11 02:31:25 +0200
    message:
      Add myself to NEWS.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4253.4.3
    revision-id: jelmer at samba.org-20090411002914-3w0nzogzhl9yq408
    parent: jelmer at samba.org-20090410225851-rohblavzvmcxl0jm
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: ipv6
    timestamp: Sat 2009-04-11 02:29:14 +0200
    message:
      Support empty host name.
    modified:
      bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
    ------------------------------------------------------------
    revno: 4253.4.2
    revision-id: jelmer at samba.org-20090410225851-rohblavzvmcxl0jm
    parent: jelmer at samba.org-20090404014509-qworcvw6gemoajoo
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: ipv6
    timestamp: Sat 2009-04-11 00:58:51 +0200
    message:
      Still parse port in case of ipv6.
    modified:
      bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
    ------------------------------------------------------------
    revno: 4253.4.1
    revision-id: jelmer at samba.org-20090404014509-qworcvw6gemoajoo
    parent: pqm at pqm.ubuntu.com-20090404000810-fqvkqdjx9s1h9ks3
    parent: mbp at sourcefrog.net-20081201034223-zbdz1hrtxk7m12r0
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: ipv6
    timestamp: Sat 2009-04-04 03:45:09 +0200
    message:
      Merge in Martins' IPv6 literals patch.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
    ------------------------------------------------------------
    revno: 3873.3.2
    revision-id: mbp at sourcefrog.net-20081201034223-zbdz1hrtxk7m12r0
    parent: mbp at sourcefrog.net-20081201033327-2wrnkbf8ntcna0gi
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: trivial
    timestamp: Mon 2008-12-01 14:42:23 +1100
    message:
      Accept ipv6 literals in URLs
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
      bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
    ------------------------------------------------------------
    revno: 3873.3.1
    revision-id: mbp at sourcefrog.net-20081201033327-2wrnkbf8ntcna0gi
    parent: pqm at pqm.ubuntu.com-20081129023747-31a9su43tijw8p3r
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: trivial
    timestamp: Mon 2008-12-01 14:33:27 +1100
    message:
      Move Transport._split_url to urlutils, and ad a simple test
    modified:
      bzrlib/tests/test_urlutils.py  test_urlutils.py-20060502192900-46b1f9579987cf9c
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/urlutils.py             urlutils.py-20060502195429-e8a161ecf8fac004
=== modified file 'NEWS'
--- a/NEWS	2009-04-14 03:15:43 +0000
+++ b/NEWS	2009-04-15 01:33:57 +0000
@@ -159,6 +159,9 @@
 * ``bzr send`` is faster on repositories with deep histories.
   (Ian Clatworthy)
 
+* IPv6 literals are accepted in URLs.
+  (stlman, Martin Pool, Jelmer Vernooij, #165014)
+
 * Progress bars now show the rate of network activity for
   ``bzr+ssh://`` and ``bzr://`` connections.  (Andrew Bennetts)
 

=== modified file 'bzrlib/tests/test_urlutils.py'
--- a/bzrlib/tests/test_urlutils.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_urlutils.py	2009-04-04 01:45:09 +0000
@@ -672,3 +672,14 @@
                          '/bar', '/bar/baz'))
         self.assertEqual('.', urlutils.determine_relative_path(
                          '/bar', '/bar'))
+
+
+class TestParseURL(TestCase):
+
+    def test_parse_url(self):
+        self.assertEqual(urlutils.parse_url('http://example.com:80/one'),
+            ('http', None, None, 'example.com', 80, '/one'))
+        self.assertEqual(urlutils.parse_url('http://[1:2:3::40]/one'),
+                ('http', None, None, '1:2:3::40', None, '/one'))
+        self.assertEqual(urlutils.parse_url('http://[1:2:3::40]:80/one'),
+                ('http', None, None, '1:2:3::40', 80, '/one'))

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2009-03-24 01:53:42 +0000
+++ b/bzrlib/transport/__init__.py	2009-04-04 01:45:09 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006, 2007 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -1334,46 +1334,7 @@
 
     @staticmethod
     def _split_url(url):
-        """
-        Extract the server address, the credentials and the path from the url.
-
-        user, password, host and path should be quoted if they contain reserved
-        chars.
-
-        :param url: an quoted url
-
-        :return: (scheme, user, password, host, port, path) tuple, all fields
-            are unquoted.
-        """
-        if isinstance(url, unicode):
-            raise errors.InvalidURL('should be ascii:\n%r' % url)
-        url = url.encode('utf-8')
-        (scheme, netloc, path, params,
-         query, fragment) = urlparse.urlparse(url, allow_fragments=False)
-        user = password = host = port = None
-        if '@' in netloc:
-            user, host = netloc.rsplit('@', 1)
-            if ':' in user:
-                user, password = user.split(':', 1)
-                password = urllib.unquote(password)
-            user = urllib.unquote(user)
-        else:
-            host = netloc
-
-        if ':' in host:
-            host, port = host.rsplit(':', 1)
-            try:
-                port = int(port)
-            except ValueError:
-                raise errors.InvalidURL('invalid port number %s in url:\n%s' %
-                                        (port, url))
-        if host == '':
-            raise errors.InvalidURL('Host empty in: %s' % url)
-
-        host = urllib.unquote(host)
-        path = urllib.unquote(path)
-
-        return (scheme, user, password, host, port, path)
+        return urlutils.parse_url(url)
 
     @staticmethod
     def _unsplit_url(scheme, user, password, host, port, path):

=== modified file 'bzrlib/urlutils.py'
--- a/bzrlib/urlutils.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/urlutils.py	2009-04-11 00:29:14 +0000
@@ -1,6 +1,4 @@
-# Bazaar -- distributed version control
-#
-# Copyright (C) 2006 Canonical Ltd
+# Copyright (C) 2006, 2008 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -687,3 +685,49 @@
     if len(segments) == 0:
         return '.'
     return osutils.pathjoin(*segments)
+
+
+
+def parse_url(url):
+    """Extract the server address, the credentials and the path from the url.
+
+    user, password, host and path should be quoted if they contain reserved
+    chars.
+
+    :param url: an quoted url
+
+    :return: (scheme, user, password, host, port, path) tuple, all fields
+        are unquoted.
+    """
+    if isinstance(url, unicode):
+        raise errors.InvalidURL('should be ascii:\n%r' % url)
+    url = url.encode('utf-8')
+    (scheme, netloc, path, params,
+     query, fragment) = urlparse.urlparse(url, allow_fragments=False)
+    user = password = host = port = None
+    if '@' in netloc:
+        user, host = netloc.rsplit('@', 1)
+        if ':' in user:
+            user, password = user.split(':', 1)
+            password = urllib.unquote(password)
+        user = urllib.unquote(user)
+    else:
+        host = netloc
+
+    if ':' in host and not (host[0] == '[' and host[-1] == ']'): #there *is* port
+        host, port = host.rsplit(':',1)
+        try:
+            port = int(port)
+        except ValueError:
+            raise errors.InvalidURL('invalid port number %s in url:\n%s' %
+                                    (port, url))
+    if host != "" and host[0] == '[' and host[-1] == ']': #IPv6
+        host = host[1:-1]
+
+    if host == '':
+        raise errors.InvalidURL('Host empty in: %s' % url)
+
+    host = urllib.unquote(host)
+    path = urllib.unquote(path)
+
+    return (scheme, user, password, host, port, path)




More information about the bazaar-commits mailing list