Skip to content

Commit 6386127

Browse files
committed
Refactoring modules
1 parent 2c99079 commit 6386127

26 files changed

+373
-439
lines changed

examples/test_examples.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from unittest import skip, skipUnless
2323

2424
from neo4j.v1 import TRUST_ON_FIRST_USE, TRUST_SIGNED_CERTIFICATES, SSL_AVAILABLE
25-
from neo4j.v1.exceptions import CypherError
25+
from neo4j.v1.session import CypherError
2626
from test.util import ServerTestCase
2727

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

neo4j/__main__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from sys import stdout, stderr
2828

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

3233

3334
def main():

neo4j/v1/constants.py renamed to neo4j/bolt/__init__.py

+2-28
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,5 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21-
22-
from os.path import expanduser, join
23-
24-
from .compat.ssl import SSL_AVAILABLE
25-
from ..meta import version
26-
27-
28-
DEFAULT_PORT = 7687
29-
DEFAULT_USER_AGENT = "neo4j-python/%s" % version
30-
31-
KNOWN_HOSTS = join(expanduser("~"), ".neo4j", "known_hosts")
32-
33-
MAGIC_PREAMBLE = 0x6060B017
34-
35-
ENCRYPTION_OFF = 0
36-
ENCRYPTION_ON = 1
37-
ENCRYPTION_DEFAULT = ENCRYPTION_ON if SSL_AVAILABLE else ENCRYPTION_OFF
38-
39-
TRUST_ON_FIRST_USE = 0 # Deprecated
40-
TRUST_SIGNED_CERTIFICATES = 1 # Deprecated
41-
TRUST_ALL_CERTIFICATES = 2
42-
TRUST_CUSTOM_CA_SIGNED_CERTIFICATES = 3
43-
TRUST_SYSTEM_CA_SIGNED_CERTIFICATES = 4
44-
TRUST_DEFAULT = TRUST_ALL_CERTIFICATES
45-
46-
READ_ACCESS = "READ"
47-
WRITE_ACCESS = "WRITE"
48-
ACCESS_DEFAULT = WRITE_ACCESS
21+
from .connection import *
22+
from .packstream import *

neo4j/v1/bolt.py renamed to neo4j/bolt/connection.py

+28-5
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,30 @@
2727

2828
from __future__ import division
2929

30+
import logging
3031
from base64 import b64encode
3132
from collections import deque, namedtuple
3233
from io import BytesIO
33-
import logging
3434
from os import makedirs, open as os_open, write as os_write, close as os_close, O_CREAT, O_APPEND, O_WRONLY
35-
from os.path import dirname, isfile
35+
from os.path import dirname, isfile, join as path_join, expanduser
3636
from select import select
3737
from socket import create_connection, SHUT_RDWR, error as SocketError
3838
from struct import pack as struct_pack, unpack as struct_unpack
3939
from threading import RLock
4040

41-
from .compat.ssl import SSL_AVAILABLE, HAS_SNI, SSLError
42-
from .constants import DEFAULT_USER_AGENT, KNOWN_HOSTS, MAGIC_PREAMBLE, TRUST_DEFAULT, TRUST_ON_FIRST_USE
43-
from .exceptions import ProtocolError, Unauthorized, ServiceUnavailable
41+
from neo4j.compat.ssl import SSL_AVAILABLE, HAS_SNI, SSLError
42+
from neo4j.meta import version
4443
from .packstream import Packer, Unpacker
4544

4645

46+
DEFAULT_PORT = 7687
47+
DEFAULT_USER_AGENT = "neo4j-python/%s" % version
48+
49+
KNOWN_HOSTS = path_join(expanduser("~"), ".neo4j", "known_hosts")
50+
51+
MAGIC_PREAMBLE = 0x6060B017
52+
53+
4754
# Signature bytes for each message type
4855
INIT = b"\x01" # 0000 0001 // INIT <user_agent> <auth>
4956
ACK_FAILURE = b"\x0E" # 0000 1110 // ACK_FAILURE
@@ -544,6 +551,7 @@ def connect(address, ssl_context=None, **config):
544551
error.__cause__ = cause
545552
raise error
546553
else:
554+
from neo4j.v1 import TRUST_DEFAULT, TRUST_ON_FIRST_USE
547555
# Check that the server provides a certificate
548556
der_encoded_server_certificate = s.getpeercert(binary_form=True)
549557
if der_encoded_server_certificate is None:
@@ -598,3 +606,18 @@ def connect(address, ssl_context=None, **config):
598606
else:
599607
log_error("S: [CLOSE]")
600608
raise ProtocolError("Unknown Bolt protocol version: %d", agreed_version)
609+
610+
611+
class ServiceUnavailable(Exception):
612+
""" Raised when no database service is available.
613+
"""
614+
615+
616+
class ProtocolError(Exception):
617+
""" Raised when an unexpected or unsupported protocol event occurs.
618+
"""
619+
620+
621+
class Unauthorized(Exception):
622+
""" Raised when an action is not permitted.
623+
"""
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

neo4j/util.py

-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
# limitations under the License.
2020

2121

22-
try:
23-
from collections.abc import MutableSet
24-
except ImportError:
25-
from collections import MutableSet, OrderedDict
26-
else:
27-
from collections import OrderedDict
2822
import logging
2923
from sys import stdout
3024

neo4j/v1/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21-
from .constants import *
22-
from .exceptions import *
21+
from .driver import *
2322
from .session import *
2423
from .types import *

0 commit comments

Comments
 (0)