Skip to content

Commit

Permalink
ZODBConnector -> _ZODBState and private
Browse files Browse the repository at this point in the history
  • Loading branch information
dag committed Sep 9, 2011
1 parent b3610e2 commit 38ab012
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
3 changes: 0 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ API Reference
.. autoclass:: ZODB
:members:

.. autoclass:: ZODBConnector
:members:


Persistent Objects
""""""""""""""""""
Expand Down
14 changes: 7 additions & 7 deletions flaskext/zodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
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
from persistent.list import PersistentList as List
from persistent.mapping import PersistentMapping as Dict


__all__ = ['ZODB', 'ZODBConnector', 'Object', 'List', 'Dict', 'BTree']
__all__ = ['ZODB', 'Object', 'List', 'Dict', 'BTree']


class ZODB(IterableUserDict):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 38ab012

Please sign in to comment.