This file is indexed.

/usr/share/pyshared/storm/django/middleware.py is in python-storm 0.19-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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# Copyright (c) 2008 Canonical
#
# Written by James Henstridge <jamesh@canonical.com>
#
# This file is part of Storm Object Relational Mapper.
#
# Storm is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# Storm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""Django middleware support for the Zope transaction manager.

Adding storm.django.middleware.ZopeTransactionMiddleware to
L{MIDDLEWARE_CLASSES} in the application's settings module will cause a
Zope transaction to be run for each request.
"""

__all__ = ['ZopeTransactionMiddleware']


from django.conf import settings

import transaction


class ZopeTransactionMiddleware(object):
    """Zope Transaction middleware for Django.

    If this is enabled, a Zope transaction will be run to cover each
    request.
    """
    def __init__(self):
        self.commit_safe_methods = getattr(
            settings, 'STORM_COMMIT_SAFE_METHODS', True)

    def process_request(self, request):
        """Begin a transaction on request start.."""
        from django.db import transaction as django_transaction
        django_transaction.enter_transaction_management()
        django_transaction.managed(True)
        transaction.begin()

    def process_exception(self, request, exception):
        """Abort the transaction on errors."""
        from django.db import transaction as django_transaction
        transaction.abort()
        django_transaction.set_clean()
        django_transaction.leave_transaction_management()

    def process_response(self, request, response):
        """Commit or abort the transaction after processing the response.

        On successful completion of the request, the transaction will
        be committed.

        As an exception to this, if the L{STORM_COMMIT_SAFE_METHODS}
        setting is False, and the request used either of the GET and
        HEAD methods, the transaction will be aborted.
        """
        from django.db import transaction as django_transaction
        # If process_exception() has been called, then we'll no longer
        # be in managed transaction mode.
        if django_transaction.is_managed():
            if self.commit_safe_methods or (
                request.method not in ['HEAD', 'GET']):
                transaction.commit()
            else:
                transaction.abort()
            django_transaction.set_clean()
            django_transaction.leave_transaction_management()
        return response