Skip to content

Commit

Permalink
refactor: rename private helper for clarity
Browse files Browse the repository at this point in the history
Preserve original name ('_resolve_uri') as a BBB alias.
  • Loading branch information
tseaver committed May 4, 2024
1 parent efd44fb commit 3980ee2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions zodburi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def resolve_uri(uri):
returns a storage matching the spec defined in the uri. dbkw is a dict of
keyword arguments that may be passed to ZODB.DB.DB.
"""
factory, dbkw = _resolve_uri(uri)
factory, dbkw = _get_uri_factory_and_dbkw(uri)
return factory, _get_dbkw(dbkw)


# _resolve_uri serves resolve_uri: it returns factory and original raw dbkw.
def _resolve_uri(uri):
def _get_uri_factory_and_dbkw(uri):
"""Return factory and original raw dbkw for a URI."""
scheme = uri[:uri.find(":")]
try:
resolver_eps = entry_points(group="zodburi.resolvers")
Expand All @@ -76,6 +76,9 @@ def _resolve_uri(uri):
raise NoResolverForScheme(uri)


_resolve_uri = _get_uri_factory_and_dbkw # pragma: noqa BBB alias


def _parse_bytes(s):
m = HAS_UNITS_RE.match(s.lower())

Expand Down
6 changes: 3 additions & 3 deletions zodburi/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ZODB.FileStorage.FileStorage import FileStorage
from ZODB.MappingStorage import MappingStorage

from zodburi import _resolve_uri
from zodburi import _get_uri_factory_and_dbkw
from zodburi import CONNECTION_PARAMETERS
from zodburi.datatypes import convert_bytesize
from zodburi.datatypes import convert_int
Expand Down Expand Up @@ -236,12 +236,12 @@ def __call__(self, uri):
base_uri = m.group('base')
delta_uri = m.group('changes')

basef, base_dbkw = _resolve_uri(base_uri)
basef, base_dbkw = _get_uri_factory_and_dbkw(base_uri)

if base_dbkw:
raise InvalidDemoStorgeURI(uri, 'DB arguments in base')

deltaf, delta_dbkw = _resolve_uri(delta_uri)
deltaf, delta_dbkw = _get_uri_factory_and_dbkw(delta_uri)

if delta_dbkw:
raise InvalidDemoStorgeURI(uri, 'DB arguments in changes')
Expand Down
4 changes: 2 additions & 2 deletions zodburi/tests/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def test_resolve_uri_w_valid_scheme():
expected_factory = object()
expected_kw = {"database_name": "foo"}

with mock.patch("zodburi._resolve_uri") as ruri:
ruri.return_value = (expected_factory, expected_kw)
with mock.patch("zodburi._get_uri_factory_and_dbkw") as gufad:
gufad.return_value = (expected_factory, expected_kw)
factory, dbkw = zodburi.resolve_uri(valid)

assert factory is expected_factory
Expand Down

0 comments on commit 3980ee2

Please sign in to comment.