1 ### -*- coding: utf-8 -*- #################################################### |
|
2 ############################################################################## |
|
3 # |
|
4 # Copyright (c) 2008-2012 Thierry Florac <tflorac AT ulthar.net> |
|
5 # All Rights Reserved. |
|
6 # |
|
7 # This software is subject to the provisions of the Zope Public License, |
|
8 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
9 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
12 # FOR A PARTICULAR PURPOSE. |
|
13 # |
|
14 ############################################################################## |
|
15 |
|
16 __docformat__ = "restructuredtext" |
|
17 |
|
18 # import standard packages |
|
19 |
|
20 # import Zope3 interfaces |
|
21 from persistent.interfaces import IPersistent |
|
22 from transaction.interfaces import ITransactionManager |
|
23 from ZODB.interfaces import IConnection |
|
24 |
|
25 # import local interfaces |
|
26 |
|
27 # import Zope3 packages |
|
28 from zope.component import adapter |
|
29 from zope.interface import implementer |
|
30 |
|
31 # import local packages |
|
32 |
|
33 |
|
34 # IPersistent adapters copied from zc.twist package |
|
35 # also register this for adapting from IConnection |
|
36 @adapter(IPersistent) |
|
37 @implementer(ITransactionManager) |
|
38 def transactionManager(obj): |
|
39 conn = IConnection(obj) # typically this will be |
|
40 # zope.app.keyreference.persistent.connectionOfPersistent |
|
41 try: |
|
42 return conn.transaction_manager |
|
43 except AttributeError: |
|
44 return conn._txn_mgr |
|
45 # or else we give up; who knows. transaction_manager is the more |
|
46 # recent spelling. |
|