[Repoze-dev] Repoze CVS: root.py
Chris McDonough
chrism at agendaless.com
Thu Sep 13 15:33:28 UTC 2007
Update of /home/repoze/cvs/repoze.zope2/repoze/zope2
In directory laguna.palladion.com:/tmp/cvs-serv18088/repoze.zope2/repoze/zope2
Modified Files:
root.py
Log Message:
Provide a better API for registering callbacks that should be invoked
at transaction end.
Index: root.py
===================================================================
RCS file: /home/repoze/cvs/repoze.zope2/repoze/zope2/root.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- root.py 13 Sep 2007 05:47:52 -0000 1.1
+++ root.py 13 Sep 2007 15:33:26 -0000 1.2
@@ -1,4 +1,5 @@
from App.ZApplication import connection_open_hooks
+from repoze.tm import after_end
class Root:
""" A class which is much like App.ZApplication.ZApplicationWrapper,
@@ -12,7 +13,8 @@
"""
def __init__(self, db, name, txn):
- # we pass txn in for testability
+ # we pass txn in for testability, not because we couldn't just
+ # do "import transaction; transaction.commit()" here.
from OFS.Application import Application
conn = db.open()
root = conn.root()
@@ -30,12 +32,10 @@
for hook in connection_open_hooks:
hook(conn)
+ environ = REQUEST.environ
# close the connection when the txn ends
- closer = Closer(conn)
- cleanup = REQUEST.environ.setdefault('tm.cleanup', {})
- cleanup['closeconn'] = closer
-
- conn.setDebugInfo(REQUEST.environ, REQUEST.other)
+ after_end.register(conn.close, environ)
+ conn.setDebugInfo(environ, REQUEST.other)
return conn.root()[self._name]
@@ -46,15 +46,3 @@
return conn.root()[self._name]
-class Closer:
- def __init__(self, jar):
- self._jar = jar
-
- def __del__(self):
- try:
- self._jar.close()
- except:
- import traceback
- traceback.print_exc()
- raise
-
_______________________________________________
Repoze-dev mailing list
Repoze-dev at lists.repoze.org
http://lists.repoze.org/mailman/listinfo/repoze-dev
More information about the Repoze-dev
mailing list