|
39 | 39 | from neo4j.bolt.response import InitResponse, AckFailureResponse, ResetResponse |
40 | 40 | from neo4j.compat.ssl import SSL_AVAILABLE, HAS_SNI, SSLError |
41 | 41 | from neo4j.exceptions import ClientError, ProtocolError, SecurityError, ServiceUnavailable |
42 | | -from neo4j.meta import version |
43 | 42 | from neo4j.packstream import Packer, Unpacker |
44 | 43 | from neo4j.util import import_best as _import_best |
45 | 44 | from time import clock |
| 45 | +from neo4j.config import default_config |
46 | 46 |
|
47 | 47 | ChunkedInputBuffer = _import_best("neo4j.bolt._io", "neo4j.bolt.io").ChunkedInputBuffer |
48 | 48 | ChunkedOutputBuffer = _import_best("neo4j.bolt._io", "neo4j.bolt.io").ChunkedOutputBuffer |
49 | 49 |
|
50 | | - |
51 | | -INFINITE = -1 |
52 | | -DEFAULT_MAX_CONNECTION_LIFETIME = INFINITE |
53 | | -DEFAULT_MAX_CONNECTION_POOL_SIZE = 250 |
54 | | -DEFAULT_CONNECTION_TIMEOUT = 5.0 |
55 | | -DEFAULT_CONNECTION_ACQUISITION_TIMEOUT = 60 |
56 | 50 | DEFAULT_PORT = 7687 |
57 | | -DEFAULT_USER_AGENT = "neo4j-python/%s" % version |
58 | | - |
59 | 51 | MAGIC_PREAMBLE = 0x6060B017 |
60 | 52 |
|
61 | 53 |
|
@@ -183,11 +175,11 @@ def __init__(self, address, sock, error_handler, **config): |
183 | 175 | self.packer = Packer(self.output_buffer) |
184 | 176 | self.unpacker = Unpacker() |
185 | 177 | self.responses = deque() |
186 | | - self._max_connection_lifetime = config.get("max_connection_lifetime", DEFAULT_MAX_CONNECTION_LIFETIME) |
| 178 | + self._max_connection_lifetime = config.get("max_connection_lifetime", default_config["max_connection_lifetime"]) |
187 | 179 | self._creation_timestamp = clock() |
188 | 180 |
|
189 | 181 | # Determine the user agent and ensure it is a Unicode value |
190 | | - user_agent = config.get("user_agent", DEFAULT_USER_AGENT) |
| 182 | + user_agent = config.get("user_agent", default_config["user_agent"]) |
191 | 183 | if isinstance(user_agent, bytes): |
192 | 184 | user_agent = user_agent.decode("UTF-8") |
193 | 185 | self.user_agent = user_agent |
@@ -413,8 +405,8 @@ def __init__(self, connector, connection_error_handler, **config): |
413 | 405 | self.connections = {} |
414 | 406 | self.lock = RLock() |
415 | 407 | self.cond = Condition(self.lock) |
416 | | - self._max_connection_pool_size = config.get("max_connection_pool_size", DEFAULT_MAX_CONNECTION_POOL_SIZE) |
417 | | - self._connection_acquisition_timeout = config.get("connection_acquisition_timeout", DEFAULT_CONNECTION_ACQUISITION_TIMEOUT) |
| 408 | + self._max_connection_pool_size = config.get("max_connection_pool_size", default_config["max_connection_pool_size"]) |
| 409 | + self._connection_acquisition_timeout = config.get("connection_acquisition_timeout", default_config["connection_acquisition_timeout"]) |
418 | 410 |
|
419 | 411 | def __enter__(self): |
420 | 412 | return self |
@@ -546,10 +538,10 @@ def connect(address, ssl_context=None, error_handler=None, **config): |
546 | 538 | else: |
547 | 539 | raise ValueError("Unsupported address {!r}".format(address)) |
548 | 540 | t = s.gettimeout() |
549 | | - s.settimeout(config.get("connection_timeout", DEFAULT_CONNECTION_TIMEOUT)) |
| 541 | + s.settimeout(config.get("connection_timeout", default_config["connection_timeout"])) |
550 | 542 | s.connect(address) |
551 | 543 | s.settimeout(t) |
552 | | - s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1 if config.get("keep_alive", True) else 0) |
| 544 | + s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1 if config.get("keep_alive", default_config["keep_alive"]) else 0) |
553 | 545 | except SocketTimeout: |
554 | 546 | if s: |
555 | 547 | try: |
@@ -589,7 +581,7 @@ def connect(address, ssl_context=None, error_handler=None, **config): |
589 | 581 | s.close() |
590 | 582 | raise ProtocolError("When using a secure socket, the server should always " |
591 | 583 | "provide a certificate") |
592 | | - trust = config.get("trust", TRUST_DEFAULT) |
| 584 | + trust = config.get("trust", default_config["trust"]) |
593 | 585 | if trust == TRUST_ON_FIRST_USE: |
594 | 586 | from neo4j.bolt.cert import PersonalCertificateStore |
595 | 587 | store = PersonalCertificateStore() |
|
0 commit comments