This file is indexed.

/usr/lib/python3/dist-packages/plainbox/impl/validation.py is in python3-plainbox 0.25-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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# This file is part of Checkbox.
#
# Copyright 2012-2014 Canonical Ltd.
# Written by:
#   Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.

#
# Checkbox 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.

"""
:mod:`plainbox.impl.validation` -- validation tools
===================================================
"""

import logging
import copy

from plainbox.i18n import gettext as _
from plainbox.i18n import gettext_noop as N_
from plainbox.impl.symbol import SymbolDef


logger = logging.getLogger("plainbox.validation")


class Problem(SymbolDef):
    """
    Symbols for each possible problem that a field value may have
    """
    missing = 'missing'
    wrong = 'wrong'
    useless = 'useless'
    deprecated = 'deprecated'
    constant = 'constant'
    variable = 'variable'
    unknown_param = 'unknown_param'
    syntax_error = 'syntax_error'
    unknown = 'unknown'
    not_unique = 'not_unique'
    expected_i18n = 'expected_i18n'
    unexpected_i18n = 'unexpected_i18n'
    bad_reference = 'bad_reference'


class Severity(SymbolDef, allow_outer={"N_"}):
    """
    Symbols for class:`Issue` severity
    """
    error = N_('error')
    warning = N_('warning')
    advice = N_('advice')


class Issue:
    """
    Base carrier class for information about problems

    :attr message:
        Short description of the problem (one line)
    :attr severity:
        Severity of the problem (see :class:`Severity`)
    :attr kind:
        Problem "type" which is a Symbol with ``errno``-like semantics
    :attr origin:
        (optional) Origin of the problem
        (see :class:`plainbox.impl.secure.origin.Origin`)
    """

    def __init__(self, message, severity, kind, origin):
        self.message = message
        self.severity = severity
        self.kind = kind
        self.origin = origin

    def __str__(self):
        if self.origin is not None:
            return "{origin}: {severity}: {message}".format(
                origin=self.origin, severity=_(str(self.severity)),
                message=self.message)
        else:
            return "{severity}: {message}".format(
                severity=_(str(self.severity)), message=self.message)

    def __repr__(self):
        return (
            "{}(message={!r}, severity={!r}, kind={!r}, origin={!r})"
        ).format(self.__class__.__name__, self.message,
                 self.severity, self.kind, self.origin)

    def relative_to(self, base_dir):
        other = copy.copy(self)
        if self.origin is not None:
            other.origin = self.origin.relative_to(base_dir)
        return other


class ValidationError(ValueError):
    """
    Exception raised by to report jobs with problematic definitions.
    """

    def __init__(self, field, problem, hint=None, origin=None):
        self.field = field
        self.problem = problem
        self.hint = hint
        self.origin = origin

    def __str__(self):
        return _("Problem with field {}: {}").format(self.field, self.problem)

    def __repr__(self):
        return (
            "ValidationError(field={!r}, problem={!r}, "
            "hint={!r}, origin={!r})"
        ).format(self.field, self.problem, self.hint, self.origin)