/usr/lib/python2.7/dist-packages/setoptconf/setting.py is in python-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 | # pylint: disable=W0401,W0223
import re
from .datatype import *
from .exception import NamingError
from .util import UnicodeMixin
__all__ = (
'Setting',
'StringSetting',
'IntegerSetting',
'FloatSetting',
'BooleanSetting',
'ListSetting',
'ChoiceSetting',
)
class Setting(UnicodeMixin, DataType):
RE_NAME = re.compile(r'^[a-z](?:[a-z0-9]|[_](?![_]))*[a-z0-9]$')
def __init__(self, name, default=None, required=False):
if Setting.RE_NAME.match(name):
self.name = name
else:
raise NamingError(name)
self._value = None
self.default = self.sanitize(default)
self.required = required
self.established = False
@property
def value(self):
return self._value
@value.setter
def value(self, value):
self._value = self.sanitize(value)
self.established = True
def __unicode__(self): # pragma: no cover
return unicode(self.name)
def __repr__(self): # pragma: no cover
return '<%s(%s=%s)>' % (
self.__class__.__name__,
self.name,
self.value if self.established else '',
)
class StringSetting(Setting, String):
pass
class IntegerSetting(Setting, Integer):
pass
class FloatSetting(Setting, Float):
pass
class BooleanSetting(Setting, Boolean):
pass
class ListSetting(Setting, List):
def __init__(self, name, subtype, **kwargs):
List.__init__(self, subtype)
Setting.__init__(self, name, **kwargs)
class ChoiceSetting(Setting, Choice):
def __init__(self, name, choices, subtype=None, **kwargs):
Choice.__init__(self, choices, subtype=subtype)
Setting.__init__(self, name, **kwargs)
|