def coerceValue(cls, val): """ Coerce a value to the type of the attribute, raise exception on fail. Arguments: val - the value to coerce Returns: None """ if type(val) is str: return val if isinstance(val, str): return str(val) # unicode subclass try: '' + val return str(val, 'latin-1') except Exception as e: raise exceptions.StringValueError(val)
def coerceValue(cls, value): """ Coerce a value to the type of the attribute, raise exception on fail. Arguments: val - the value to coerce Returns: None """ try: name, val = value if type(name) is not str: '' + name name = str(name, 'latin-1') #if type(val) not in (unicode, NoneType): # '' + val # val = unicode(val, 'latin-1') return MapValue((name, val)) except Exception as e: raise exceptions.StringValueError(value)
def coerceValue(cls, value): """ Coerce a value to the type of the attribute, raise exception on fail. Arguments: val - the value to coerce Returns: None """ try: name, val = value if type(name) is not str: '' + name name = str(name, 'latin-1') except Exception as e: raise exceptions.StringValueError(value) try: val = int(val) except ValueError: raise exceptions.TimestampValueError(value) return MapValue((name, val))
def coerceValue(cls, value): """ Coerce a value to the type of the attribute, raise exception on fail. Arguments: val - the value to coerce Returns: None """ try: name, val = value if type(name) is not str: '' + name name = str(name, 'latin-1') except Exception as e: raise exceptions.StringValueError(value) try: if not hasattr(cls, 'quantifier'): cls.quantifier = decimal.Decimal("0."+(cls.precision-1)*"0"+"1") val = decimal.Decimal(val).quantize(cls.quantifier) except Exception as e: raise exceptions.DecimalValueError(val) return MapValue((name, val))