Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

simplify

  • Loading branch information...
commit ba4e85ab05f2d0b21c33adb35673a98f5ea41bce 1 parent d018a3a
@pjenvey pjenvey authored
Showing with 5 additions and 21 deletions.
  1. +2 −8 docs/index.rst
  2. +3 −13 pyramid_tm/__init__.py
View
10 docs/index.rst
@@ -99,14 +99,8 @@ vetoes a commit if the status code starts with ``4`` or ``5`` or there is a
def default_commit_veto(request, response):
xtm = response.headers.get('x-tm')
if xtm is not None:
- if xtm == 'commit':
- return False
- return True
- status = response.status
- for bad in ('4', '5'):
- if status.startswith(bad):
- return True
- return False
+ return xtm != 'commit'
+ return response.status.startswith(('4', '5'))
If you'd like to use this commit veto in your system, you can do it via
Python:
View
16 pyramid_tm/__init__.py
@@ -23,14 +23,8 @@ def default_commit_veto(request, response):
"""
xtm = response.headers.get('x-tm')
if xtm is not None:
- if xtm == 'commit':
- return False
- return True
- status = response.status
- for bad in ('4', '5'):
- if status.startswith(bad):
- return True
- return False
+ return xtm != 'commit'
+ return response.status.startswith(('4', '5'))
class AbortResponse(Exception):
def __init__(self, response):
@@ -79,11 +73,7 @@ def tm_tween_factory(handler, registry, transaction=transaction):
old_commit_veto = registry.settings.get('pyramid_tm.commit_veto', None)
commit_veto = registry.settings.get('tm.commit_veto', old_commit_veto)
attempts = int(registry.settings.get('tm.attempts', 1))
-
- if not commit_veto:
- commit_veto = None
- else:
- commit_veto = resolver.maybe_resolve(commit_veto)
+ commit_veto = resolver.maybe_resolve(commit_veto) if commit_veto else None
def tm_tween(request):
if 'repoze.tm.active' in request.environ:
Please sign in to comment.
Something went wrong with that request. Please try again.