Rev 3628: (spiv) Fix a regression in bzr+http:// where http wasn't implementing in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Aug 14 05:22:55 BST 2008


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

------------------------------------------------------------
revno: 3628
revision-id: pqm at pqm.ubuntu.com-20080814042250-v7qws60l3fjwelb1
parent: pqm at pqm.ubuntu.com-20080814035325-ikgddts7pv17l23e
parent: andrew.bennetts at canonical.com-20080814021531-3axt0ak75mpxobrk
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-08-14 05:22:50 +0100
message:
  (spiv) Fix a regression in bzr+http:// where http wasn't implementing
  	a necessary function.
modified:
  bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
  bzrlib/tests/http_utils.py     HTTPTestUtil.py-20050914180604-247d3aafb7a43343
  bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
  bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
    ------------------------------------------------------------
    revno: 3606.4.1
    revision-id: andrew.bennetts at canonical.com-20080814021531-3axt0ak75mpxobrk
    parent: pqm at pqm.ubuntu.com-20080805202941-gdv30kq4cign8fs4
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: hpss-http-bug
    timestamp: Thu 2008-08-14 12:15:31 +1000
    message:
      Fix NotImplementedError when probing for smart protocol via HTTP.
    modified:
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/http_utils.py     HTTPTestUtil.py-20050914180604-247d3aafb7a43343
      bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
      bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2008-07-22 00:52:19 +0000
+++ b/bzrlib/smart/medium.py	2008-08-14 02:15:31 +0000
@@ -80,6 +80,28 @@
     return protocol_factory, bytes
 
 
+def _get_line(read_bytes_func):
+    """Read bytes using read_bytes_func until a newline byte.
+    
+    This isn't particularly efficient, so should only be used when the
+    expected size of the line is quite short.
+    
+    :returns: a tuple of two strs: (line, excess)
+    """
+    newline_pos = -1
+    bytes = ''
+    while newline_pos == -1:
+        new_bytes = read_bytes_func(1)
+        bytes += new_bytes
+        if new_bytes == '':
+            # Ran out of bytes before receiving a complete line.
+            return bytes, ''
+        newline_pos = bytes.find('\n')
+    line = bytes[:newline_pos+1]
+    excess = bytes[newline_pos+1:]
+    return line, excess
+
+
 class SmartMedium(object):
     """Base class for smart protocol media, both client- and server-side."""
 
@@ -131,17 +153,8 @@
 
         :returns: a string of bytes ending in a newline (byte 0x0A).
         """
-        newline_pos = -1
-        bytes = ''
-        while newline_pos == -1:
-            new_bytes = self.read_bytes(1)
-            bytes += new_bytes
-            if new_bytes == '':
-                # Ran out of bytes before receiving a complete line.
-                return bytes
-            newline_pos = bytes.find('\n')
-        line = bytes[:newline_pos+1]
-        self._push_back(bytes[newline_pos+1:])
+        line, excess = _get_line(self.read_bytes)
+        self._push_back(excess)
         return line
  
 
@@ -438,7 +451,7 @@
         return self._medium.read_bytes(count)
 
     def read_line(self):
-        line = self._medium._get_line()
+        line = self._read_line()
         if not line.endswith('\n'):
             # end of file encountered reading from server
             raise errors.ConnectionReset(
@@ -446,6 +459,14 @@
                 "(and try -Dhpss if further diagnosis is required)")
         return line
 
+    def _read_line(self):
+        """Helper for SmartClientMediumRequest.read_line.
+        
+        By default this forwards to self._medium._get_line because we are
+        operating on the medium's stream.
+        """
+        return self._medium._get_line()
+
 
 class SmartClientMedium(SmartMedium):
     """Smart client is a medium for sending smart protocol requests over."""

=== modified file 'bzrlib/tests/http_utils.py'
--- a/bzrlib/tests/http_utils.py	2008-05-16 05:55:23 +0000
+++ b/bzrlib/tests/http_utils.py	2008-08-14 02:15:31 +0000
@@ -28,10 +28,13 @@
 from bzrlib import (
     errors,
     tests,
-    transport,
     )
 from bzrlib.smart import medium, protocol
 from bzrlib.tests import http_server
+from bzrlib.transport import (
+    chroot,
+    get_transport,
+    )
 
 
 class HTTPServerWithSmarts(http_server.HttpServer):
@@ -46,13 +49,29 @@
 
 
 class SmartRequestHandler(http_server.TestingHTTPRequestHandler):
-    """Extend TestingHTTPRequestHandler to support smart client POSTs."""
+    """Extend TestingHTTPRequestHandler to support smart client POSTs.
+    
+    XXX: This duplicates a fair bit of the logic in bzrlib.transport.http.wsgi.
+    """
 
     def do_POST(self):
         """Hand the request off to a smart server instance."""
+        backing = get_transport(self.server.test_case_server._home_dir)
+        chroot_server = chroot.ChrootServer(backing)
+        chroot_server.setUp()
+        try:
+            t = get_transport(chroot_server.get_url())
+            self.do_POST_inner(t)
+        finally:
+            chroot_server.tearDown()
+
+    def do_POST_inner(self, chrooted_transport):
         self.send_response(200)
         self.send_header("Content-type", "application/octet-stream")
-        t = transport.get_transport(self.server.test_case_server._home_dir)
+        if not self.path.endswith('.bzr/smart'):
+            raise AssertionError(
+                'POST to path not ending in .bzr/smart: %r' % (self.path,))
+        t = chrooted_transport.clone(self.path[:-len('.bzr/smart')])
         # if this fails, we should return 400 bad request, but failure is
         # failure for now - RBC 20060919
         data_length = int(self.headers['Content-Length'])

=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py	2008-05-19 07:50:49 +0000
+++ b/bzrlib/tests/test_http.py	2008-08-14 02:15:31 +0000
@@ -34,9 +34,11 @@
 
 import bzrlib
 from bzrlib import (
+    bzrdir,
     config,
     errors,
     osutils,
+    remote as _mod_remote,
     tests,
     transport,
     ui,
@@ -1667,6 +1669,13 @@
         return http_utils.HTTPServerWithSmarts(
             protocol_version=self._protocol_version)
 
+    def test_open_bzrdir(self):
+        branch = self.make_branch('relpath')
+        http_server = self.get_readonly_server()
+        url = http_server.get_url() + 'relpath'
+        bd = bzrdir.BzrDir.open(url)
+        self.assertIsInstance(bd, _mod_remote.RemoteBzrDir)
+
     def test_bulk_data(self):
         # We should be able to send and receive bulk data in a single message.
         # The 'readv' command in the smart protocol both sends and receives

=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py	2008-07-21 08:45:17 +0000
+++ b/bzrlib/transport/http/__init__.py	2008-08-14 02:15:31 +0000
@@ -555,6 +555,14 @@
         """See SmartClientMediumRequest._read_bytes."""
         return self._response_body.read(count)
 
+    def _read_line(self):
+        line, excess = medium._get_line(self._response_body.read)
+        if excess != '':
+            raise AssertionError(
+                '_get_line returned excess bytes, but this mediumrequest '
+                'cannot handle excess. (%r)' % (excess,))
+        return line
+
     def _finished_reading(self):
         """See SmartClientMediumRequest._finished_reading."""
         pass




More information about the bazaar-commits mailing list