Skip to content

Commit dd40433

Browse files
Added class-method get_handshake
The Bolt.get_handshake() returns bytes that is used in the version negotiation.
1 parent 5ba362d commit dd40433

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

neo4j/io/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ class Bolt:
9494

9595
PROTOCOL_VERSION = None
9696

97+
@classmethod
98+
def get_handshake(cls):
99+
""" Return the supported Bolt versions as bytes.
100+
The length is 16 bytes as specified in the Bolt version negotiation.
101+
:return: bytes
102+
"""
103+
offered_versions = sorted(cls.protocol_handlers().keys(), reverse=True)[:4]
104+
return b"".join(version.to_bytes() for version in offered_versions).ljust(16, b"\x00")
105+
97106
@classmethod
98107
def protocol_handlers(cls, protocol_version=None):
99108
""" Return a dictionary of available Bolt protocol handlers,

tests/unit/io/test_class_bolt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ def test_class_method_protocol_handlers_with_invalid_protocol_version():
4848
# python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_class_method_protocol_handlers_with_invalid_protocol_version
4949
with pytest.raises(TypeError):
5050
Bolt.protocol_handlers(protocol_version=2)
51+
52+
53+
def test_class_method_get_handshake():
54+
# python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_class_method_get_handshake
55+
handshake = Bolt.get_handshake()
56+
assert handshake == b"\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00"

0 commit comments

Comments
 (0)