This file is indexed.

/usr/lib/python3/dist-packages/pygccxml/declarations/mdecl_wrapper.py is in python3-pygccxml 1.8.0-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
# Copyright 2014-2016 Insight Software Consortium.
# Copyright 2004-2008 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

"""
defines class :class:`mdecl_wrapper_t` that allows to work on set of
declarations, as it was one declaration.

The :class:`class <mdecl_wrapper_t>` allows user to not write "for" loops
within the code.
"""

import os


class call_redirector_t(object):

    """Internal class used to call some function of objects"""

    def __init__(self, name, decls):
        """creates call_redirector_t instance.

        :param name: name of method, to be called on every object in the
        `decls` list
        :param decls: list of objects
        """
        object.__init__(self)
        self.name = name
        self.decls = decls

    def __call__(self, *arguments, **keywords):
        """calls method :attr:`call_redirector_t.name` on every object
        within the :attr:`call_redirector_t.decls` list"""
        for d in self.decls:
            callable_ = getattr(d, self.name)
            callable_(*arguments, **keywords)


class mdecl_wrapper_t(object):

    """
    multiple declarations class wrapper

    The main purpose of this class is to allow an user to work on many
    declarations, as they were only one single declaration.

    For example, instead of writing `for` loop like the following

    .. code-block:: python

       for c in global_namespace.classes():
           c.attribute = "xxxx"

    you can write:

    .. code-block:: python

       global_namespace.classes().attribute = "xxxx"

    The same functionality could be applied on "set" methods too.
    """

    def __init__(self, decls):
        """:param decls: list of declarations to operate on.
        :type decls: list of :class:`declaration wrappers <decl_wrapper_t>`
        """
        object.__init__(self)
        self.__dict__['declarations'] = decls

    def __bool__(self):
        return bool(self.declarations)

    def __len__(self):
        """returns the number of declarations"""
        return len(self.declarations)

    def __getitem__(self, index):
        """provides access to declaration"""
        return self.declarations[index]

    def __iter__(self):
        return iter(self.declarations)

    def __ensure_attribute(self, name):
        invalid_decls = [d for d in self.declarations if not hasattr(d, name)]
        sep = os.linesep + '    '
        if invalid_decls:
            raise RuntimeError((
                "Next declarations don't have '%s' attribute: %s")
                % (name, sep.join(map(str, invalid_decls))))

    def __setattr__(self, name, value):
        """Updates the value of attribute on all declarations.
        :param name: name of attribute
        :param value: new value of attribute
        """
        self.__ensure_attribute(name)
        for d in self.declarations:
            setattr(d, name, value)

    def __getattr__(self, name):
        """:param name: name of method
        """
        return call_redirector_t(name, self.declarations)

    def __contains__(self, item):
        return item in self.declarations

    def to_list(self):
        l = []
        for d in self.declarations:
            l.append(d)
        return l