Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
- Remove deprecated exports from `neo4j`:
- `log`, `Config`, `PoolConfig`, `SessionConfig`, `WorkspaceConfig` (internal - no replacement)
- `SummaryNotificationPosition` (use `SummaryInputPosition` instead)
- `api.Version` has been removed as it's unused now.
- `api.Version` has been removed as it's unusedparse_target now.
`ServerInfo.protocol_version` now is a `tuple[int, int]` insteadof a `api.Version`.
This should be drop-in replacement is most cases:
- `Version` was a sup-type of `tuple[int, int]`
Expand Down Expand Up @@ -56,6 +56,16 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
If you were calling it directly, please use `Record.__getitem__(slice(...))` or simply `record[...]` instead.
- Remove deprecated class `neo4j.Bookmark` in favor of `neo4j.Bookmarks`.
- Remove deprecated class `session.last_bookmark()` in favor of `last_bookmarks()`.
- Remove undocumented internals
- `GraphDatabase`
- `.bolt_driver`
- `.neo4j_driver`
- `BoltDriver` and `Neo4jDriver`
- `.open`
- `.parse_target`
- `.default_host`
- `.default_port`
- `.default_target`


## Version 5.28
Expand Down
60 changes: 25 additions & 35 deletions src/neo4j/_async/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ def driver(
# 'Routing parameters are not supported with scheme '
# '"bolt". Given URI "{}".'.format(uri)
# )
return cls.bolt_driver(parsed.netloc, **config)
return cls._bolt_driver(parsed.netloc, **config)
# else driver_type == DRIVER_NEO4J
routing_context = parse_routing_context(parsed.query)
return cls.neo4j_driver(
return cls._neo4j_driver(
parsed.netloc, routing_context=routing_context, **config
)

Expand Down Expand Up @@ -404,7 +404,7 @@ def bookmark_manager(
)

@classmethod
def bolt_driver(cls, target, **config):
def _bolt_driver(cls, target, **config):
"""
Create a direct driver.

Expand All @@ -417,36 +417,28 @@ def bolt_driver(cls, target, **config):
)

try:
return AsyncBoltDriver.open(target, **config)
return AsyncBoltDriver._open(target, **config)
except (BoltHandshakeError, BoltSecurityError) as error:
from ..exceptions import ServiceUnavailable

raise ServiceUnavailable(str(error)) from error

@classmethod
def neo4j_driver(cls, *targets, routing_context=None, **config):
def _neo4j_driver(cls, target, routing_context=None, **config):
"""
Create a routing driver.

Create a driver for routing-capable Neo4j service access
that uses socket I/O and thread-based concurrency.
"""
# TODO: 6.0 - adjust signature to only take one target
if len(targets) > 1:
deprecation_warn(
"Creating a routing driver with multiple targets is "
"deprecated. The driver only uses the first target anyway. "
"The method signature will change in a future release.",
)

from .._exceptions import (
BoltHandshakeError,
BoltSecurityError,
)

try:
return AsyncNeo4jDriver.open(
*targets, routing_context=routing_context, **config
return AsyncNeo4jDriver._open(
target, routing_context=routing_context, **config
)
except (BoltHandshakeError, BoltSecurityError) as error:
from ..exceptions import ServiceUnavailable
Expand All @@ -455,10 +447,9 @@ def neo4j_driver(cls, *targets, routing_context=None, **config):


class _Direct:
# TODO: 6.0 - those attributes should be private
default_host = "localhost"
default_port = 7687
default_target = ":"
_default_host = "localhost"
_default_port = 7687
_default_target = ":"

def __init__(self, address):
self._address = address
Expand All @@ -468,22 +459,21 @@ def address(self):
return self._address

@classmethod
def parse_target(cls, target):
def _parse_target(cls, target):
"""Parse a target string to produce an address."""
if not target:
target = cls.default_target
target = cls._default_target
return Address.parse(
target,
default_host=cls.default_host,
default_port=cls.default_port,
default_host=cls._default_host,
default_port=cls._default_port,
)


class _Routing:
# TODO: 6.0 - those attributes should be private
default_host = "localhost"
default_port = 7687
default_targets = ": :17601 :17687"
_default_host = "localhost"
_default_port = 7687
_default_targets = ": :17601 :17687"

def __init__(self, initial_addresses):
self._initial_addresses = initial_addresses
Expand All @@ -493,15 +483,15 @@ def initial_addresses(self):
return self._initial_addresses

@classmethod
def parse_targets(cls, *targets):
def _parse_targets(cls, *targets):
"""Parse a sequence of target strings to produce an address list."""
targets = " ".join(targets)
if not targets:
targets = cls.default_targets
targets = cls._default_targets
return Address.parse_list(
targets,
default_host=cls.default_host,
default_port=cls.default_port,
default_host=cls._default_host,
default_port=cls._default_port,
)


Expand Down Expand Up @@ -1331,10 +1321,10 @@ class AsyncBoltDriver(_Direct, AsyncDriver):
"""

@classmethod
def open(cls, target, **config):
def _open(cls, target, **config):
from .io import AsyncBoltPool

address = cls.parse_target(target)
address = cls._parse_target(target)
pool_config, default_workspace_config = Config.consume_chain(
config, AsyncPoolConfig, WorkspaceConfig
)
Expand Down Expand Up @@ -1365,10 +1355,10 @@ class AsyncNeo4jDriver(_Routing, AsyncDriver):
"""

@classmethod
def open(cls, *targets, routing_context=None, **config):
def _open(cls, *targets, routing_context=None, **config):
from .io import AsyncNeo4jPool

addresses = cls.parse_targets(*targets)
addresses = cls._parse_targets(*targets)
pool_config, default_workspace_config = Config.consume_chain(
config, AsyncPoolConfig, WorkspaceConfig
)
Expand Down
60 changes: 25 additions & 35 deletions src/neo4j/_sync/driver.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/integration/examples/test_bearer_auth_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def __init__(self, uri, token):
def test_example(uri, mocker):
# Currently, there is no way of running the test against a server with SSO
# setup.
mocker.patch("neo4j.GraphDatabase.bolt_driver")
mocker.patch("neo4j.GraphDatabase.neo4j_driver")
mocker.patch("neo4j.GraphDatabase._bolt_driver")
mocker.patch("neo4j.GraphDatabase._neo4j_driver")

token = "myToken"
BearerAuthExample(uri, token)
calls = (
neo4j.GraphDatabase.bolt_driver.call_args_list
+ neo4j.GraphDatabase.neo4j_driver.call_args_list
neo4j.GraphDatabase._bolt_driver.call_args_list
+ neo4j.GraphDatabase._neo4j_driver.call_args_list
)
assert len(calls) == 1
_args, kwargs = calls[0]
Expand Down