This file is indexed.

/usr/lib/python2.7/dist-packages/kiwi/controllers.py is in python-kiwi 1.9.22-4.

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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#
# Kiwi: a Framework and Enhanced Widgets for Python
#
# Copyright (C) 2001-2005 Async Open Source
#
# This library 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.
#
# This library 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 library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA
#
# Author(s): Christian Reis <kiko@async.com.br>
#            Lorenzo Gil Sanchez <lgs@sicem.biz>
#

from gtk import gdk

"""Holds the base controller class for the Kiwi Framework"""

class BaseController:
    """
    A generic controller that can be attached to any View

    BaseController defines one public variable:

        - view: corresponds to a the associated View instance, which
          holds the UI implementation itself (widgets, layout, etc.)
    """
    view = None
    def __init__(self, view=None, keyactions=None):
        """
        Creates a new controller, and attaches itself to a view. The
        constructor triggers a view.set_constructor(self) call, so the
        view is also attached to it. The arguments are identical to the
        view and keyactions class variables.

          - view: the correspondent view for the controller
          - keyactions: a mapping from GDK key symbol (GDK.A, etc.) to a
            method. The method will be called when any relevant keypress is
            generated for that view. The handler definition should look like:

            >>> def my_A_handler(self, widget, event, args):
        """

        if not view and not self.view:
            raise AssertionError(
                "Need a view to create controller, found None" )
        else:
            self.set_view(view)

        # Copy just to be on the safe side, avoiding problems with
        # mutable class variables
        self._keyactions = keyactions or {}

        self.view._attach_callbacks(self)
        # Call finalization hook
        self.view.on_startup()

    def on_key_press(self, widget, event):
        """
        The keypress handler, which dispatches keypresses to the
        functions mapped to in self.keyactions"""

        keyval = gdk.keyval_name(event.keyval)
        if keyval is None:
            return

        # Order is important, we want control_shift_alt_XXX
        method_name = 'key_'
        if event.state & gdk.CONTROL_MASK:
            method_name += 'control_'
        if event.state & gdk.SHIFT_MASK:
            method_name += 'shift_'
        if event.state & gdk.MOD1_MASK:
            method_name += 'alt_'

        method_name += keyval

        func = getattr(self, method_name, None)
        if not func and event.keyval in self._keyactions:
            func = self._keyactions[event.keyval]

        if func:
            return func()


    #
    # Accessors
    #

    def get_parent(self):
        """parent: the correspondent parent for the controller"""
        return self.parent

    def set_parent(self, parent):
        """parent: the correspondent parent for the controller"""
        self.parent = parent

    def get_view(self):
        """view: the correspondent view for the controller"""
        return self.view

    def set_view(self, view):
        """view: the correspondent view for the controller"""
        if self.view:
            msg = "This controller already has a view: %s"
            raise AssertionError(msg % self.view)
        self.view = view
        view.set_controller(self)

    def set_keyactions(self, keyactions):
        """
        Sets the keyactions mapping. See the constructor
        documentation for a description of it."""
        self._keyactions = keyactions

    def update_keyactions(self, new_actions):
        """
        XXX
        """
        self._keyactions.update(new_actions)

    #
    #
    #

    def _get_all_methods(self, klass=None):
        klass = klass or self.__class__
        # Very poor simulation of inheritance, but WFM(tm)
        classes = [klass]
        # Collect bases for class, using a pretty evil recursion
        for klass in classes:
            map(classes.append, klass.__bases__)
        # Order bases so that the class itself is the last one referred to
        # in the loop. This guarantees that the inheritance ordering for the
        # methods is preserved.
        classes.reverse()
        methods = {}
        for c in classes:
            for name in c.__dict__.keys():
                # Need to use getattr() to ensure we get bound methods
                try:
                    methods[name] = getattr(self, name)
                except AttributeError:
                    continue
        return methods