2323from warnings import warn
2424
2525from neo4j .data import DataDehydrator
26- from neo4j .exceptions import (
27- Neo4jError ,
28- ServiceUnavailable ,
29- SessionExpired ,
30- )
26+ from neo4j .io import ConnectionErrorHandler
3127from neo4j .work .summary import ResultSummary
3228
3329
34- class _ConnectionErrorHandler :
35- """
36- Wrapper class for handling connection errors.
37-
38- The class will wrap each method to invoke a callback if the method raises
39- SessionExpired or ServiceUnavailable.
40- The error will be re-raised after the callback.
41- """
42-
43- def __init__ (self , connection , on_error ):
44- """
45- :param connection the connection object to warp
46- :type connection Bolt
47- :param on_error the function to be called when a method of
48- connection raises of of the caught errors.
49- :type on_error callable
50- """
51- self .connection = connection
52- self .on_error = on_error
53-
54- def __getattr__ (self , item ):
55- connection_attr = getattr (self .connection , item )
56- if not callable (connection_attr ):
57- return connection_attr
58-
59- def outer (func ):
60- def inner (* args , ** kwargs ):
61- try :
62- func (* args , ** kwargs )
63- except (Neo4jError , ServiceUnavailable , SessionExpired ) as exc :
64- self .on_error (exc )
65- raise
66- return inner
67-
68- return outer (connection_attr )
69-
70-
7130class Result :
7231 """A handler for the result of Cypher query execution. Instances
7332 of this class are typically constructed and returned by
@@ -76,7 +35,7 @@ class Result:
7635
7736 def __init__ (self , connection , hydrant , fetch_size , on_closed ,
7837 on_error ):
79- self ._connection = _ConnectionErrorHandler (connection , on_error )
38+ self ._connection = ConnectionErrorHandler (connection , on_error )
8039 self ._hydrant = hydrant
8140 self ._on_closed = on_closed
8241 self ._metadata = None
@@ -98,7 +57,7 @@ def __init__(self, connection, hydrant, fetch_size, on_closed,
9857
9958 @property
10059 def _qid (self ):
101- if self ._raw_qid == self ._connection .connection . most_recent_qid :
60+ if self ._raw_qid == self ._connection .most_recent_qid :
10261 return - 1
10362 else :
10463 return self ._raw_qid
@@ -127,7 +86,7 @@ def on_attached(metadata):
12786 # For auto-commit there is no qid and Bolt 3 does not support qid
12887 self ._raw_qid = metadata .get ("qid" , - 1 )
12988 if self ._raw_qid != - 1 :
130- self ._connection .connection . most_recent_qid = self ._raw_qid
89+ self ._connection .most_recent_qid = self ._raw_qid
13190 self ._keys = metadata .get ("fields" )
13291 self ._attached = True
13392
0 commit comments