30
30
]
31
31
32
32
from logging import getLogger
33
- from urllib .parse import (
34
- urlparse ,
35
- parse_qs ,
36
- )
33
+
37
34
38
35
from neo4j .addressing import (
39
36
Address ,
40
37
IPv4Address ,
41
38
IPv6Address ,
42
39
)
43
40
from neo4j .api import (
44
- Auth ,
41
+ Auth , # TODO: Validate naming for Auth compared to other drivers.
45
42
AuthToken ,
46
43
basic_auth ,
47
44
kerberos_auth ,
51
48
Version ,
52
49
READ_ACCESS ,
53
50
WRITE_ACCESS ,
51
+ SYSTEM_DATABASE ,
52
+ DEFAULT_DATABASE ,
53
+ TRUST_ALL_CERTIFICATES ,
54
+ TRUST_SYSTEM_CA_SIGNED_CERTIFICATES ,
54
55
)
55
56
from neo4j .conf import (
56
57
Config ,
57
58
PoolConfig ,
58
- TRUST_ALL_CERTIFICATES ,
59
- TRUST_SYSTEM_CA_SIGNED_CERTIFICATES ,
59
+ WorkspaceConfig ,
60
+ SessionConfig ,
60
61
)
61
62
from neo4j .meta import (
62
63
experimental ,
72
73
ResultSummary ,
73
74
Query ,
74
75
Session ,
75
- SessionConfig ,
76
76
unit_of_work ,
77
77
)
78
78
@@ -85,7 +85,7 @@ class GraphDatabase:
85
85
"""
86
86
87
87
@classmethod
88
- def driver (cls , uri , * , auth = None , acquire_timeout = None , ** config ):
88
+ def driver (cls , uri , * , auth = None , ** config ):
89
89
""" Create a Neo4j driver that uses socket I/O and thread-based
90
90
concurrency.
91
91
@@ -116,12 +116,12 @@ def driver(cls, uri, *, auth=None, acquire_timeout=None, **config):
116
116
**Settings:** Neo4jDriver with encryption (accepts only certificates signed by an certificate authority), full certificate checks.
117
117
118
118
:param auth:
119
- :param acquire_timeout: seconds
120
119
:param config: connection configuration settings
121
120
"""
122
121
123
122
from neo4j .api import (
124
123
parse_neo4j_uri ,
124
+ parse_routing_context ,
125
125
DRIVER_BOLT ,
126
126
DRIVER_NEO4j ,
127
127
SECURITY_TYPE_NOT_SECURE ,
@@ -173,60 +173,37 @@ def driver(cls, uri, *, auth=None, acquire_timeout=None, **config):
173
173
config ["trust" ] = TRUST_ALL_CERTIFICATES
174
174
175
175
if driver_type == DRIVER_BOLT :
176
- return cls .bolt_driver (parsed .netloc , auth = auth , acquire_timeout = acquire_timeout , ** config )
176
+ return cls .bolt_driver (parsed .netloc , auth = auth , ** config )
177
177
elif driver_type == DRIVER_NEO4j :
178
- rc = cls . _parse_routing_context (parsed .query )
179
- return cls .neo4j_driver (parsed .netloc , auth = auth , routing_context = rc , acquire_timeout = acquire_timeout , ** config )
178
+ routing_context = parse_routing_context (parsed .query )
179
+ return cls .neo4j_driver (parsed .netloc , auth = auth , routing_context = routing_context , ** config )
180
180
181
181
@classmethod
182
- def bolt_driver (cls , target , * , auth = None , acquire_timeout = None , ** config ):
182
+ def bolt_driver (cls , target , * , auth = None , ** config ):
183
183
""" Create a driver for direct Bolt server access that uses
184
184
socket I/O and thread-based concurrency.
185
185
"""
186
186
from neo4j ._exceptions import BoltHandshakeError , BoltSecurityError
187
187
188
188
try :
189
- return BoltDriver .open (target , auth = auth , acquire_timeout = acquire_timeout , ** config )
189
+ return BoltDriver .open (target , auth = auth , ** config )
190
190
except (BoltHandshakeError , BoltSecurityError ) as error :
191
191
from neo4j .exceptions import ServiceUnavailable
192
192
raise ServiceUnavailable (str (error )) from error
193
193
194
194
@classmethod
195
- def neo4j_driver (cls , * targets , auth = None , routing_context = None , acquire_timeout = None ,
196
- ** config ):
195
+ def neo4j_driver (cls , * targets , auth = None , routing_context = None , ** config ):
197
196
""" Create a driver for routing-capable Neo4j service access
198
197
that uses socket I/O and thread-based concurrency.
199
198
"""
200
199
from neo4j ._exceptions import BoltHandshakeError , BoltSecurityError
201
200
202
201
try :
203
- return Neo4jDriver .open (* targets , auth = auth , routing_context = routing_context , acquire_timeout = acquire_timeout , ** config )
202
+ return Neo4jDriver .open (* targets , auth = auth , routing_context = routing_context , ** config )
204
203
except (BoltHandshakeError , BoltSecurityError ) as error :
205
204
from neo4j .exceptions import ServiceUnavailable
206
205
raise ServiceUnavailable (str (error )) from error
207
206
208
- @classmethod
209
- def _parse_routing_context (cls , query ):
210
- """ Parse the query portion of a URI to generate a routing
211
- context dictionary.
212
- """
213
- if not query :
214
- return {}
215
-
216
- context = {}
217
- parameters = parse_qs (query , True )
218
- for key in parameters :
219
- value_list = parameters [key ]
220
- if len (value_list ) != 1 :
221
- raise ValueError ("Duplicated query parameters with key '%s', "
222
- "value '%s' found in query string '%s'" % (key , value_list , query ))
223
- value = value_list [0 ]
224
- if not value :
225
- raise ValueError ("Invalid parameters:'%s=%s' in query string "
226
- "'%s'." % (key , value , query ))
227
- context [key ] = value
228
- return context
229
-
230
207
231
208
class Direct :
232
209
@@ -303,7 +280,7 @@ def __exit__(self, exc_type, exc_value, traceback):
303
280
304
281
@property
305
282
def encrypted (self ):
306
- return bool (self ._pool .config .encrypted )
283
+ return bool (self ._pool .pool_config .encrypted )
307
284
308
285
def session (self , ** config ):
309
286
""" Create a simple session.
@@ -350,7 +327,6 @@ class BoltDriver(Direct, Driver):
350
327
@classmethod
351
328
def open (cls , target , * , auth = None , ** config ):
352
329
from neo4j .io import BoltPool
353
- from neo4j .work import WorkspaceConfig
354
330
address = cls .parse_target (target )
355
331
pool_config , default_workspace_config = Config .consume_chain (config , PoolConfig , WorkspaceConfig )
356
332
pool = BoltPool .open (address , auth = auth , ** pool_config )
@@ -362,15 +338,15 @@ def __init__(self, pool, default_workspace_config):
362
338
self ._default_workspace_config = default_workspace_config
363
339
364
340
def session (self , ** config ):
365
- from neo4j .work .simple import Session , SessionConfig
366
- session_config = SessionConfig (self ._default_workspace_config ,
367
- SessionConfig .consume (config ))
341
+ from neo4j .work .simple import Session
342
+ session_config = SessionConfig (self ._default_workspace_config , config )
343
+ SessionConfig .consume (config ) # Consume the config
368
344
return Session (self ._pool , session_config )
369
345
370
346
def pipeline (self , ** config ):
371
347
from neo4j .work .pipelining import Pipeline , PipelineConfig
372
- pipeline_config = PipelineConfig (self ._default_workspace_config ,
373
- PipelineConfig .consume (config ))
348
+ pipeline_config = PipelineConfig (self ._default_workspace_config , config )
349
+ PipelineConfig .consume (config ) # Consume the config
374
350
return Pipeline (self ._pool , pipeline_config )
375
351
376
352
def verify_connectivity (self , ** config ):
@@ -394,7 +370,6 @@ class Neo4jDriver(Routing, Driver):
394
370
@classmethod
395
371
def open (cls , * targets , auth = None , routing_context = None , ** config ):
396
372
from neo4j .io import Neo4jPool
397
- from neo4j .work import WorkspaceConfig
398
373
addresses = cls .parse_targets (* targets )
399
374
pool_config , default_workspace_config = Config .consume_chain (config , PoolConfig , WorkspaceConfig )
400
375
pool = Neo4jPool .open (* addresses , auth = auth , routing_context = routing_context , ** pool_config )
@@ -406,15 +381,15 @@ def __init__(self, pool, default_workspace_config):
406
381
self ._default_workspace_config = default_workspace_config
407
382
408
383
def session (self , ** config ):
409
- from neo4j .work .simple import Session , SessionConfig
410
- session_config = SessionConfig (self ._default_workspace_config ,
411
- SessionConfig .consume (config ))
384
+ from neo4j .work .simple import Session
385
+ session_config = SessionConfig (self ._default_workspace_config , config )
386
+ SessionConfig .consume (config ) # Consume the config
412
387
return Session (self ._pool , session_config )
413
388
414
389
def pipeline (self , ** config ):
415
390
from neo4j .work .pipelining import Pipeline , PipelineConfig
416
- pipeline_config = PipelineConfig (self ._default_workspace_config ,
417
- PipelineConfig .consume (config ))
391
+ pipeline_config = PipelineConfig (self ._default_workspace_config , config )
392
+ PipelineConfig .consume (config ) # Consume the config
418
393
return Pipeline (self ._pool , pipeline_config )
419
394
420
395
def get_routing_table (self ):
0 commit comments