Strict commit veto to use with the transaction manager.

    Unlike the default commit veto supplied with the transaction manager,
    this will veto all commits for HTTP status codes other than 2xx unless
    a commit is explicitly requested by setting the "x-tm" response header to
    "commit". As with the default commit veto, the commit is always vetoed if
    the "x-tm" response header is set to anything other than "commit".

def commit_veto(request, response): # unused request arg pylint: disable=W0613
    """
    Strict commit veto to use with the transaction manager.

    Unlike the default commit veto supplied with the transaction manager,
    this will veto all commits for HTTP status codes other than 2xx unless
    a commit is explicitly requested by setting the "x-tm" response header to
    "commit". As with the default commit veto, the commit is always vetoed if
    the "x-tm" response header is set to anything other than "commit".
    """
    tm_header = response.headers.get('x-tm')
    if not tm_header is None:
        result = tm_header != 'commit'
    else:
        result = not response.status.startswith('2') \
                 and not tm_header == 'commit'
    return result