Verified Commit 25b8b921 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Change type of Macro.stage to int

In the same ways as Message.ident, using a bytes string with a length
of one would eventually cause issues.  It also maintains the ability to
set/compare the value to a Message.ident value.
parent bb8ac263
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -423,10 +423,10 @@ class Macro(Message, ident=b"D"):
	A message type for transferring symbol mappings prior to a stage event
	"""

	stage: bytes
	stage: int
	macros: Mapping[str, str]

	_struct = Struct("!c")
	_struct = Struct("!B")

	@classmethod
	def from_buffer(cls, buf: memoryview) -> Self:
+2 −2
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ class FilterProtocolTests(unittest.TestCase):
		# Prepare input messages
		buf = SimpleBuffer(100)
		Negotiate(6, ALL_ACTION_FLAGS, ALL_PROTOCOL_FLAGS).pack(buf)
		Macro(b"\x00", dict(spam="ham")).pack(buf)
		Macro(0, dict(spam="ham")).pack(buf)
		Connect("example.com", IPv4Address("10.1.1.1"), 11111).pack(buf)

		protocol = FilterProtocol()
@@ -96,7 +96,7 @@ class FilterProtocolTests(unittest.TestCase):
		# Prepare input messages
		buf = SimpleBuffer(100)
		Negotiate(6, ALL_ACTION_FLAGS, ALL_PROTOCOL_FLAGS).pack(buf)
		Macro(b"\x00", dict(spam="ham")).pack(buf)
		Macro(0, dict(spam="ham")).pack(buf)
		Connect("example.com", IPv4Address("10.1.1.1"), 11111).pack(buf)

		with self.assertRaises(UnexpectedMessage):
+6 −6
Original line number Diff line number Diff line
@@ -340,18 +340,18 @@ class MacroMessageTests(
		Return test values for generic message tests, appropriate for Macro
		"""
		yield (
			(b"C", {}), dict(),
			dict(stage=b"C", macros=dict()),
			(ord("C"), {}), dict(),
			dict(stage=ord("C"), macros=dict()),
			b"C",
		)
		yield (
			(b"H",), dict(macros=dict(spam="ham", eggs="green")),
			dict(stage=b"H", macros=dict(spam="ham", eggs="green")),
			(ord("H"),), dict(macros=dict(spam="ham", eggs="green")),
			dict(stage=ord("H"), macros=dict(spam="ham", eggs="green")),
			b"Hspam\x00ham\x00eggs\x00green\x00",
		)
		yield (
			tuple(), dict(stage=b"M", macros=dict(spam="ham", eggs="green")),
			dict(stage=b"M", macros=dict(spam="ham", eggs="green")),
			tuple(), dict(stage=ord("M"), macros=dict(spam="ham", eggs="green")),
			dict(stage=ord("M"), macros=dict(spam="ham", eggs="green")),
			b"Mspam\x00ham\x00eggs\x00green\x00",
		)