def parsenumber(v, strict=False):
    """
    Attempt to parse the value as a number, trying :func:`int`, :func:`long`,
    :func:`float` and :func:`complex` in that order. If all fail, return the
    value as-is.
    
    .. versionadded:: 0.4
    
    .. versionchanged:: 0.7 Set ``strict=True`` to get an exception if parsing fails.
    
    """
    
    try:
        return int(v)
    except:
        pass
    try:
        return int(v)
    except:
        pass
    try:
        return float(v)
    except:
        pass
    try:
        return complex(v)
    except:
        if strict:
            raise
    return v