def coerce_to_specific(datum):
    """
    Coerces datum to the most specific data type possible
    Order of preference: datetime, boolean, integer, decimal, float, string

    >>> coerce_to_specific('-000000001854.60')
    Decimal('-1854.60')
    >>> coerce_to_specific(7.2)
    Decimal('7.2')
    >>> coerce_to_specific("Jan 17 2012")
    datetime.datetime(2012, 1, 17, 0, 0)
    >>> coerce_to_specific("something else")
    'something else'
    >>> coerce_to_specific("20141010")
    datetime.datetime(2014, 10, 10, 0, 0)
    >>> coerce_to_specific("001210107")
    1210107
    >>> coerce_to_specific("010")
    10
    """
    if datum is None:
        return None 
    try:
        result = dateutil.parser.parse(datum)
        # but even if this does not raise an exception, may
        # not be a date -- dateutil's parser is very aggressive
        # check for nonsense unprintable date
        str(result) 
        # most false date hits will be interpreted as times today
        # or as unlikely far-future or far-past years
        clean_datum = datum.strip().lstrip('-').lstrip('0').rstrip('.')
        if len(_complex_enough_to_be_date.findall(clean_datum)) < 2:
            digits = _digits_only.search(clean_datum)
            if (not digits) or (len(digits.group(0)) not in 
                                (4, 6, 8, 12, 14, 17)):
                raise Exception("false date hit for %s" % datum)
            if result.date() == datetime.datetime.now().date():
                raise Exception("false date hit (%s) for %s" % (
                    str(result), datum))
            if not (1700 < result.year < 2150):
                raise Exception("false date hit (%s) for %s" % (
                    str(result), datum)) 
        return result
    except Exception as e:
        pass
    if str(datum).strip().lower() in ('0', 'false', 'f', 'n', 'no'):
        return False
    elif str(datum).strip().lower() in ('1', 'true', 't', 'y', 'yes'):
        return True
    try:
        return int(str(datum))
    except ValueError:
        pass
    try:
        return Decimal(str(datum))
    except InvalidOperation:
        pass
    try:
        return float(str(datum))
    except ValueError:
        pass
    return str(datum)
def coerce_to_specific ( datum ) : if datum is None : return None try : result = dateutil . parser . parse ( datum ) str ( result ) clean_datum = datum . strip ( ) . lstrip ( '-' ) . lstrip ( '0' ) . rstrip ( '.' ) if len ( _complex_enough_to_be_date . findall ( clean_datum ) ) < 2 : digits = _digits_only . search ( clean_datum ) if ( not digits ) or ( len ( digits . group ( 0 ) ) not in ( 4 , 6 , 8 , 12 , 14 , 17 ) ) : raise Exception ( "false date hit for %s" % datum ) if result . date ( ) == datetime . datetime . now ( ) . date ( ) : raise Exception ( "false date hit (%s) for %s" % ( str ( result ) , datum ) ) if not ( 1700 < result . year < 2150 ) : raise Exception ( "false date hit (%s) for %s" % ( str ( result ) , datum ) ) return result except Exception as e : pass if str ( datum ) . strip ( ) . lower ( ) in ( '0' , 'false' , 'f' , 'n' , 'no' ) : return False elif str ( datum ) . strip ( ) . lower ( ) in ( '1' , 'true' , 't' , 'y' , 'yes' ) : return True try : return int ( str ( datum ) ) except ValueError : pass try : return Decimal ( str ( datum ) ) except InvalidOperation : pass try : return float ( str ( datum ) ) except ValueError : pass return str ( datum )
Coerces datum to the most specific data type possible
    Order of preference: datetime, boolean, integer, decimal, float, string

    >>> coerce_to_specific('-000000001854.60')
    Decimal('-1854.60')
    >>> coerce_to_specific(7.2)
    Decimal('7.2')
    >>> coerce_to_specific("Jan 17 2012")
    datetime.datetime(2012, 1, 17, 0, 0)
    >>> coerce_to_specific("something else")
    'something else'
    >>> coerce_to_specific("20141010")
    datetime.datetime(2014, 10, 10, 0, 0)
    >>> coerce_to_specific("001210107")
    1210107
    >>> coerce_to_specific("010")
    10