def commit_veto(request, response):
    """
    When used as a commit veto, the logic in this function will cause
    the transaction to be aborted if:

        - An ``X-Tm`` response header with the value ``'abort'`` (or
          any value other than ``'commit'``) exists. A value of
          ``'commit'`` overrides any later match in this list.

        - The response status code starts with ``'4'`` or ``'5'``.

        - The request environment has a true value for
          ``'nti.commit_veto'``

    Otherwise the transaction will be allowed to commit.
    """
    xtm = response.headers.get('x-tm')
    if xtm is not None:
        return xtm != 'commit'
    if response.status.startswith(('4', '5')):
        return True
    return request.environ.get('nti.commit_veto')
