From 38ab0128645f8438209bfc79edb8ff2172d1a84c Mon Sep 17 00:00:00 2001 From: Dag Odenhall Date: Fri, 9 Sep 2011 18:27:40 +0200 Subject: [PATCH] ZODBConnector -> _ZODBState and private --- docs/index.rst | 3 --- flaskext/zodb.py | 14 +++++++------- tests.py | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 5f4e45e..1ae4fa5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -181,9 +181,6 @@ API Reference .. autoclass:: ZODB :members: -.. autoclass:: ZODBConnector - :members: - Persistent Objects """""""""""""""""" diff --git a/flaskext/zodb.py b/flaskext/zodb.py index 87f841a..dab4bae 100644 --- a/flaskext/zodb.py +++ b/flaskext/zodb.py @@ -5,7 +5,7 @@ from UserDict import IterableUserDict from ZODB.DB import DB from contextlib import contextmanager, closing -from werkzeug import cached_property +from werkzeug.utils import cached_property from BTrees.OOBTree import OOBTree as BTree from persistent import Persistent as Object @@ -13,7 +13,7 @@ from persistent.mapping import PersistentMapping as Dict -__all__ = ['ZODB', 'ZODBConnector', 'Object', 'List', 'Dict', 'BTree'] +__all__ = ['ZODB', 'Object', 'List', 'Dict', 'BTree'] class ZODB(IterableUserDict): @@ -42,7 +42,7 @@ def init_app(self, app): """Configure a Flask application to use this ZODB extension.""" assert 'zodb' not in app.extensions, \ 'app already initiated for zodb' - app.extensions['zodb'] = ZODBConnector(self, app) + app.extensions['zodb'] = _ZODBState(self, app) app.teardown_request(self.close_db) def close_db(self, exception): @@ -91,14 +91,14 @@ def data(self): return self.connection.root() -class ZODBConnector(object): +class _ZODBState(object): """Adds a ZODB connection pool to a Flask application.""" - def __init__(self, ext, app): - self.ext = ext + def __init__(self, zodb, app): + self.zodb = zodb self.app = app @cached_property def db(self): """Connection pool.""" - return self.ext.create_db(self.app) + return self.zodb.create_db(self.app) diff --git a/tests.py b/tests.py index 037e56c..e27fd0a 100644 --- a/tests.py +++ b/tests.py @@ -29,8 +29,8 @@ def pytest_generate_tests(metafunc): def test_single_app_shortcut(): app = Flask(__name__) - ext = ZODB(app) - assert app.extensions['zodb'].ext is ext + zodb = ZODB(app) + assert app.extensions['zodb'].zodb is zodb def test_connection(app):