Skip to content

Commit e58ed7e

Browse files
Changed MAGIC_PREAMBLE to be bytes
This is to align with aio.
1 parent dd40433 commit e58ed7e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

neo4j/io/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Bolt:
9090
the handshake was carried out.
9191
"""
9292

93-
MAGIC_PREAMBLE = 0x6060B017
93+
MAGIC_PREAMBLE = b"\x60\x60\xB0\x17"
9494

9595
PROTOCOL_VERSION = None
9696

@@ -804,8 +804,8 @@ def _handshake(s, resolved_address):
804804

805805
# Send details of the protocol versions supported
806806
supported_versions = [3, 0, 0, 0]
807-
handshake = [Bolt.MAGIC_PREAMBLE] + supported_versions
808-
log.debug("[#%04X] C: <MAGIC> 0x%08X", local_port, Bolt.MAGIC_PREAMBLE)
807+
handshake = [int.from_bytes(Bolt.MAGIC_PREAMBLE, byteorder="big")] + supported_versions
808+
log.debug("[#%04X] C: <MAGIC> 0x%08X", local_port, int.from_bytes(Bolt.MAGIC_PREAMBLE, byteorder="big"))
809809
log.debug("[#%04X] C: <HANDSHAKE> 0x%08X 0x%08X 0x%08X 0x%08X", local_port, *supported_versions)
810810
data = b"".join(struct_pack(">I", num) for num in handshake)
811811
s.sendall(data)

tests/unit/io/test_class_bolt.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ def test_class_method_get_handshake():
5454
# python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_class_method_get_handshake
5555
handshake = Bolt.get_handshake()
5656
assert handshake == b"\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00"
57+
58+
59+
def test_magic_preamble():
60+
# python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_magic_preamble
61+
preamble = 0x6060B017
62+
preamble_bytes = preamble.to_bytes(4, byteorder="big")
63+
assert Bolt.MAGIC_PREAMBLE == preamble_bytes

0 commit comments

Comments
 (0)