示例#1
0
文件: util.py 项目: shenjia1/mavis
def soft_cast(value, cast_type):
    """
    cast a value to a given type, if the cast fails, cast to null

    Example:
        >>> cast(None, int)
        None
        >>> cast('', int)
        None
    """
    try:
        return cast(value, cast_type)
    except (TypeError, ValueError):
        pass
    return tab.cast_null(value)
示例#2
0
文件: util.py 项目: shenjia1/mavis
 def soft_null_cast(value):
     try:
         tab.cast_null(value)
     except TypeError:
         return value