def decode(cls, data): data = data.strip() if not data: # Turn it into default value at the time of writing return None try: value = Integer.decode(data) except ValueError: value = data return value
def get_int_value(value, default=0): """ Return the interger representation of value is his decoding succeed otherwise the default value """ if not value: return default try: return Integer.decode(value) except ValueError: return default
def test_Integer(self): for x in range(-10,11): data = Integer.encode(x) self.assertEqual(x, Integer.decode(data))