示例#1
0
def parse_distance_km(val):
    if val is None:
        return None
    try:
        return float(val) * 1000
    except:
        raise exceptions.ParseValueError("Error parsing distance value.")
示例#2
0
def parse_date(val):
    if val is None:
        return None
    else:
        mobj = re.match('\w+,\s*(\d+)\s+(\w+)\s+(\d+)', val)
        if mobj is not None:
            return date(int(mobj.group(3)), 
                        settings.MONTH2NUM[mobj.group(2)],
                        int(mobj.group(1)))
        else:
            exceptions.ParseValueError("Error parsing date value.")
示例#3
0
def parse_bool(val):
    if val is None:
        return None
    elif isinstance(val, bool):
        return val
    elif val.lower() == 'true':
        return True
    elif val.lower() == 'false':
        return False
    else:
        raise exceptions.ParseValueError("Error parsing bool value.")