Make the int and long types validation interchangeable

This commit is contained in:
Christophe de Vienne
2012-01-04 10:48:07 +01:00
parent 000d35d177
commit f66ef98ba6

View File

@@ -122,6 +122,12 @@ def validate_value(datatype, value):
for key, v in value.items():
validate_value(key_type, key)
validate_value(value_type, v)
elif datatype in (int, long):
if not isinstance(value, int) and not isinstance(value, long):
raise ValueError(
"Wrong type. Expected an integer, got '%s'" % (
type(value)
))
elif not isinstance(value, datatype):
raise ValueError(
"Wrong type. Expected '%s', got '%s'" % (
@@ -195,7 +201,10 @@ class wsattr(object):
return getattr(instance, '_' + self.key, Unset)
def __set__(self, instance, value):
validate_value(self.datatype, value)
try:
validate_value(self.datatype, value)
except ValueError, e:
raise ValueError("%s: %s" % (self.name, e))
if value is Unset:
if hasattr(instance, '_' + self.key):
delattr(instance, '_' + self.key)