From 3980ee276e158af6e86dc5c8e725d2a332e8bbee Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Sat, 4 May 2024 16:33:35 -0400 Subject: [PATCH] refactor: rename private helper for clarity Preserve original name ('_resolve_uri') as a BBB alias. --- zodburi/__init__.py | 9 ++++++--- zodburi/resolvers.py | 6 +++--- zodburi/tests/test___init__.py | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/zodburi/__init__.py b/zodburi/__init__.py index d9c7a7c..daf7522 100644 --- a/zodburi/__init__.py +++ b/zodburi/__init__.py @@ -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") @@ -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()) diff --git a/zodburi/resolvers.py b/zodburi/resolvers.py index 720fb93..faf882d 100644 --- a/zodburi/resolvers.py +++ b/zodburi/resolvers.py @@ -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 @@ -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') diff --git a/zodburi/tests/test___init__.py b/zodburi/tests/test___init__.py index 7a6915a..2204866 100644 --- a/zodburi/tests/test___init__.py +++ b/zodburi/tests/test___init__.py @@ -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