3535 BoltError ,
3636 BoltHandshakeError ,
3737)
38+ from ..._io import BoltProtocolVersion
3839from ..._meta import USER_AGENT
3940from ..._sync .config import PoolConfig
4041from ...addressing import ResolvedAddress
41- from ...api import (
42- ServerInfo ,
43- Version ,
44- )
42+ from ...api import ServerInfo
4543from ...exceptions import (
4644 ConfigurationError ,
4745 DriverError ,
4846 IncompleteCommit ,
4947 ServiceUnavailable ,
5048 SessionExpired ,
49+ UnsupportedServerProduct ,
5150)
5251from ..config import AsyncPoolConfig
5352from ._bolt_socket import AsyncBoltSocket
@@ -109,7 +108,7 @@ class AsyncBolt:
109108
110109 MAGIC_PREAMBLE = b"\x60 \x60 \xb0 \x17 "
111110
112- PROTOCOL_VERSION : Version = None # type: ignore[assignment]
111+ PROTOCOL_VERSION : BoltProtocolVersion = None # type: ignore[assignment]
113112
114113 # flag if connection needs RESET to go back to READY state
115114 is_reset = False
@@ -159,7 +158,7 @@ def __init__(
159158 ResolvedAddress (
160159 sock .getpeername (), host_name = unresolved_address .host
161160 ),
162- self .PROTOCOL_VERSION ,
161+ self .PROTOCOL_VERSION . version ,
163162 )
164163 self .connection_hints = {}
165164 self .patch = {}
@@ -244,7 +243,7 @@ def assert_re_auth_support(self):
244243 if not self .supports_re_auth :
245244 raise ConfigurationError (
246245 "User switching is not supported for Bolt "
247- f"Protocol { self .PROTOCOL_VERSION !r } . Server Agent "
246+ f"Protocol { self .PROTOCOL_VERSION } . Server Agent "
248247 f"{ self .server_info .agent !r} "
249248 )
250249
@@ -257,11 +256,13 @@ def assert_notification_filtering_support(self):
257256 if not self .supports_notification_filtering :
258257 raise ConfigurationError (
259258 "Notification filtering is not supported for the Bolt "
260- f"Protocol { self .PROTOCOL_VERSION !r } . Server Agent "
259+ f"Protocol { self .PROTOCOL_VERSION } . Server Agent "
261260 f"{ self .server_info .agent !r} "
262261 )
263262
264- protocol_handlers : t .ClassVar [dict [Version , type [AsyncBolt ]]] = {}
263+ protocol_handlers : t .ClassVar [
264+ dict [BoltProtocolVersion , type [AsyncBolt ]]
265+ ] = {}
265266
266267 def __init_subclass__ (cls : type [te .Self ], ** kwargs : t .Any ) -> None :
267268 if cls .SKIP_REGISTRATION :
@@ -272,14 +273,10 @@ def __init_subclass__(cls: type[te.Self], **kwargs: t.Any) -> None:
272273 raise ValueError (
273274 "AsyncBolt subclasses must define PROTOCOL_VERSION"
274275 )
275- if not (
276- isinstance (protocol_version , Version )
277- and len (protocol_version ) == 2
278- and all (isinstance (i , int ) for i in protocol_version )
279- ):
276+ if not isinstance (protocol_version , BoltProtocolVersion ):
280277 raise TypeError (
281- "PROTOCOL_VERSION must be a 2-tuple of integers, not "
282- f"{ protocol_version !r } "
278+ "PROTOCOL_VERSION must be a BoltProtocolVersion, found "
279+ f"{ type ( protocol_version ) } for { cls . __name__ } "
283280 )
284281 if protocol_version in AsyncBolt .protocol_handlers :
285282 cls_conflict = AsyncBolt .protocol_handlers [protocol_version ]
@@ -336,16 +333,15 @@ async def ping(cls, address, *, deadline=None, pool_config=None):
336333 await AsyncBoltSocket .close_socket (s )
337334 return protocol_version
338335
339- @classmethod
336+ @staticmethod
340337 async def open (
341- cls ,
342338 address ,
343339 * ,
344340 auth_manager = None ,
345341 deadline = None ,
346342 routing_context = None ,
347343 pool_config = None ,
348- ):
344+ ) -> AsyncBolt :
349345 """
350346 Open a new Bolt connection to a given server address.
351347
@@ -366,7 +362,7 @@ async def open(
366362 if deadline is None :
367363 deadline = Deadline (None )
368364
369- s , protocol_version , handshake , data = await AsyncBoltSocket .connect (
365+ s , protocol_version = await AsyncBoltSocket .connect (
370366 address ,
371367 tcp_timeout = pool_config .connection_timeout ,
372368 deadline = deadline ,
@@ -381,15 +377,10 @@ async def open(
381377 if bolt_cls is None :
382378 log .debug ("[#%04X] C: <CLOSE>" , s .getsockname ()[1 ])
383379 await AsyncBoltSocket .close_socket (s )
384-
385- # TODO: 6.0 - raise public DriverError subclass instead
386- raise BoltHandshakeError (
380+ raise UnsupportedServerProduct (
387381 "The neo4j server does not support communication with this "
388382 "driver. This driver has support for Bolt protocols "
389- f"{ tuple (map (str , AsyncBolt .protocol_handlers .keys ()))} ." ,
390- address = address ,
391- request_data = handshake ,
392- response_data = data ,
383+ f"{ tuple (map (str , AsyncBolt .protocol_handlers ))} ." ,
393384 )
394385
395386 try :
0 commit comments