Rev 2509: Finish http refactoring. Test suite passing. in file:///v/home/vila/src/experimental/reuse.transports/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Jun 1 11:02:07 BST 2007


At file:///v/home/vila/src/experimental/reuse.transports/

------------------------------------------------------------
revno: 2509
revision-id: v.ladeuil+lp at free.fr-20070601100205-i8hq7x0zm8k79g90
parent: v.ladeuil+lp at free.fr-20070601080226-5styxtzexznctvg0
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Fri 2007-06-01 12:02:05 +0200
message:
  Finish http refactoring. Test suite passing.
  
  * bzrlib/transport/http/_pycurl.py: 
  Replaces _real_abspath by _unqualified_abspath.
  
  * bzrlib/transport/http/_urllib.py:
  Replaces _real_abspath by _unqualified_abspath.
  
  * bzrlib/transport/http/__init__.py:
  (HttpTransportBase.abspath): Deleted.
  (HttpTransportBase._unqualified_abspath): Kind of _remote_path for
  hhtp, replaces _real_abspath.
  
  * bzrlib/tests/test_http.py:
  (TestHttpTransportUrls.test_invalid_http_urls): Delete the test
  for directories, we are not listable anyway.
modified:
  bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
  bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
  bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
  bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
-------------- next part --------------
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py	2007-04-26 07:21:24 +0000
+++ b/bzrlib/tests/test_http.py	2007-06-01 10:02:05 +0000
@@ -201,10 +201,9 @@
     def test_invalid_http_urls(self):
         """Trap invalid construction of urls"""
         t = self._transport('http://bazaar-vcs.org/bzr/bzr.dev/')
-        self.assertRaises(ValueError, t.abspath, '.bzr/')
-        t = self._transport('http://http://bazaar-vcs.org/bzr/bzr.dev/')
         self.assertRaises((errors.InvalidURL, errors.ConnectionError),
-                          t.has, 'foo/bar')
+                          self._transport,
+                          'http://http://bazaar-vcs.org/bzr/bzr.dev/')
 
     def test_http_root_urls(self):
         """Construction of URLs from server root"""

=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py	2007-05-30 07:15:16 +0000
+++ b/bzrlib/transport/http/__init__.py	2007-06-01 10:02:05 +0000
@@ -26,7 +26,11 @@
 import urllib
 import sys
 
-from bzrlib import errors, ui
+from bzrlib import (
+    errors,
+    ui,
+    urlutils,
+    )
 from bzrlib.smart import medium
 from bzrlib.trace import mutter
 from bzrlib.transport import (
@@ -122,26 +126,20 @@
     implementation.
     """
 
-    # _proto: "http" or "https"
-    # _qualified_proto: may have "+pycurl", etc
+    # _unqualified_scheme: "http" or "https"
+    # _scheme: may have "+pycurl", etc
 
     def __init__(self, base, from_transport=None):
         """Set the base path where files will be stored."""
         proto_match = re.match(r'^(https?)(\+\w+)?://', base)
         if not proto_match:
             raise AssertionError("not a http url: %r" % base)
-        self._proto = proto_match.group(1)
+        self._unqualified_scheme = proto_match.group(1)
         impl_name = proto_match.group(2)
         if impl_name:
             impl_name = impl_name[1:]
         self._impl_name = impl_name
-        if base[-1] != '/':
-            base = base + '/'
-        super(HttpTransportBase, self).__init__(base)
-        (apparent_proto, self._host,
-            self._path, self._parameters,
-            self._query, self._fragment) = urlparse.urlparse(self.base)
-        self._qualified_proto = apparent_proto
+        super(HttpTransportBase, self).__init__(base, from_transport)
         # range hint is handled dynamically throughout the life
         # of the transport object. We start by trying multi-range
         # requests and if the server returns bogus results, we
@@ -154,67 +152,13 @@
         else:
             self._range_hint = 'multi'
 
-    def abspath(self, relpath):
-        """Return the full url to the given relative path.
-
-        This can be supplied with a string or a list.
-
-        The URL returned always has the protocol scheme originally used to 
-        construct the transport, even if that includes an explicit
-        implementation qualifier.
-        """
-        assert isinstance(relpath, basestring)
-        if isinstance(relpath, unicode):
-            raise errors.InvalidURL(relpath, 'paths must not be unicode.')
-        if isinstance(relpath, basestring):
-            relpath_parts = relpath.split('/')
-        else:
-            # TODO: Don't call this with an array - no magic interfaces
-            relpath_parts = relpath[:]
-        if relpath.startswith('/'):
-            basepath = []
-        else:
-            # Except for the root, no trailing slashes are allowed
-            if len(relpath_parts) > 1 and relpath_parts[-1] == '':
-                raise ValueError(
-                    "path %r within branch %r seems to be a directory"
-                    % (relpath, self._path))
-            basepath = self._path.split('/')
-            if len(basepath) > 0 and basepath[-1] == '':
-                basepath = basepath[:-1]
-
-        for p in relpath_parts:
-            if p == '..':
-                if len(basepath) == 0:
-                    # In most filesystems, a request for the parent
-                    # of root, just returns root.
-                    continue
-                basepath.pop()
-            elif p == '.' or p == '':
-                continue # No-op
-            else:
-                basepath.append(p)
-        # Possibly, we could use urlparse.urljoin() here, but
-        # I'm concerned about when it chooses to strip the last
-        # portion of the path, and when it doesn't.
-        path = '/'.join(basepath)
-        if path == '':
-            path = '/'
-        result = urlparse.urlunparse((self._qualified_proto,
-                                    self._host, path, '', '', ''))
-        return result
-
-    def _real_abspath(self, relpath):
+    def _unqualified_abspath(self, relpath):
         """Produce absolute path, adjusting protocol if needed"""
-        abspath = self.abspath(relpath)
-        qp = self._qualified_proto
-        rp = self._proto
-        if self._qualified_proto != self._proto:
-            abspath = rp + abspath[len(qp):]
-        if not isinstance(abspath, str):
-            # escaping must be done at a higher level
-            abspath = abspath.encode('ascii')
-        return abspath
+        path = self._remote_path(relpath)
+        return self._unsplit_url(self._unqualified_scheme,
+                                 self._user, self._password,
+                                 self._host, self._port,
+                                 self._urlencode_abspath(path))
 
     def has(self, relpath):
         raise NotImplementedError("has() is abstract on %r" % self)

=== modified file 'bzrlib/transport/http/_pycurl.py'
--- a/bzrlib/transport/http/_pycurl.py	2007-03-13 17:00:20 +0000
+++ b/bzrlib/transport/http/_pycurl.py	2007-06-01 10:02:05 +0000
@@ -112,7 +112,7 @@
         # We set NO BODY=0 in _get_full, so it should be safe
         # to re-use the non-range curl object
         curl = self._curl
-        abspath = self._real_abspath(relpath)
+        abspath = self._unqualified_abspath(relpath)
         curl.setopt(pycurl.URL, abspath)
         self._set_curl_options(curl)
         curl.setopt(pycurl.HTTPGET, 1)
@@ -161,7 +161,7 @@
                  data: file that will be filled with the body
                  header: file that will be filled with the headers
         """
-        abspath = self._real_abspath(relpath)
+        abspath = self._unqualified_abspath(relpath)
         curl.setopt(pycurl.URL, abspath)
         self._set_curl_options(curl)
 
@@ -294,7 +294,7 @@
             raise errors.RedirectRequested(url,
                                            redirected_to,
                                            is_permament=(code == 301),
-                                           qual_proto=self._qualified_proto)
+                                           qual_proto=self._scheme)
 
 
 def get_test_permutations():

=== modified file 'bzrlib/transport/http/_urllib.py'
--- a/bzrlib/transport/http/_urllib.py	2007-04-22 16:32:04 +0000
+++ b/bzrlib/transport/http/_urllib.py	2007-06-01 10:02:05 +0000
@@ -64,7 +64,7 @@
             self._connection = None
             self._opener = self._opener_class()
 
-            authuri = extract_authentication_uri(self._real_abspath(self._path))
+            authuri = extract_authentication_uri(self._unqualified_abspath(self._path))
             self._auth = {'user': user, 'password': password,
                           'authuri': authuri}
             if user and password is not None: # '' is a valid password
@@ -105,7 +105,7 @@
             raise errors.RedirectRequested(request.get_full_url(),
                                            request.redirected_to,
                                            is_permament=(code == 301),
-                                           qual_proto=self._qualified_proto)
+                                           qual_proto=self._scheme)
 
         if request.redirected_to is not None:
             mutter('redirected from: %s to: %s' % (request.get_full_url(),
@@ -116,7 +116,7 @@
     def _get(self, relpath, ranges, tail_amount=0):
         """See HttpTransport._get"""
 
-        abspath = self._real_abspath(relpath)
+        abspath = self._unqualified_abspath(relpath)
         headers = {}
         if ranges or tail_amount:
             range_header = self.attempted_range_header(ranges, tail_amount)
@@ -138,7 +138,7 @@
         return code, data
 
     def _post(self, body_bytes):
-        abspath = self._real_abspath('.bzr/smart')
+        abspath = self._unqualified_abspath('.bzr/smart')
         response = self._perform(Request('POST', abspath, body_bytes))
         code = response.code
         data = handle_response(abspath, code, response.headers, response)
@@ -156,7 +156,7 @@
 
         Performs the request and leaves callers handle the results.
         """
-        abspath = self._real_abspath(relpath)
+        abspath = self._unqualified_abspath(relpath)
         request = Request('HEAD', abspath)
         response = self._perform(request)
 



More information about the bazaar-commits mailing list