/usr/share/pyshared/DAV/INI_Parse.py is in python-webdav 0.9.4.1-1build1.
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 | from ConfigParser import SafeConfigParser
class Configuration:
def __init__(self, fileName):
cp = SafeConfigParser()
cp.read(fileName)
self.__parser = cp
self.fileName = fileName
def __getattr__(self, name):
if name in self.__parser.sections():
return Section(name, self.__parser)
else:
return None
def __str__(self):
p = self.__parser
result = []
result.append('<Configuration from %s>' % self.fileName)
for s in p.sections():
result.append('[%s]' % s)
for o in p.options(s):
result.append('%s=%s' % (o, p.get(s, o)))
return '\n'.join(result)
class Section:
def __init__(self, name, parser):
self.name = name
self.__parser = parser
def __getattr__(self, name):
return self.__parser.get(self.name, name)
def __str__(self):
return str(self.__repr__())
def __repr__(self):
return self.__parser.items(self.name)
def getboolean(self, name):
return self.__parser.getboolean(self.name, name)
def __contains__(self, name):
return self.__parser.has_option(self.name, name)
def get(self, name, default):
if name in self:
return self.__getattr__(name)
else:
return default
def set(self, name, value):
self.__parser.set(self.name, name, str(value))
# Test
if __name__ == '__main__':
c = Configuration('Importador.ini')
print c.Origem.host, c.Origem.port
|