This file is indexed.

/usr/lib/python3/dist-packages/requestbuilder/logging.py is in python3-requestbuilder 0.5.2-2.

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) 2012-2015, Eucalyptus Systems, Inc.
#
# Permission to use, copy, modify, and/or distribute this software for
# any purpose with or without fee is hereby granted, provided that the
# above copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from __future__ import absolute_import

import logging


class ProgressiveStreamHandler(logging.StreamHandler):
    '''
    A handler class that allows the "cursor" to stay on one line for selected
    messages
    '''

    def __init__(self, **kwargs):
        logging.StreamHandler.__init__(self, **kwargs)
        self.appending = False

    def emit(self, record):
        try:
            if getattr(record, 'append', False):
                if self.appending:
                    self.stream.write(record.getMessage())
                else:
                    self.stream.write(self.format(record))
                self.appending = True
            else:
                terminator = getattr(self, 'terminator', '\n')
                if self.appending:
                    self.stream.write(terminator)
                self.stream.write(self.format(record))
                self.stream.write(terminator)
                self.appending = False
            self.flush()
        except (KeyboardInterrupt, SystemExit):
            raise
        except Exception:
            self.handleError(record)


class ColoringFormatter(logging.Formatter):
    LOG_COLORS = [(logging.ERROR, '\033[91m'),
                  (logging.WARN, '\033[93m'),
                  (logging.INFO, '\033[92m'),
                  (logging.DEBUG, '\033[94m')]

    def format(self, record):
        msg = logging.Formatter.format(self, record)
        for level, colorcode in sorted(self.LOG_COLORS, reverse=True):
            if record.levelno >= level:
                return colorcode + msg + '\033[0m'
        return msg


def configure_root_logger(use_color=False):
    logfmt = '%(asctime)s %(levelname)-7s %(name)s %(message)s'
    rootlogger = logging.getLogger('')
    handler = ProgressiveStreamHandler()
    if use_color:
        formatter = ColoringFormatter(logfmt)
    else:
        formatter = logging.Formatter(logfmt)
    handler.setFormatter(formatter)
    rootlogger.addHandler(handler)
    rootlogger.setLevel(100)

    # Attempt to have logging capture warnings as well (requires 2.7)
    try:
        logging.captureWarnings(True)
    except AttributeError:
        pass