90 | 90 |
from repoze.tm import TM
|
91 | 91 |
new_wsgiapp = TM(mywsgiapp)
|
92 | 92 |
|
|
93 |
Using A Commit Veto
|
|
94 |
-------------------
|
|
95 |
|
|
96 |
If you'd like to veto commits based on the status code returned by the
|
|
97 |
downstream application, use a commit veto callback.
|
|
98 |
|
|
99 |
First, define the callback somewhere in your application:
|
|
100 |
|
|
101 |
.. code-block:: python
|
|
102 |
|
|
103 |
def commit_veto(environ, status, headers):
|
|
104 |
for good in ('1', '2', '3'):
|
|
105 |
if not status.startswith(good):
|
|
106 |
return True
|
|
107 |
for header_name, header_value in headers:
|
|
108 |
if header_name.lower() == 'x-tm-abort':
|
|
109 |
return True
|
|
110 |
|
|
111 |
Then configure it into your middleware.
|
|
112 |
|
|
113 |
Via Python:
|
|
114 |
|
|
115 |
.. code-block:: python
|
|
116 |
|
|
117 |
from otherplace import mywsgiapp
|
|
118 |
from my.package import commit_veto
|
|
119 |
|
|
120 |
from repoze.tm import TM
|
|
121 |
new_wsgiapp = TM(mywsgiapp, commit_veto=commit_veto)
|
|
122 |
|
|
123 |
Via PasteDeploy:
|
|
124 |
|
|
125 |
.. code-block:: ini
|
|
126 |
|
|
127 |
[filter:tm]
|
|
128 |
commit_veto = my.package:commit_veto
|
|
129 |
|
|
130 |
In the PasteDeploy example, the path is a Python dotted name, where the dots
|
|
131 |
separate module and package names, and the colon separates a module from its
|
|
132 |
contents. In the above example, the code would be implemented as a
|
|
133 |
"commit_veto" function which lives in the "package" submodule of the "my"
|
|
134 |
package.
|
|
135 |
|
93 | 136 |
Mocking Up A Data Manager
|
94 | 137 |
-------------------------
|
95 | 138 |
|