/usr/lib/python3/dist-packages/setoptconf/config.py is in python3-setoptconf 0.2.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 | from .exception import MissingRequiredError, ReadOnlyError
from .util import UnicodeMixin
__all__ = (
'Configuration',
)
class Configuration(UnicodeMixin):
def __init__(self, settings, parent=None):
self.__dict__['_parent'] = parent
self.__dict__['_settings'] = {}
for setting in settings:
self._settings[setting.name] = setting
def validate_setting(self, name):
if name in self._settings:
setting = self._settings[name]
if setting.required and not setting.established:
if self._parent:
self._parent.validate_setting(name)
else:
raise MissingRequiredError(name)
elif self._parent:
self._parent.validate_setting(name)
else:
raise AttributeError('No such setting "%s"' % name)
def validate(self):
for name in self:
self.validate_setting(name)
def __getattr__(self, name):
if name in self._settings:
if self._settings[name].established:
return self._settings[name].value
elif self._parent:
return getattr(self._parent, name)
else:
return self._settings[name].default
elif self._parent:
return getattr(self._parent, name)
else:
raise AttributeError('No such setting "%s"' % name)
def __getitem__(self, key):
return getattr(self, key)
def __setattr__(self, name, value):
raise ReadOnlyError('Cannot change the value of settings')
def __setitem__(self, key, value):
setattr(self, key, value)
def __delattr__(self, name):
raise ReadOnlyError('Cannot delete settings')
def __delitem__(self, key):
delattr(self, key)
def __iter__(self):
all_names = set(self._settings.keys())
if self._parent:
all_names.update(iter(self._parent))
return iter(all_names)
def __len__(self):
return len(list(iter(self)))
def __contains__(self, item):
return item in list(iter(self))
def __unicode__(self): # pragma: no cover
return 'Configuration(%s)' % (
', '.join([
'%s=%s' % (name, repr(self[name]))
for name in self
])
)
def __repr__(self): # pragma: no cover
return '<%s>' % str(self)
|