Added ConfigurableTypes.{str,int}.

This commit is contained in:
Jeremy Fincher 2003-11-08 09:46:23 +00:00
parent 024f462361
commit 0435ff00dc
1 changed files with 19 additions and 0 deletions

View File

@ -256,8 +256,27 @@ class _ConfigurableTypes(object):
else:
s = 'Value must be one of on/off/true/false/enable/disable.'
raise ConfigurableTypeError, s
def str(self, s):
if s and s[0] not in '\'"' and s[-1] not in '\'"':
s = repr(s)
try:
v = utils.safeEval(s)
if type(v) is not str:
raise ValueError
except ValueError:
raise ConfigurableTypeError, 'Value must be a string.'
return v
def int(self, s):
try:
return int(s)
except ValueError:
raise ConfigurableTypeError, 'Value must be an int.'
ConfigurableTypes = _ConfigurableTypes()
foobar = 'baz'
class Configurable(object):
"""A mixin class to provide a "config" command that can be consistent
across all plugins, in order to unify the configuration for each plugin.