/usr/lib/python3/dist-packages/reversion/middleware.py is in python3-django-reversion 2.0.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import sys
from reversion.revisions import create_revision as create_revision_base
from reversion.views import _request_creates_revision, _set_user_from_request, create_revision
class RevisionMiddleware(object):
"""Wraps the entire request in a revision."""
manage_manually = False
using = None
atomic = True
def __init__(self, get_response=None):
super(RevisionMiddleware, self).__init__()
# Support Django 1.10 middleware.
if get_response is not None:
self.get_response = create_revision(
manage_manually=self.manage_manually,
using=self.using,
atomic=self.atomic
)(get_response)
def process_request(self, request):
if _request_creates_revision(request):
context = create_revision_base(
manage_manually=self.manage_manually,
using=self.using,
atomic=self.atomic
)
context.__enter__()
if not hasattr(request, "_revision_middleware"):
setattr(request, "_revision_middleware", {})
request._revision_middleware[self] = context
def _close_revision(self, request, is_exception):
if self in getattr(request, "_revision_middleware", {}):
_set_user_from_request(request)
request._revision_middleware.pop(self).__exit__(*sys.exc_info() if is_exception else (None, None, None))
def process_response(self, request, response):
self._close_revision(request, False)
return response
def process_exception(self, request, exception):
self._close_revision(request, True)
def __call__(self, request):
return self.get_response(request)
|