Uncommented something I didn't understand. Good thing I saw this before the release :)

This commit is contained in:
Jeremy Fincher 2004-04-16 08:13:55 +00:00
parent 392108a6fc
commit a4b54566e9
1 changed files with 22 additions and 10 deletions

View File

@ -128,8 +128,7 @@ class Group(object):
v = self.__class__(self.default, self.help) v = self.__class__(self.default, self.help)
v.set(s) v.set(s)
v.__class__ = self.X v.__class__ = self.X
# Undo this later unless you understand why you commented it out! v.supplyDefault = False
#v.supplyDefault = False
v.help = '' # Clear this so it doesn't print a bazillion times. v.help = '' # Clear this so it doesn't print a bazillion times.
self.register(attr, v) self.register(attr, v)
return v return v
@ -198,6 +197,7 @@ class Group(object):
class Value(Group): class Value(Group):
# Docstrings should start with, "Value must be ..." whenever possible.
"""Invalid registry value. If you're getting this message, report it, """Invalid registry value. If you're getting this message, report it,
because someone forgot to put a proper help string here.""" because someone forgot to put a proper help string here."""
def __init__(self, default, help, def __init__(self, default, help,
@ -299,7 +299,7 @@ class Float(Value):
self.error() self.error()
class String(Value): class String(Value):
"""Value is not a valid Python string.""" """Value must be a valid Python string."""
def set(self, s): def set(self, s):
if not s: if not s:
s = '""' s = '""'
@ -313,18 +313,22 @@ class String(Value):
except ValueError: # This catches utils.safeEval(s) errors too. except ValueError: # This catches utils.safeEval(s) errors too.
self.error() self.error()
class MetaOnlySomeStrings(type):
def __new__(cls, name, bases, dict):
if 'validStrings' in dict:
validStrings = dict['validStrings']
dict['__doc__'] = 'Value must be one of %s.' % \
utils.commaAndify(validStrings, And='or')
return type.__new__(cls, name, bases, dict)
class OnlySomeStrings(String): class OnlySomeStrings(String):
validStrings = () validStrings = ()
__metaclass__ = MetaOnlySomeStrings
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
assert self.validStrings, 'There must be some valid strings. ' \ assert self.validStrings, 'There must be some valid strings. ' \
'This is a bug.' 'This is a bug.'
String.__init__(self, *args, **kwargs) String.__init__(self, *args, **kwargs)
def error(self):
raise InvalidRegistryValue, \
'That is not a valid value. Valid values include %s.' % \
utils.commaAndify(map(repr, self.validStrings))
def normalize(self, s): def normalize(self, s):
lowered = s.lower() lowered = s.lower()
L = list(map(str.lower, self.validStrings)) L = list(map(str.lower, self.validStrings))
@ -369,6 +373,7 @@ class StringWithSpaceOnRight(String):
String.setValue(self, v) String.setValue(self, v)
class Regexp(Value): class Regexp(Value):
"""Value must be a valid Python regular expression of the form m/.../"""
def error(self, e): def error(self, e):
raise InvalidRegistryValue, 'Invalid regexp: %s' % e raise InvalidRegistryValue, 'Invalid regexp: %s' % e
@ -396,9 +401,17 @@ class Regexp(Value):
self() # Gotta update if we've been reloaded. self() # Gotta update if we've been reloaded.
return self.sr return self.sr
class MetaSeparatedListOf(type):
def __new__(cls, name, bases, dict):
if 'Value' in dict:
Value = dict['Value']
dict['__doc__'] = """Value must be a list of """
# XXX
class SeparatedListOf(Value): class SeparatedListOf(Value):
List = list List = list
Value = Value Value = Value
Separator = None
def splitter(self, s): def splitter(self, s):
"""Override this with a function that takes a string and returns a list """Override this with a function that takes a string and returns a list
of strings.""" of strings."""
@ -431,8 +444,7 @@ class SeparatedListOf(Value):
class SpaceSeparatedListOfStrings(SeparatedListOf): class SpaceSeparatedListOfStrings(SeparatedListOf):
Value = String Value = String
def splitter(self, s): splitter = staticmethod(str.split)
return s.split()
joiner = ' '.join joiner = ' '.join
class CommaSeparatedListOfStrings(SeparatedListOf): class CommaSeparatedListOfStrings(SeparatedListOf):