11# For the moment this is just a Connection pooler to keep compatibility with other clients
2+ import copy
23import logging
34from typing import Annotated , Callable , Optional , TypeVar
45
@@ -23,46 +24,52 @@ class Environment:
2324 _connections (list[Connection]): List of active connections managed by this environment
2425 """
2526
26- def __init__ (self ): # type: ignore
27+ def __init__ (
28+ self , # single-node mode
29+ uri : Optional [str ] = None ,
30+ # multi-node mode
31+ uris : Optional [list [str ]] = None ,
32+ ssl_context : Optional [SslConfigurationContext ] = None ,
33+ on_disconnection_handler : Optional [CB ] = None , # type: ignore
34+ ):
2735 """
2836 Initialize a new Environment instance.
2937
3038 Creates an empty list to track active connections.
39+
40+ Args:
41+ uri: Single node connection URI
42+ uris: List of URIs for multi-node setup
43+ ssl_context: SSL configuration for secure connections
44+ on_disconnection_handler: Callback for handling disconnection events
45+
3146 """
47+ self ._uri = uri
48+ self ._uris = uris
49+ self ._ssl_context = ssl_context
50+ self ._on_disconnection_handler = on_disconnection_handler
3251 self ._connections : list [Connection ] = []
3352
3453 def connection (
3554 self ,
36- # single-node mode
37- uri : Optional [str ] = None ,
38- # multi-node mode
39- uris : Optional [list [str ]] = None ,
40- ssl_context : Optional [SslConfigurationContext ] = None ,
41- on_disconnection_handler : Optional [CB ] = None , # type: ignore
4255 ) -> Connection :
4356 """
4457 Create and return a new connection.
4558
4659 This method supports both single-node and multi-node configurations, with optional
4760 SSL/TLS security and disconnection handling.
4861
49- Args:
50- uri: Single node connection URI
51- uris: List of URIs for multi-node setup
52- ssl_context: SSL configuration for secure connections
53- on_disconnection_handler: Callback for handling disconnection events
54-
5562 Returns:
5663 Connection: A new connection instance
5764
5865 Raises:
5966 ValueError: If neither uri nor uris is provided
6067 """
6168 connection = Connection (
62- uri = uri ,
63- uris = uris ,
64- ssl_context = ssl_context ,
65- on_disconnection_handler = on_disconnection_handler ,
69+ uri = self . _uri ,
70+ uris = self . _uris ,
71+ ssl_context = copy . deepcopy ( self . _ssl_context ) ,
72+ on_disconnection_handler = copy . deepcopy ( self . _on_disconnection_handler ) ,
6673 )
6774 logger .debug ("Environment: Creating and returning a new connection" )
6875 self ._connections .append (connection )
0 commit comments