This is an automated email from the ASF dual-hosted git repository. jdanek pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-python.git
commit 787c8b9475a0a6daffb6883feeba93fea6fdd062 Author: Jiri Daněk <jda...@redhat.com> AuthorDate: Mon Apr 10 11:21:22 2023 +0200 QPID-8631: use b"" to mark bytestring literals --- qpid/codec.py | 6 +- qpid/codec010.py | 4 +- qpid/compat.py | 4 +- qpid/connection08.py | 8 +-- qpid/delegates.py | 2 +- qpid/framer.py | 10 ++-- qpid/framing.py | 10 ++-- qpid/messaging/driver.py | 6 +- qpid/tests/codec.py | 62 ++++++++++----------- qpid/tests/codec010.py | 6 +- qpid/tests/connection.py | 22 ++++---- qpid/tests/framing.py | 120 ++++++++++++++++++++-------------------- qpid/tests/messaging/message.py | 10 ++-- qpid/tests/spec010.py | 8 +-- qpid_tests/broker_0_9/echo.py | 2 +- 15 files changed, 140 insertions(+), 140 deletions(-) diff --git a/qpid/codec.py b/qpid/codec.py index a300dc5..01c4309 100644 --- a/qpid/codec.py +++ b/qpid/codec.py @@ -667,13 +667,13 @@ class Codec: def encode_boolean(self, s): if (s): - self.pack("!c", "\x01") + self.pack("!c", b"\x01") else: - self.pack("!c", "\x00") + self.pack("!c", b"\x00") def decode_boolean(self): b = self.unpack("!c") - if b == "\x00": + if b == b"\x00": return False else: # AMQP spec says anything else is True diff --git a/qpid/codec010.py b/qpid/codec010.py index 8f9eee0..f742d4a 100644 --- a/qpid/codec010.py +++ b/qpid/codec010.py @@ -240,7 +240,7 @@ class Codec(Packer): return self.read(self.read_uint32()) def write_vbin32(self, b): if isinstance(b, buffer): - b = str(b) + b = bytes(b) # Allow unicode values in connection 'response' field if isinstance(b, unicode): b = b.encode('utf8') @@ -408,7 +408,7 @@ class Codec(Packer): class StringCodec(Codec): - def __init__(self, encoded = ""): + def __init__(self, encoded = b""): self.encoded = encoded def read(self, n): diff --git a/qpid/compat.py b/qpid/compat.py index f3559ab..c6619bd 100644 --- a/qpid/compat.py +++ b/qpid/compat.py @@ -158,7 +158,7 @@ if sys.platform in ('win32', 'cygwin'): self.write_sock = write_sock def _do_write(self): - self.write_sock.send("\0") + self.write_sock.send(b"\0") def _do_read(self): self.read_sock.recv(65536) @@ -198,7 +198,7 @@ else: self.read_fd, self.write_fd = os.pipe() def _do_write(self): - os.write(self.write_fd, "\0") + os.write(self.write_fd, b"\0") def _do_read(self): os.read(self.read_fd, 65536) diff --git a/qpid/connection08.py b/qpid/connection08.py index d8f14a2..338e79f 100644 --- a/qpid/connection08.py +++ b/qpid/connection08.py @@ -48,7 +48,7 @@ class SockIO: self.sock.sendall(buf) def read(self, n): - data = "" + data = b"" while len(data) < n: try: s = self.sock.recv(n - len(data)) @@ -179,7 +179,7 @@ class Connection: INIT="!4s4B" def init(self): - self.codec.pack(Connection.INIT, "AMQP", 1, 1, self.spec.major, + self.codec.pack(Connection.INIT, b"AMQP", 1, 1, self.spec.major, self.spec.minor) def tini(self): @@ -216,7 +216,7 @@ class Connection: frame.channel = channel end = c.decode_octet() if end != self.FRAME_END: - garbage = "" + garbage = b"" while end != self.FRAME_END: garbage += chr(end) end = c.decode_octet() @@ -291,7 +291,7 @@ class Connection: frame.subchannel = subchannel end = c.decode_octet() if end != self.FRAME_END: - garbage = "" + garbage = b"" while end != self.FRAME_END: garbage += chr(end) end = c.decode_octet() diff --git a/qpid/delegates.py b/qpid/delegates.py index 482f59f..487a376 100644 --- a/qpid/delegates.py +++ b/qpid/delegates.py @@ -177,7 +177,7 @@ class Client(Delegate): cli_minor = 10 self.connection.write_header(cli_major, cli_minor) magic, _, _, major, minor = self.connection.read_header() - if not (magic == "AMQP" and major == cli_major and minor == cli_minor): + if not (magic == b"AMQP" and major == cli_major and minor == cli_minor): raise VersionError("client: %s-%s, server: %s-%s" % (cli_major, cli_minor, major, minor)) diff --git a/qpid/framer.py b/qpid/framer.py index e676612..b0146b2 100644 --- a/qpid/framer.py +++ b/qpid/framer.py @@ -37,8 +37,8 @@ class Framer(Packer): def __init__(self, sock): self.sock = sock self.sock_lock = RLock() - self.tx_buf = "" - self.rx_buf = "" + self.tx_buf = b"" + self.rx_buf = b"" self.security_layer_tx = None self.security_layer_rx = None self.maxbufsize = 65535 @@ -60,7 +60,7 @@ class Framer(Packer): self._write(cipher_buf) else: self._write(self.tx_buf) - self.tx_buf = "" + self.tx_buf = b"" frm.debug("FLUSHED") finally: self.sock_lock.release() @@ -106,7 +106,7 @@ class Framer(Packer): else: continue except socket.error as e: - if self.rx_buf != "": + if self.rx_buf != b"": raise e else: raise Closed() @@ -124,7 +124,7 @@ class Framer(Packer): def write_header(self, major, minor): self.sock_lock.acquire() try: - self.pack(Framer.HEADER, "AMQP", 1, 1, major, minor) + self.pack(Framer.HEADER, b"AMQP", 1, 1, major, minor) self.flush() finally: self.sock_lock.release() diff --git a/qpid/framing.py b/qpid/framing.py index a441487..e44918b 100644 --- a/qpid/framing.py +++ b/qpid/framing.py @@ -81,7 +81,7 @@ class Segment: class FrameDecoder: def __init__(self): - self.input = "" + self.input = b"" self.output = [] self.parse = self.__frame_header @@ -122,7 +122,7 @@ class FrameDecoder: class FrameEncoder: def __init__(self): - self.output = "" + self.output = b"" def write(self, *frames): for frame in frames: @@ -134,7 +134,7 @@ class FrameEncoder: def read(self): result = self.output - self.output = "" + self.output = b"" return result class SegmentDecoder: @@ -150,7 +150,7 @@ class SegmentDecoder: if seg == None: seg = Segment(frm.isFirstSegment(), frm.isLastSegment(), - frm.type, frm.track, frm.channel, "") + frm.type, frm.track, frm.channel, b"") self.fragments[key] = seg seg.payload += frm.payload @@ -222,7 +222,7 @@ class OpEncoder: seg = Segment(True, False, seg_type, seg_track, op.channel, enc) self.segments.append(seg) if hasattr(op, "headers") and op.headers is not None: - hdrs = "" + hdrs = b"" for h in op.headers: hdrs += self.encode_compound(h) seg = Segment(False, False, segment_type.header, seg_track, op.channel, diff --git a/qpid/messaging/driver.py b/qpid/messaging/driver.py index cb6c931..ae2d4e6 100644 --- a/qpid/messaging/driver.py +++ b/qpid/messaging/driver.py @@ -631,8 +631,8 @@ class Engine: self.address_cache = Cache(self.connection.address_ttl) self._status = CLOSED - self._buf = "" - self._hdr = "" + self._buf = b"" + self._hdr = b"" # Set _last_in and _last_out here so heartbeats will be timed from the # beginning of connection if no data is sent/received. self._last_in = time.time() @@ -885,7 +885,7 @@ class Engine: def open(self): self._reset() self._status = OPEN - self._buf += struct.pack(HEADER, "AMQP", 1, 1, 0, 10) + self._buf += struct.pack(HEADER, b"AMQP", 1, 1, 0, 10) def disconnect(self): self.write_op(ConnectionClose(close_code.normal)) diff --git a/qpid/tests/codec.py b/qpid/tests/codec.py index 03f6fc2..6520e0e 100644 --- a/qpid/tests/codec.py +++ b/qpid/tests/codec.py @@ -121,10 +121,10 @@ class IntegerTestCase(BaseDataTypes): BaseDataTypes.__init__(self, *args) self.const_integer = 2 - self.const_integer_octet_encoded = '\x02' - self.const_integer_short_encoded = '\x00\x02' - self.const_integer_long_encoded = '\x00\x00\x00\x02' - self.const_integer_long_long_encoded = '\x00\x00\x00\x00\x00\x00\x00\x02' + self.const_integer_octet_encoded = b'\x02' + self.const_integer_short_encoded = b'\x00\x02' + self.const_integer_long_encoded = b'\x00\x00\x00\x02' + self.const_integer_long_long_encoded = b'\x00\x00\x00\x00\x00\x00\x00\x02' # -------------------------- # # Unsigned Octect - 8 bits # @@ -308,35 +308,35 @@ class BitTestCase(BaseDataTypes): """ sends in 11 """ - self.failUnlessEqual(self.callFunc('encode_bit', 1, 1), '\x03', '11 bit encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_bit', 1, 1), b'\x03', '11 bit encoding FAILED...') # ------------------- def test_bit2(self): """ sends in 10011 """ - self.failUnlessEqual(self.callFunc('encode_bit', 1, 1, 0, 0, 1), '\x13', '10011 bit encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_bit', 1, 1, 0, 0, 1), b'\x13', '10011 bit encoding FAILED...') # ------------------- def test_bit3(self): """ sends in 1110100111 [10 bits(right to left), should be compressed into two octets] """ - self.failUnlessEqual(self.callFunc('encode_bit', 1,1,1,0,0,1,0,1,1,1), '\xa7\x03', '1110100111(right to left) bit encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_bit', 1,1,1,0,0,1,0,1,1,1), b'\xa7\x03', '1110100111(right to left) bit encoding FAILED...') # ------------------------------------ def test_bit_decode_1(self): """ decode bit 1 """ - self.failUnlessEqual(self.readFunc('decode_bit', '\x01'), 1, 'decode bit 1 FAILED...') + self.failUnlessEqual(self.readFunc('decode_bit', b'\x01'), 1, 'decode bit 1 FAILED...') # ------------------------------------ def test_bit_decode_0(self): """ decode bit 0 """ - self.failUnlessEqual(self.readFunc('decode_bit', '\x00'), 0, 'decode bit 0 FAILED...') + self.failUnlessEqual(self.readFunc('decode_bit', b'\x00'), 0, 'decode bit 0 FAILED...') # ----------------------------------- # ----------------------------------- @@ -355,28 +355,28 @@ class StringTestCase(BaseDataTypes): """ 0 length short string """ - self.failUnlessEqual(self.callFunc('encode_shortstr', ''), '\x00', '0 length short string encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_shortstr', b''), b'\x00', '0 length short string encoding FAILED...') # ------------------------------------------- def test_short_string_positive_length(self): """ positive length short string """ - self.failUnlessEqual(self.callFunc('encode_shortstr', 'hello world'), '\x0bhello world', 'positive length short string encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_shortstr', b'hello world'), b'\x0bhello world', 'positive length short string encoding FAILED...') # ------------------------------------------- def test_short_string_out_of_upper_range(self): """ string length > 255 """ - self.failUnlessRaises(Exception, self.codec.encode_shortstr, 'x'*256) + self.failUnlessRaises(Exception, self.codec.encode_shortstr, b'x'*256) # ------------------------------------ def test_short_string_decode(self): """ short string decode """ - self.failUnlessEqual(self.readFunc('decode_shortstr', '\x0bhello world'), 'hello world', 'short string decode FAILED...') + self.failUnlessEqual(self.readFunc('decode_shortstr', b'\x0bhello world'), b'hello world', 'short string decode FAILED...') # ------------------------------------------------------------- # @@ -388,21 +388,21 @@ class StringTestCase(BaseDataTypes): """ 0 length long string """ - self.failUnlessEqual(self.callFunc('encode_longstr', ''), '\x00\x00\x00\x00', '0 length long string encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_longstr', b''), b'\x00\x00\x00\x00', '0 length long string encoding FAILED...') # ------------------------------------------- def test_long_string_positive_length(self): """ positive length long string """ - self.failUnlessEqual(self.callFunc('encode_longstr', 'hello world'), '\x00\x00\x00\x0bhello world', 'positive length long string encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_longstr', b'hello world'), b'\x00\x00\x00\x0bhello world', 'positive length long string encoding FAILED...') # ------------------------------------ def test_long_string_decode(self): """ long string decode """ - self.failUnlessEqual(self.readFunc('decode_longstr', '\x00\x00\x00\x0bhello world'), 'hello world', 'long string decode FAILED...') + self.failUnlessEqual(self.readFunc('decode_longstr', b'\x00\x00\x00\x0bhello world'), b'hello world', 'long string decode FAILED...') # -------------------------------------- @@ -431,15 +431,15 @@ class FieldTableTestCase(BaseDataTypes): """ BaseDataTypes.__init__(self, *args) - self.const_field_table_dummy_dict = {'$key1':'value1','$key2':'value2'} - self.const_field_table_dummy_dict_encoded = '\x00\x00\x00\x22\x05$key2S\x00\x00\x00\x06value2\x05$key1S\x00\x00\x00\x06value1' + self.const_field_table_dummy_dict = {b'$key2':b'value2',b'$key1':b'value1'} + self.const_field_table_dummy_dict_encoded = b'\x00\x00\x00\x22\x05$key2S\x00\x00\x00\x06value2\x05$key1S\x00\x00\x00\x06value1' # ------------------------------------------- def test_field_table_name_value_pair(self): """ valid name value pair """ - self.failUnlessEqual(self.callFunc('encode_table', {'$key1':'value1'}), '\x00\x00\x00\x11\x05$key1S\x00\x00\x00\x06value1', 'valid name value pair encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_table', {'$key1':'value1'}), b'\x00\x00\x00\x11\x05$key1S\x00\x00\x00\x06value1', 'valid name value pair encoding FAILED...') # --------------------------------------------------- def test_field_table_multiple_name_value_pair(self): @@ -469,28 +469,28 @@ class ContentTestCase(BaseDataTypes): """ inline content """ - self.failUnlessEqual(self.callFunc('encode_content', 'hello inline message'), '\x00\x00\x00\x00\x14hello inline message', 'inline content encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_content', 'hello inline message'), b'\x00\x00\x00\x00\x14hello inline message', 'inline content encoding FAILED...') # -------------------------------- def test_content_reference(self): """ reference content """ - self.failUnlessEqual(self.callFunc('encode_content', ReferenceId('dummyId')), '\x01\x00\x00\x00\x07dummyId', 'reference content encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_content', ReferenceId('dummyId')), b'\x01\x00\x00\x00\x07dummyId', 'reference content encoding FAILED...') # ------------------------------------ def test_content_inline_decode(self): """ inline content decode """ - self.failUnlessEqual(self.readFunc('decode_content', '\x00\x00\x00\x00\x14hello inline message'), 'hello inline message', 'inline content decode FAILED...') + self.failUnlessEqual(self.readFunc('decode_content', b'\x00\x00\x00\x00\x14hello inline message'), b'hello inline message', 'inline content decode FAILED...') # ------------------------------------ def test_content_reference_decode(self): """ reference content decode """ - self.failUnlessEqual(self.readFunc('decode_content', '\x01\x00\x00\x00\x07dummyId').id, 'dummyId', 'reference content decode FAILED...') + self.failUnlessEqual(self.readFunc('decode_content', b'\x01\x00\x00\x00\x07dummyId').id, b'dummyId', 'reference content decode FAILED...') # ----------------------------------- # ----------------------------------- @@ -498,21 +498,21 @@ class BooleanTestCase(BaseDataTypes): # ------------------- def test_true_encode(self): - self.failUnlessEqual(self.callFunc('encode_boolean', True), '\x01', 'True encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_boolean', True), b'\x01', 'True encoding FAILED...') # ------------------- def test_true_decode(self): - self.failUnlessEqual(self.readFunc('decode_boolean', '\x01'), True, 'True decoding FAILED...') - self.failUnlessEqual(self.readFunc('decode_boolean', '\x02'), True, 'True decoding FAILED...') - self.failUnlessEqual(self.readFunc('decode_boolean', '\xFF'), True, 'True decoding FAILED...') + self.failUnlessEqual(self.readFunc('decode_boolean', b'\x01'), True, 'True decoding FAILED...') + self.failUnlessEqual(self.readFunc('decode_boolean', b'\x02'), True, 'True decoding FAILED...') + self.failUnlessEqual(self.readFunc('decode_boolean', b'\xFF'), True, 'True decoding FAILED...') # ------------------- def test_false_encode(self): - self.failUnlessEqual(self.callFunc('encode_boolean', False), '\x00', 'False encoding FAILED...') + self.failUnlessEqual(self.callFunc('encode_boolean', False), b'\x00', 'False encoding FAILED...') # ------------------- def test_false_decode(self): - self.failUnlessEqual(self.readFunc('decode_boolean', '\x00'), False, 'False decoding FAILED...') + self.failUnlessEqual(self.readFunc('decode_boolean', b'\x00'), False, 'False decoding FAILED...') # ----------------------------------- # ----------------------------------- @@ -663,7 +663,7 @@ def oldtests(): for i in range(10): dotest("bit", [x == "1" for x in value*i]) - for value in ({}, {"asdf": "fdsa", "fdsa": 1, "three": 3}, {"one": 1}): + for value in ({}, {b"asdf": b"fdsa", b"fdsa": 1, b"three": 3}, {b"one": 1}): dotest("table", value) for type in ("octet", "short", "long", "longlong"): @@ -671,7 +671,7 @@ def oldtests(): dotest(type, value) for type in ("shortstr", "longstr"): - for value in ("", "a", "asdf"): + for value in (b"", b"a", b"asdf"): dotest(type, value) # ----------------------------------------- diff --git a/qpid/tests/codec010.py b/qpid/tests/codec010.py index cf0ab50..7f22b89 100644 --- a/qpid/tests/codec010.py +++ b/qpid/tests/codec010.py @@ -43,10 +43,10 @@ class CodecTest(TestCase): self.check("map", {"unicode": u"this is a unicode test"}) def testMapBinary(self): - self.check("map", {"binary": "\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5"}) + self.check("map", {"binary": b"\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5"}) def testMapBuffer(self): - s = "\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5" + s = b"\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5" dec = self.check("map", {"buffer": buffer(s)}, False) assert dec["buffer"] == s @@ -82,7 +82,7 @@ class CodecTest(TestCase): def testMapAll(self): decoded = self.check("map", {"string": "this is a test", "unicode": u"this is a unicode test", - "binary": "\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5", + "binary": b"\x7f\xb4R^\xe5\xf0:\x89\x96E1\xf6\xfe\xb9\x1b\xf5", "int": 3, "long": 2**32, "timestamp": timestamp(0), diff --git a/qpid/tests/connection.py b/qpid/tests/connection.py index f223501..e1dc7dd 100644 --- a/qpid/tests/connection.py +++ b/qpid/tests/connection.py @@ -103,11 +103,11 @@ class ConnectionTest(TestCase): c = self.connect() c.start(10) - ssn1 = c.session("test1", timeout=10) - ssn2 = c.session("test2", timeout=10) + ssn1 = c.session(b"test1", timeout=10) + ssn2 = c.session(b"test2", timeout=10) - assert ssn1 == c.sessions["test1"] - assert ssn2 == c.sessions["test2"] + assert ssn1 == c.sessions[b"test1"] + assert ssn2 == c.sessions[b"test2"] assert ssn1.channel != None assert ssn2.channel != None assert ssn1 in c.attached.values() @@ -125,7 +125,7 @@ class ConnectionTest(TestCase): assert ssn2 not in c.attached.values() assert ssn2 not in c.sessions.values() - ssn = c.session("session", timeout=10) + ssn = c.session(b"session", timeout=10) assert ssn.channel != None assert ssn in c.sessions.values() @@ -141,7 +141,7 @@ class ConnectionTest(TestCase): assert cmd.headers == None assert cmd.payload == None - msg = Message("this is a test") + msg = Message(b"this is a test") ssn.message_transfer("four", message=msg) cmd = self.queue.get(10) assert cmd.destination == "four" @@ -159,14 +159,14 @@ class ConnectionTest(TestCase): echos = ssn.incoming("echo") for i in range(10): - ssn.message_transfer("echo", message=Message("test%d" % i)) + ssn.message_transfer("echo", message=Message(b"test%d" % i)) ssn.auto_sync=False ssn.message_transfer("abort") for i in range(10): m = echos.get(timeout=10) - assert m.body == "test%d" % i + assert m.body == b"test%d" % i try: m = echos.get(timeout=10) @@ -193,7 +193,7 @@ class ConnectionTest(TestCase): echos.listen(listener, exc_listener) for i in range(10): - ssn.message_transfer("echo", message=Message("test%d" % i)) + ssn.message_transfer("echo", message=Message(b"test%d" % i)) ssn.auto_sync=False ssn.message_transfer("abort") @@ -208,7 +208,7 @@ class ConnectionTest(TestCase): for i in range(10): m = messages.pop(0) - assert m.body == "test%d" % i + assert m.body == b"test%d" % i assert len(exceptions) == 1 @@ -217,7 +217,7 @@ class ConnectionTest(TestCase): c.start(10) s = c.session("test") s.auto_sync = False - s.message_transfer("echo", message=Message("test")) + s.message_transfer("echo", message=Message(b"test")) s.sync(10) def testHeartbeat(self): diff --git a/qpid/tests/framing.py b/qpid/tests/framing.py index 2d987f8..2b39143 100644 --- a/qpid/tests/framing.py +++ b/qpid/tests/framing.py @@ -103,42 +103,42 @@ class FrameTest(Base): self.cmp_frames(f, df) def testEmpty(self): - self.enc_dec([Frame(0, 0, 0, 0, "")], - "\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00") + self.enc_dec([Frame(0, 0, 0, 0, b"")], + b"\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00") def testSingle(self): - self.enc_dec([Frame(0, 0, 0, 1, "payload")], - "\x00\x00\x00\x13\x00\x00\x00\x01\x00\x00\x00\x00payload") + self.enc_dec([Frame(0, 0, 0, 1, b"payload")], + b"\x00\x00\x00\x13\x00\x00\x00\x01\x00\x00\x00\x00payload") def testMaxChannel(self): - self.enc_dec([Frame(0, 0, 0, 65535, "max-channel")], - "\x00\x00\x00\x17\x00\x00\xff\xff\x00\x00\x00\x00max-channel") + self.enc_dec([Frame(0, 0, 0, 65535, b"max-channel")], + b"\x00\x00\x00\x17\x00\x00\xff\xff\x00\x00\x00\x00max-channel") def testMaxType(self): - self.enc_dec([Frame(0, 255, 0, 0, "max-type")], - "\x00\xff\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00max-type") + self.enc_dec([Frame(0, 255, 0, 0, b"max-type")], + b"\x00\xff\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00max-type") def testMaxTrack(self): - self.enc_dec([Frame(0, 0, 15, 0, "max-track")], - "\x00\x00\x00\x15\x00\x0f\x00\x00\x00\x00\x00\x00max-track") + self.enc_dec([Frame(0, 0, 15, 0, b"max-track")], + b"\x00\x00\x00\x15\x00\x0f\x00\x00\x00\x00\x00\x00max-track") def testSequence(self): - self.enc_dec([Frame(0, 0, 0, 0, "zero"), - Frame(0, 0, 0, 1, "one"), - Frame(0, 0, 1, 0, "two"), - Frame(0, 0, 1, 1, "three"), - Frame(0, 1, 0, 0, "four"), - Frame(0, 1, 0, 1, "five"), - Frame(0, 1, 1, 0, "six"), - Frame(0, 1, 1, 1, "seven"), - Frame(1, 0, 0, 0, "eight"), - Frame(1, 0, 0, 1, "nine"), - Frame(1, 0, 1, 0, "ten"), - Frame(1, 0, 1, 1, "eleven"), - Frame(1, 1, 0, 0, "twelve"), - Frame(1, 1, 0, 1, "thirteen"), - Frame(1, 1, 1, 0, "fourteen"), - Frame(1, 1, 1, 1, "fifteen")]) + self.enc_dec([Frame(0, 0, 0, 0, b"zero"), + Frame(0, 0, 0, 1, b"one"), + Frame(0, 0, 1, 0, b"two"), + Frame(0, 0, 1, 1, b"three"), + Frame(0, 1, 0, 0, b"four"), + Frame(0, 1, 0, 1, b"five"), + Frame(0, 1, 1, 0, b"six"), + Frame(0, 1, 1, 1, b"seven"), + Frame(1, 0, 0, 0, b"eight"), + Frame(1, 0, 0, 1, b"nine"), + Frame(1, 0, 1, 0, b"ten"), + Frame(1, 0, 1, 1, b"eleven"), + Frame(1, 1, 0, 0, b"twelve"), + Frame(1, 1, 0, 1, b"thirteen"), + Frame(1, 1, 1, 0, b"fourteen"), + Frame(1, 1, 1, 1, b"fifteen")]) class SegmentTest(Base): @@ -168,54 +168,54 @@ class SegmentTest(Base): self.cmp_segments(s1, s2) def testEmpty(self): - self.enc_dec([Segment(True, True, 0, 0, 0, "")], + self.enc_dec([Segment(True, True, 0, 0, 0, b"")], [Frame(FIRST_FRM | LAST_FRM | FIRST_SEG | LAST_SEG, 0, 0, 0, - "")]) + b"")]) def testSingle(self): - self.enc_dec([Segment(True, True, 0, 0, 0, "payload")], + self.enc_dec([Segment(True, True, 0, 0, 0, b"payload")], [Frame(FIRST_FRM | LAST_FRM | FIRST_SEG | LAST_SEG, 0, 0, 0, - "payload")]) + b"payload")]) def testMaxChannel(self): - self.enc_dec([Segment(False, False, 0, 0, 65535, "max-channel")], - [Frame(FIRST_FRM | LAST_FRM, 0, 0, 65535, "max-channel")]) + self.enc_dec([Segment(False, False, 0, 0, 65535, b"max-channel")], + [Frame(FIRST_FRM | LAST_FRM, 0, 0, 65535, b"max-channel")]) def testMaxType(self): - self.enc_dec([Segment(False, False, 255, 0, 0, "max-type")], - [Frame(FIRST_FRM | LAST_FRM, 255, 0, 0, "max-type")]) + self.enc_dec([Segment(False, False, 255, 0, 0, b"max-type")], + [Frame(FIRST_FRM | LAST_FRM, 255, 0, 0, b"max-type")]) def testMaxTrack(self): - self.enc_dec([Segment(False, False, 0, 15, 0, "max-track")], - [Frame(FIRST_FRM | LAST_FRM, 0, 15, 0, "max-track")]) + self.enc_dec([Segment(False, False, 0, 15, 0, b"max-track")], + [Frame(FIRST_FRM | LAST_FRM, 0, 15, 0, b"max-track")]) def testSequence(self): - self.enc_dec([Segment(True, False, 0, 0, 0, "one"), - Segment(False, False, 0, 0, 0, "two"), - Segment(False, True, 0, 0, 0, "three")], - [Frame(FIRST_FRM | LAST_FRM | FIRST_SEG, 0, 0, 0, "one"), - Frame(FIRST_FRM | LAST_FRM, 0, 0, 0, "two"), - Frame(FIRST_FRM | LAST_FRM | LAST_SEG, 0, 0, 0, "three")]) + self.enc_dec([Segment(True, False, 0, 0, 0, b"one"), + Segment(False, False, 0, 0, 0, b"two"), + Segment(False, True, 0, 0, 0, b"three")], + [Frame(FIRST_FRM | LAST_FRM | FIRST_SEG, 0, 0, 0, b"one"), + Frame(FIRST_FRM | LAST_FRM, 0, 0, 0, b"two"), + Frame(FIRST_FRM | LAST_FRM | LAST_SEG, 0, 0, 0, b"three")]) def testInterleaveChannel(self): - frames = [Frame(0, 0, 0, 0, chr(ord("a") + i)) for i in range(7)] + frames = [Frame(0, 0, 0, 0, b'%c' % (ord("a") + i,)) for i in range(7)] frames[0].flags |= FIRST_FRM frames[-1].flags |= LAST_FRM - ilvd = [Frame(0, 0, 0, 1, chr(ord("a") + i)) for i in range(7)] + ilvd = [Frame(0, 0, 0, 1, b'%c' % (ord("a") + i,)) for i in range(7)] - self.enc_dec([Segment(False, False, 0, 0, 0, "abcdefg")], frames, ilvd, max_payload=1) + self.enc_dec([Segment(False, False, 0, 0, 0, b"abcdefg")], frames, ilvd, max_payload=1) def testInterleaveTrack(self): - frames = [Frame(0, 0, 0, 0, "%c%c" % (ord("a") + i, ord("a") + i + 1)) + frames = [Frame(0, 0, 0, 0, b"%c%c" % (ord("a") + i, ord("a") + i + 1)) for i in range(0, 8, 2)] frames[0].flags |= FIRST_FRM frames[-1].flags |= LAST_FRM - ilvd = [Frame(0, 0, 1, 0, "%c%c" % (ord("a") + i, ord("a") + i + 1)) + ilvd = [Frame(0, 0, 1, 0, b"%c%c" % (ord("a") + i, ord("a") + i + 1)) for i in range(0, 8, 2)] - self.enc_dec([Segment(False, False, 0, 0, 0, "abcdefgh")], frames, ilvd, max_payload=2) + self.enc_dec([Segment(False, False, 0, 0, 0, b"abcdefgh")], frames, ilvd, max_payload=2) from qpid.ops import * @@ -245,46 +245,46 @@ class OpTest(Base): self.enc_dec([MessageTransfer(destination="asdf", sync=True)]) def testEmptyPayloadMT(self): - self.enc_dec([MessageTransfer(payload="")]) + self.enc_dec([MessageTransfer(payload=b"")]) def testPayloadMT(self): - self.enc_dec([MessageTransfer(payload="test payload")]) + self.enc_dec([MessageTransfer(payload=b"test payload")]) def testHeadersEmptyPayloadMT(self): self.enc_dec([MessageTransfer(headers=[DeliveryProperties()])]) def testHeadersPayloadMT(self): - self.enc_dec([MessageTransfer(headers=[DeliveryProperties()], payload="test payload")]) + self.enc_dec([MessageTransfer(headers=[DeliveryProperties()], payload=b"test payload")]) def testMultiHeadersEmptyPayloadMT(self): self.enc_dec([MessageTransfer(headers=[DeliveryProperties(), MessageProperties()])]) def testMultiHeadersPayloadMT(self): - self.enc_dec([MessageTransfer(headers=[MessageProperties(), DeliveryProperties()], payload="test payload")]) + self.enc_dec([MessageTransfer(headers=[MessageProperties(), DeliveryProperties()], payload=b"test payload")]) def testContentTypeHeadersPayloadMT(self): - self.enc_dec([MessageTransfer(headers=[MessageProperties(content_type="text/plain")], payload="test payload")]) + self.enc_dec([MessageTransfer(headers=[MessageProperties(content_type="text/plain")], payload=b"test payload")]) def testMulti(self): self.enc_dec([MessageTransfer(), MessageTransfer(sync=True), MessageTransfer(destination="one"), MessageTransfer(destination="two", sync=True), - MessageTransfer(destination="three", payload="test payload")]) + MessageTransfer(destination="three", payload=b"test payload")]) def testControl(self): - self.enc_dec([SessionAttach(name="asdf")]) + self.enc_dec([SessionAttach(name=b"asdf")]) def testMixed(self): - self.enc_dec([SessionAttach(name="fdsa"), MessageTransfer(destination="test")]) + self.enc_dec([SessionAttach(name=b"fdsa"), MessageTransfer(destination="test")]) def testChannel(self): - self.enc_dec([SessionAttach(name="asdf", channel=3), MessageTransfer(destination="test", channel=1)]) + self.enc_dec([SessionAttach(name=b"asdf", channel=3), MessageTransfer(destination="test", channel=1)]) def testCompound(self): self.enc_dec([MessageTransfer(headers=[MessageProperties(reply_to=ReplyTo(exchange="exch", routing_key="rk"))])]) def testListCompound(self): - self.enc_dec([ExecutionResult(value=RecoverResult(in_doubt=[Xid(global_id="one"), - Xid(global_id="two"), - Xid(global_id="three")]))]) + self.enc_dec([ExecutionResult(value=RecoverResult(in_doubt=[Xid(global_id=b"one"), + Xid(global_id=b"two"), + Xid(global_id=b"three")]))]) diff --git a/qpid/tests/messaging/message.py b/qpid/tests/messaging/message.py index ee5b56e..ed6604d 100644 --- a/qpid/tests/messaging/message.py +++ b/qpid/tests/messaging/message.py @@ -25,8 +25,8 @@ from qpid.tests.messaging import Base class MessageTests(Base): def testCreateString(self): - m = Message("string") - assert m.content == "string" + m = Message(b"string") + assert m.content == b"string" assert m.content_type is None def testCreateUnicode(self): @@ -79,7 +79,7 @@ class MessageEchoTests(Base): self.check(Message(u"unicode")) - TEST_MAP = {"key1": "string", + TEST_MAP = {"key1": b"string", "key2": u"unicode", "key3": 3, "key4": -3, @@ -90,7 +90,7 @@ class MessageEchoTests(Base): "key9": {"sub-key0": 3}, "key10": True, "key11": False, - "x-amqp-0-10.app-id": "test-app-id", + "x-amqp-0-10.app-id": b"test-app-id", "x-amqp-0-10.content-encoding": "test-content-encoding"} def testMapContent(self): @@ -104,7 +104,7 @@ class MessageEchoTests(Base): def testProperties(self): msg = Message() msg.subject = "subject" - msg.correlation_id = str(self.test_id) + msg.correlation_id = str(self.test_id).encode() msg.durable = True msg.priority = 7 msg.ttl = 60 diff --git a/qpid/tests/spec010.py b/qpid/tests/spec010.py index cce8ca3..f662d7b 100644 --- a/qpid/tests/spec010.py +++ b/qpid/tests/spec010.py @@ -28,11 +28,11 @@ class SpecTest(TestCase): def testSessionHeader(self): sc = StringCodec() sc.write_compound(Header(sync=True)) - assert sc.encoded == "\x01\x01" + assert sc.encoded == b"\x01\x01" sc = StringCodec() sc.write_compound(Header(sync=False)) - assert sc.encoded == "\x01\x00" + assert sc.encoded == b"\x01\x00" def encdec(self, value): sc = StringCodec() @@ -57,9 +57,9 @@ class SpecTest(TestCase): def testXid(self): sc = StringCodec() - xid = Xid(format=0, global_id="gid", branch_id="bid") + xid = Xid(format=0, global_id=b"gid", branch_id=b"bid") sc.write_compound(xid) - assert sc.encoded == '\x00\x00\x00\x10\x06\x04\x07\x00\x00\x00\x00\x00\x03gid\x03bid' + assert sc.encoded == b'\x00\x00\x00\x10\x06\x04\x07\x00\x00\x00\x00\x00\x03gid\x03bid' dec = sc.read_compound(Xid) assert xid.__dict__ == dec.__dict__ diff --git a/qpid_tests/broker_0_9/echo.py b/qpid_tests/broker_0_9/echo.py index b8b5535..6391d33 100644 --- a/qpid_tests/broker_0_9/echo.py +++ b/qpid_tests/broker_0_9/echo.py @@ -33,7 +33,7 @@ class EchoTests(TestBase): self.assertTrue(self.frame_max_size >= self.client.conn.FRAME_MIN_SIZE) def test_empty_message(self): - body = '' + body = b'' self.echo_message(body) def test_small_message(self): --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org