Rev 2436: Change smart protocol version two prefix to '2\n'. in http://bazaar.launchpad.net/~bzr/bzr/hpss-protocol2
Andrew Bennetts
andrew.bennetts at canonical.com
Tue Apr 24 09:37:56 BST 2007
At http://bazaar.launchpad.net/~bzr/bzr/hpss-protocol2
------------------------------------------------------------
revno: 2436
revision-id: andrew.bennetts at canonical.com-20070424083632-f7kadff1wbp3eszn
parent: andrew.bennetts at canonical.com-20070424075513-ibtrd164miun08a8
committer: Andrew Bennetts <andrew.bennetts at canonical.com>
branch nick: hpss-protocol2
timestamp: Tue 2007-04-24 18:36:32 +1000
message:
Change smart protocol version two prefix to '2\n'.
modified:
bzrlib/smart/medium.py medium.py-20061103051856-rgu2huy59fkz902q-1
bzrlib/smart/protocol.py protocol.py-20061108035435-ot0lstk2590yqhzr-1
bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
bzrlib/tests/test_wsgi.py test_wsgi.py-20061005091552-rz8pva0olkxv0sd8-1
bzrlib/transport/http/wsgi.py wsgi.py-20061005091552-rz8pva0olkxv0sd8-2
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py 2007-04-24 07:55:13 +0000
+++ b/bzrlib/smart/medium.py 2007-04-24 08:36:32 +0000
@@ -79,7 +79,7 @@
def _build_protocol(self):
# Identify the protocol version.
bytes = self._get_bytes(2)
- if bytes.startswith('2\x01'):
+ if bytes.startswith('2\n'):
protocol_class = SmartServerRequestProtocolTwo
bytes = bytes[2:]
else:
=== modified file 'bzrlib/smart/protocol.py'
--- a/bzrlib/smart/protocol.py 2007-04-24 07:55:13 +0000
+++ b/bzrlib/smart/protocol.py 2007-04-24 08:36:32 +0000
@@ -160,15 +160,15 @@
class SmartServerRequestProtocolTwo(SmartServerRequestProtocolOne):
r"""Version two of the server side of the smart protocol.
- This prefixes responses with the protocol version: "2\x01".
+ This prefixes responses with the protocol version: "2\n".
"""
def _write_protocol_version(self):
r"""Write any prefixes this protocol requires.
- Version two sends "2\x01".
+ Version two sends "2\n".
"""
- self._write_func('2\x01')
+ self._write_func('2\n')
class LengthPrefixedBodyDecoder(object):
@@ -374,10 +374,10 @@
class SmartClientRequestProtocolTwo(SmartClientRequestProtocolOne):
r"""Version two of the client side of the smart protocol.
- This prefixes the request with the protocol version: "2\x01".
+ This prefixes the request with the protocol version: "2\n".
"""
- _version_string = '2\x01'
+ _version_string = '2\n'
def read_response_tuple(self, expect_body=False):
"""Read a response tuple from the wire.
@@ -392,7 +392,7 @@
def _write_protocol_version(self):
r"""Write any prefixes this protocol requires.
- Version two sends "2\x01".
+ Version two sends "2\n".
"""
self._request.accept_bytes(SmartClientRequestProtocolTwo._version_string)
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2007-04-24 07:55:13 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2007-04-24 08:36:32 +0000
@@ -806,23 +806,23 @@
self.assertProtocolOne(server_protocol)
def test_pipe_like_build_protocol_non_two(self):
- # A request that doesn't start with "2\x01" is version one.
+ # A request that doesn't start with "2\n" is version one.
server_protocol = self.build_protocol_pipe_like('2-')
self.assertProtocolOne(server_protocol)
def test_socket_build_protocol_non_two(self):
- # A request that doesn't start with "2\x01" is version one.
+ # A request that doesn't start with "2\n" is version one.
server_protocol = self.build_protocol_socket('2-')
self.assertProtocolOne(server_protocol)
def test_pipe_like_build_protocol_two(self):
- # A request that starts with "2\x01" is version two.
- server_protocol = self.build_protocol_pipe_like('2\x01')
+ # A request that starts with "2\n" is version two.
+ server_protocol = self.build_protocol_pipe_like('2\n')
self.assertProtocolTwo(server_protocol)
def test_socket_build_protocol_two(self):
- # A request that starts with "2\x01" is version two.
- server_protocol = self.build_protocol_socket('2\x01')
+ # A request that starts with "2\n" is version two.
+ server_protocol = self.build_protocol_socket('2\n')
self.assertProtocolTwo(server_protocol)
@@ -1605,7 +1605,7 @@
self.assertEqual('abc', smart_protocol.in_buffer)
smart_protocol.accept_bytes('\n')
self.assertEqual(
- "2\x01error\x01Generic bzr smart protocol error: bad request 'abc'\n",
+ "2\nerror\x01Generic bzr smart protocol error: bad request 'abc'\n",
out_stream.getvalue())
self.assertTrue(smart_protocol.has_dispatched)
self.assertEqual(0, smart_protocol.next_read_size())
@@ -1629,7 +1629,7 @@
out_stream.write)
smart_protocol.accept_bytes('readv\x01foo\n3\n3,3done\n')
self.assertEqual(0, smart_protocol.next_read_size())
- self.assertEqual('2\x01readv\n3\ndefdone\n', out_stream.getvalue())
+ self.assertEqual('2\nreadv\n3\ndefdone\n', out_stream.getvalue())
self.assertEqual('', smart_protocol.excess_buffer)
self.assertEqual('', smart_protocol.in_buffer)
@@ -1638,19 +1638,19 @@
smart_protocol = protocol.SmartServerRequestProtocolTwo(
None, out_stream.write)
smart_protocol.accept_bytes('hello\nhello\n')
- self.assertEqual("2\x01ok\x012\n", out_stream.getvalue())
+ self.assertEqual("2\nok\x012\n", out_stream.getvalue())
self.assertEqual("hello\n", smart_protocol.excess_buffer)
self.assertEqual("", smart_protocol.in_buffer)
def test_accept_excess_bytes_after_body(self):
# The excess bytes look like the start of another request.
protocol = self.build_protocol_waiting_for_body()
- protocol.accept_bytes('7\nabcdefgdone\n2\x01')
+ protocol.accept_bytes('7\nabcdefgdone\n2\n')
self.assertTrue(self.end_received)
- self.assertEqual("2\x01", protocol.excess_buffer)
+ self.assertEqual("2\n", protocol.excess_buffer)
self.assertEqual("", protocol.in_buffer)
protocol.accept_bytes('Y')
- self.assertEqual("2\x01Y", protocol.excess_buffer)
+ self.assertEqual("2\nY", protocol.excess_buffer)
self.assertEqual("", protocol.in_buffer)
def test_accept_excess_bytes_after_dispatch(self):
@@ -1658,11 +1658,11 @@
smart_protocol = protocol.SmartServerRequestProtocolTwo(
None, out_stream.write)
smart_protocol.accept_bytes('hello\n')
- self.assertEqual("2\x01ok\x012\n", out_stream.getvalue())
- smart_protocol.accept_bytes('2\x01hel')
- self.assertEqual("2\x01hel", smart_protocol.excess_buffer)
+ self.assertEqual("2\nok\x012\n", out_stream.getvalue())
+ smart_protocol.accept_bytes('2\nhel')
+ self.assertEqual("2\nhel", smart_protocol.excess_buffer)
smart_protocol.accept_bytes('lo\n')
- self.assertEqual("2\x01hello\n", smart_protocol.excess_buffer)
+ self.assertEqual("2\nhello\n", smart_protocol.excess_buffer)
self.assertEqual("", smart_protocol.in_buffer)
def test__send_response_sets_finished_reading(self):
@@ -1682,7 +1682,7 @@
# accept_bytes(tuple_based_encoding_of_hello) and reads and parses the
# response of tuple-encoded (ok, 1). Also, seperately we should test
# the error if the response is a non-understood version.
- input = StringIO('2\x01ok\x012\n')
+ input = StringIO('2\nok\x012\n')
output = StringIO()
client_medium = medium.SmartSimplePipesClientMedium(input, output)
request = client_medium.get_request()
@@ -1715,18 +1715,18 @@
# protocol.call() can get back an empty tuple as a response. This occurs
# when the parsed line is an empty line, and results in a tuple with
# one element - an empty string.
- self.assertServerToClientEncoding('2\x01\n', ('', ), [(), ('', )])
+ self.assertServerToClientEncoding('2\n\n', ('', ), [(), ('', )])
def untest_client_call_three_element_response(self):
# protocol.call() can get back tuples of other lengths. A three element
# tuple should be unpacked as three strings.
- self.assertServerToClientEncoding('2\x01a\x01b\x0134\n', ('a', 'b', '34'),
+ self.assertServerToClientEncoding('2\na\x01b\x0134\n', ('a', 'b', '34'),
[('a', 'b', '34')])
def test_client_call_with_body_bytes_uploads(self):
# protocol.call_with_body_bytes should length-prefix the bytes onto the
# wire.
- expected_bytes = "2\x01foo\n7\nabcdefgdone\n"
+ expected_bytes = "2\nfoo\n7\nabcdefgdone\n"
input = StringIO("\n")
output = StringIO()
client_medium = medium.SmartSimplePipesClientMedium(input, output)
@@ -1738,7 +1738,7 @@
def test_client_call_with_body_readv_array(self):
# protocol.call_with_upload should encode the readv array and then
# length-prefix the bytes onto the wire.
- expected_bytes = "2\x01foo\n7\n1,2\n5,6done\n"
+ expected_bytes = "2\nfoo\n7\n1,2\n5,6done\n"
input = StringIO("\n")
output = StringIO()
client_medium = medium.SmartSimplePipesClientMedium(input, output)
@@ -1751,7 +1751,7 @@
# read_body_bytes should decode the body bytes from the wire into
# a response.
expected_bytes = "1234567"
- server_bytes = "2\x01ok\n7\n1234567done\n"
+ server_bytes = "2\nok\n7\n1234567done\n"
input = StringIO(server_bytes)
output = StringIO()
client_medium = medium.SmartSimplePipesClientMedium(input, output)
@@ -1768,7 +1768,7 @@
# LengthPrefixedBodyDecoder that is already well tested - we can skip
# that.
expected_bytes = "1234567"
- server_bytes = "2\x01ok\n7\n1234567done\n"
+ server_bytes = "2\nok\n7\n1234567done\n"
input = StringIO(server_bytes)
output = StringIO()
client_medium = medium.SmartSimplePipesClientMedium(input, output)
@@ -1785,7 +1785,7 @@
# cancelling the expected body needs to finish the request, but not
# read any more bytes.
expected_bytes = "1234567"
- server_bytes = "2\x01ok\n7\n1234567done\n"
+ server_bytes = "2\nok\n7\n1234567done\n"
input = StringIO(server_bytes)
output = StringIO()
client_medium = medium.SmartSimplePipesClientMedium(input, output)
=== modified file 'bzrlib/tests/test_wsgi.py'
--- a/bzrlib/tests/test_wsgi.py 2007-04-24 07:55:13 +0000
+++ b/bzrlib/tests/test_wsgi.py 2007-04-24 08:36:32 +0000
@@ -204,7 +204,7 @@
self.assertEqual('error\x01incomplete request\n', response)
def test_protocol_version_detection_one(self):
- # SmartWSGIApp detects requests that don't start with '2\x01' as version
+ # SmartWSGIApp detects requests that don't start with '2\n' as version
# one.
transport = memory.MemoryTransport()
wsgi_app = wsgi.SmartWSGIApp(transport)
@@ -222,10 +222,10 @@
self.assertEqual('ok\x012\n', response)
def test_protocol_version_detection_two(self):
- # SmartWSGIApp detects requests that start with '2\x01' as version two.
+ # SmartWSGIApp detects requests that start with '2\n' as version two.
transport = memory.MemoryTransport()
wsgi_app = wsgi.SmartWSGIApp(transport)
- fake_input = StringIO('2\x01hello\n')
+ fake_input = StringIO('2\nhello\n')
environ = self.build_environ({
'REQUEST_METHOD': 'POST',
'CONTENT_LENGTH': len(fake_input.getvalue()),
@@ -236,7 +236,7 @@
response = self.read_response(iterable)
self.assertEqual('200 OK', self.status)
# Expect a version 2-encoded response.
- self.assertEqual('2\x01ok\x012\n', response)
+ self.assertEqual('2\nok\x012\n', response)
class FakeRequest(object):
=== modified file 'bzrlib/transport/http/wsgi.py'
--- a/bzrlib/transport/http/wsgi.py 2007-04-24 07:55:13 +0000
+++ b/bzrlib/transport/http/wsgi.py 2007-04-24 08:36:32 +0000
@@ -134,7 +134,7 @@
def make_request(self, transport, write_func, request_bytes):
# XXX: This duplicates the logic in
# SmartServerStreamMedium._build_protocol.
- if request_bytes.startswith('2\x01'):
+ if request_bytes.startswith('2\n'):
protocol_class = protocol.SmartServerRequestProtocolTwo
request_bytes = request_bytes[2:]
else:
More information about the bazaar-commits
mailing list