Made the exceptions raised give more useful messages.

This commit is contained in:
Jeremy Fincher 2004-02-02 08:31:11 +00:00
parent 84b0295e80
commit c0ea69ef0f

View File

@ -132,7 +132,7 @@ class Boolean(Value):
elif s == 'toggle': elif s == 'toggle':
value = not self.value value = not self.value
else: else:
raise InvalidRegistryValue, 'Value must be True or False.' raise InvalidRegistryValue, '%r is not True or False.' % s
self.setValue(value) self.setValue(value)
def setValue(self, v): def setValue(self, v):
@ -143,18 +143,18 @@ class Integer(Value):
try: try:
self.setValue(int(s)) self.setValue(int(s))
except ValueError: except ValueError:
raise InvalidRegistryValue, 'Value must be an integer.' raise InvalidRegistryValue, '%r is not an integer.' % s
class PositiveInteger(Value): class PositiveInteger(Value):
def set(self, s): def set(self, s):
try: try:
self.setValue(int(s)) self.setValue(int(s))
except ValueError: except ValueError:
raise InvalidRegistryValue, 'Value must be a positive integer.' raise InvalidRegistryValue, '%r is not a positive integer.' % s
def setValue(self, v): def setValue(self, v):
if v <= 0: if v <= 0:
raise InvalidRegistryValue, 'Value must be a positive integer.' raise InvalidRegistryValue, '%r is not a positive integer.' % v
Value.setValue(self, v) Value.setValue(self, v)
class Float(Value): class Float(Value):
@ -162,13 +162,13 @@ class Float(Value):
try: try:
self.setValue(float(s)) self.setValue(float(s))
except ValueError: except ValueError:
raise InvalidRegistryValue, 'Value must be a float.' raise InvalidRegistryValue, '%r is not a float.' % s
def setValue(self, v): def setValue(self, v):
try: try:
Value.setValue(self, float(v)) Value.setValue(self, float(v))
except ValueError: except ValueError:
raise InvalidRegistryValue, 'Value must be a float.' raise InvalidRegistryValue, '%r is not a float.' % v
class String(Value): class String(Value):
def set(self, s): def set(self, s):
@ -182,7 +182,7 @@ class String(Value):
raise ValueError raise ValueError
self.value = v self.value = v
except ValueError: # This catches utils.safeEval(s) errors too. except ValueError: # This catches utils.safeEval(s) errors too.
raise InvalidRegistryValue, 'Value must be a string.' raise InvalidRegistryValue, '%r is not a string.' % s
class NormalizedString(String): class NormalizedString(String):
def set(self, s): def set(self, s):
@ -220,7 +220,7 @@ class Regexp(Value):
self.value = None self.value = None
self.sr = s self.sr = s
except ValueError, e: except ValueError, e:
raise InvalidRegistryValue, 'Value must be a valid regexp: %s' % e raise InvalidRegistryValue, '%r is not a valid regexp: %s' % (s, e)
def setValue(self, v): def setValue(self, v):
if v is None: if v is None: