This file is indexed.

/usr/lib/python2.7/dist-packages/oops_twisted/config.py is in python-oops-twisted 0.0.6-0ubuntu4.

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
83
84
85
86
87
88
89
# Copyright (c) 2010, 2011, Canonical Ltd
#
# This program 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, version 3 only.
#
# This program 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/>.
# GNU Lesser General Public License version 3 (see the file LICENSE).

"""OOPS config and publishing for Twisted.

This module acts as an adapter for the oops.Config module - see `pydoc
oops.Config` for the primary documentation.

The only change is that Config.publish works with deferreds.

A helper function defer_publisher is supplied which can wrap a non-deferred
publisher.
"""

from functools import partial
from twisted.internet import defer
from twisted.internet.threads import deferToThread

import oops

from createhooks import failure_to_context

__all__ = [
    'Config',
    'defer_publisher',
    ]


class Config(oops.Config):
    """Twisted version of oops.Config.

    The only difference is that the publish method, which could block now
    expects each publisher to return a deferred.

    For more information see the oops.Config documentation.
    """

    def __init__(self, *args, **kwargs):
        oops.Config.__init__(self)
        self.on_create.insert(0, failure_to_context)

    def publish(self, report):
        """Publish a report.

        The report is first synchronously run past self.filters, then fired
        asynchronously at all of self.publishers.

        See `pydoc oops.Config.publish` for more documentation.

        :return: a twisted.internet.defer.Deferred. On success this deferred
            will return the list of oops ids allocated by the publishers (a
            direct translation of the oops.Config.publish result).
        """
        for report_filter in self.filters:
            if report_filter(report):
                return defer.succeed(None)
        if not self.publishers:
            return defer.succeed([])
        d = self.publishers[0](report)
        result = []
        def stash_id(id):
            report['id'] = id
            result.append(id)
            return report
        d.addCallback(stash_id)
        for publisher in self.publishers[1:]:
            d.addCallback(publisher)
            d.addCallback(stash_id)
        def return_result(_):
            return result
        d.addCallback(return_result)
        return d


def defer_publisher(publisher):
    """Wrap publisher in deferToThread."""
    return partial(deferToThread, publisher)