def as_int(obj, quiet=False):
    """Converts an arbitrary value into a integer."""
    try:
        return int(obj)
    except (ValueError, TypeError):
        pass
    try:
        return int(float(obj))
    except (ValueError, TypeError):
        pass
    if not quiet:
        raise TypeError("Can not translate '%s' (%s) to an integer" % (obj,
            type(obj)))
    return obj
