This file is indexed.

/usr/share/pyshared/Eikazo/Config.py is in eikazo 0.5.2-8.

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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
""" 
Copyright (c) Abel Deuring 2006 <adeuring@gmx.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, 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 License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

configuration.

Based on SafeConfigParser from the standard Python library,
which provides ervices for config files similar to Windows .ini
files. Quite simple, but good enough for this package

section names:

[device]
    status information for/from the Sane backends:
    Chosen resolution, scan size etc
[eikazo]
    information for/from Eikazo
[device-<someName>]
    information for/from device plugins.
"""

import ConfigParser

class SaneConfigError(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return self.value

class SaneConfig:
    def __init__(self, filenames=None):
        """ filenames: optional list of files that may be
            searched for inital cconfiguration values. See
            RawConfigParser.read() for details
        """
        self.parser = ConfigParser.SafeConfigParser()
        # list of ConfigAware instances
        # FIXME: since the config objects keep a reference to this
        # class, we have circular references. Not that much
        # of a problem, as long as the SaneMainWindow instance
        # lives as long as the program, but we will need a
        # method to break the reference circle, if SaneMainWindow
        # is destroyed and rebuild during a program run, or if
        # a class from Widgets.py are used elsewhere
        self.elements = []
        self.currentFile = None
        if filenames:
            self.parser.read(filenames)

    def register(self, ca):
        """ ca: a configAware instance. 
        """
        if not ca in self.elements:
            self.elements.append(ca)
    
    def loadConfig(self, filename):
        # load a config file. FIXME: should we use a new parser object??
        f = open(filename) # FIXME: check for errors
        self.currentFile = filename
        self.parser.readfp(f, filename)
        f.close()
        for ca in self.elements:
            ca.readConfig()

    def saveConfig(self, filename):
        # load a config file
        for ca in self.elements:
            ca.writeConfig()
        f = open(filename, 'w') # FIXME: check for errors
        self.parser.write(f)
        f.close()
        self.currentFile = filename
    
    def set(self, section, option, value):
        """ see the SafeConfigParser method
        """
        if not self.parser.has_section(section):
            self.parser.add_section(section)
        # we don't need "Percent-expansion", so let's replace
        # every '%' by '%%'. Otherwise, we'll get an exception
        # when we try to read a string with a '%' symbol
        value = value.replace('%', '%%')
        return self.parser.set(section, option, value)
    
    def get(self, section, option):
        """ see the SafeConfigParser method
        """
        try:
            return self.parser.get(section, option)
        except ConfigParser.NoSectionError:
            return None
        except ConfigParser.NoOptionError:
            return None

    def getint(self, section, option):
        """ see the SafeConfigParser method
        """
        try:
            return self.parser.getint(section, option)
        except ConfigParser.NoSectionError:
            return None
        except ConfigParser.NoOptionError:
            return None

    def getfloat(self, section, option):
        """ see the SafeConfigParser method
        """
        try:
            return self.parser.getfloat(section, option)
        except ConfigParser.NoSectionError:
            return None
        except ConfigParser.NoOptionError:
            return None

    def getboolean(self, section, option):
        """ see the SafeConfigParser method
        """
        try:
            return self.parser.getboolean(section, option)
        except ConfigParser.NoSectionError:
            return None
        except ConfigParser.NoOptionError:
            return None


class ConfigAware:
    """ base class; to be used for gtSaneWidget classes etc.
        Implements communication with a SaneConfig instance
        
        Many methods must be overloaded, because this class
        cannot know for example the data type required for a
        config value
    """
    def __init__(self, config):
        """ config: SaneConfig instance
        """
        self.config = config
        config.register(self)
    
    def readConfig(self):
        """ get config data from the SaneConfig instance.
            Called by SaneConfig fromo loadConfig; 
            should also be called in the constructor of 
            "config aware" classes
            
            Must be overloaded
        """
        raise SaneConfigError("readConfig method must be overloaded")
    
    def writeConfig(self):
        """ write config data into the config object
            Called by SaneConfig.saveConfig
            
            Must be overloaded
        """
        raise SaneConfigError("writeConfig method must be overloaded")