Skip to content

Commit 3b7c4b3

Browse files
authored
Merge pull request #115 from technige/ext-refactoring
Refactoring for extensions
2 parents c592437 + 5cb50d4 commit 3b7c4b3

File tree

15 files changed

+976
-813
lines changed

15 files changed

+976
-813
lines changed

examples/test_examples.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
from unittest import skip, skipUnless
2323

24-
from neo4j.v1 import TRUST_ON_FIRST_USE, TRUST_SIGNED_CERTIFICATES, SSL_AVAILABLE
25-
from neo4j.v1.session import CypherError
24+
from neo4j.v1 import TRUST_ON_FIRST_USE, TRUST_SIGNED_CERTIFICATES, SSL_AVAILABLE, CypherError
2625
from test.util import ServerTestCase
2726

2827
# Do not change the contents of this tagged section without good reason*

neo4j/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
from sys import stdout, stderr
2828

2929
from .util import Watcher
30-
from .v1.session import GraphDatabase, basic_auth
31-
from neo4j.v1.session import CypherError
30+
from .v1 import GraphDatabase, CypherError
3231

3332

3433
def main():
@@ -60,7 +59,7 @@ def main():
6059
except ValueError:
6160
parameters[name] = value
6261

63-
driver = GraphDatabase.driver(args.url, auth=basic_auth(args.user, args.password))
62+
driver = GraphDatabase.driver(args.url, auth=(args.user, args.password))
6463
session = driver.session()
6564
for _ in range(args.times):
6665
for statement in args.statement:

neo4j/bolt/connection.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,17 @@ def __init__(self, sock, **config):
269269
self.user_agent = user_agent
270270

271271
# Determine auth details
272-
try:
273-
self.auth_dict = vars(config["auth"])
274-
except (KeyError, TypeError):
272+
auth = config.get("auth")
273+
if not auth:
275274
self.auth_dict = {}
275+
elif isinstance(auth, tuple) and 2 <= len(auth) <= 3:
276+
from neo4j.v1 import basic_auth
277+
self.auth_dict = vars(basic_auth(*auth))
278+
else:
279+
try:
280+
self.auth_dict = vars(config["auth"])
281+
except (KeyError, TypeError):
282+
raise TypeError("Cannot determine auth details from %r" % auth)
276283

277284
# Pick up the server certificate, if any
278285
self.der_encoded_server_certificate = config.get("der_encoded_server_certificate")
@@ -400,10 +407,12 @@ def sync(self):
400407
""" Send and fetch all outstanding messages.
401408
"""
402409
self.send()
410+
count = 0
403411
while self.responses:
404412
response = self.responses[0]
405413
while not response.complete:
406-
self.fetch()
414+
count += self.fetch()
415+
return count
407416

408417
def close(self):
409418
""" Close the connection.
@@ -542,7 +551,7 @@ def connect(address, ssl_context=None, **config):
542551
try:
543552
s = create_connection(address)
544553
except SocketError as error:
545-
if error.errno == 111 or error.errno == 61 or error.errno == 10061:
554+
if error.errno in (61, 111, 10061):
546555
raise ServiceUnavailable("Failed to establish connection to %r" % (address,))
547556
else:
548557
raise

neo4j/v1/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21-
from .driver import *
22-
from .session import *
21+
from .api import *
22+
from .bolt import *
23+
from .security import *
2324
from .types import *

0 commit comments

Comments
 (0)