This file is indexed.

/usr/lib/gedit/plugins/latex/util.py is in gedit-latex-plugin 3.8.0-3build1.

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
# -*- coding: utf-8 -*-

# This file is part of the Gedit LaTeX Plugin
#
# Copyright (C) 2010 Michael Zeising
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public Licence as published by the Free Software
# Foundation; either version 2 of the Licence, or (at your option) any later
# version.
#
# 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 General Public Licence for more
# details.
#
# You should have received a copy of the GNU General Public Licence along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA  02110-1301, USA

"""
util

Utility classes, functions and decorators used at various places across
the project
"""

import logging

def singleton(cls):
    """
    Singleton decorator that works with GObject derived types. The 'recommended'
    python one - http://wiki.python.org/moin/PythonDecoratorLibrary#Singleton
    does not (interacts badly with GObjectMeta
    """
    instances = {}
    def getinstance():
        if cls not in instances:
            instances[cls] = cls()
        return instances[cls]
    return getinstance

from gi.repository import Gtk
import traceback
from xml.sax import saxutils


class StringReader(object):
    """
    A simple string reader that is able to push back one character
    """
    def __init__(self, string):
        self._iter = iter(string)
        self.offset = 0
        self._pushbackChar = None
        self._pushbackFlag = False

    def read(self):
        if self._pushbackFlag:
            self._pushbackFlag = False
            return self._pushbackChar
        else:
            self.offset += 1
            return next(self._iter)

    def unread(self, char):
        #assert not self._pushbackFlag

        self._pushbackChar = char
        self._pushbackFlag = True


def escape(string, remove_newlines=True):
    """
    Prepares a string for inclusion in Pango markup and error messages
    """
    s = saxutils.escape(string)
    s = s.replace("\n", " ")
    s = s.replace("\"", """)
    return s


def open_error(message, secondary_message=None):
    """
    Popup an error dialog window
    """
    dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, message)
    if secondary_message:
        # TODO: why not use markup?
        dialog.format_secondary_text(secondary_message)
    dialog.run()
    dialog.destroy()


def open_info(message, secondary_message=None):
    """
    Popup an info dialog window
    """
    dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            Gtk.MessageType.INFO, Gtk.ButtonsType.OK, message)
    if secondary_message:
        dialog.format_secondary_markup(secondary_message)
    dialog.run()
    dialog.destroy()


def verbose(function):
    """
    'verbose'-decorator. This runs the decorated method in a try-except-block
    and shows an error dialog on exception.
    """
    def decorated_function(*args, **kw):
        try:
            return function(*args, **kw)
        except Exception as e:
            stack = traceback.format_exc(limit=10)
            open_error(str(e), stack)
    return decorated_function


class GladeInterface(object):
    """
    Utility base class for interfaces loaded from a Glade definition
    """

    __log = logging.getLogger("GladeInterface")

    def __init__(self):
        self.__tree = None
        self.filename = None

    def __get_tree(self):
        if not self.__tree:
            self.__tree = Gtk.Builder()
            self.__tree.add_from_file(self.filename)
        return self.__tree

    def find_widget(self, name):
        """
        Find a widget by its name
        """
        widget = self.__get_tree().get_object(name)
        if widget is None:
            self.__log.error("Widget '%s' could not be found in interface description '%s'" % (name, self.filename))
        return widget

    def connect_signals(self, mapping):
        """
        Auto-connect signals
        """
        self.__get_tree().connect_signals(mapping)

# ex:ts=4:et: