From f66ef98ba6d03e69f59922fc4ff6c0cf2095aab0 Mon Sep 17 00:00:00 2001 From: Christophe de Vienne Date: Wed, 4 Jan 2012 10:48:07 +0100 Subject: [PATCH] Make the int and long types validation interchangeable --- wsme/types.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wsme/types.py b/wsme/types.py index 3c8960d..e35c6c8 100644 --- a/wsme/types.py +++ b/wsme/types.py @@ -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)