Cast unknown type into integer

    :param any x:
    :return int:
161562
def cast_int(x):
    
    try:
        x = int(x)
    except ValueError:
        try:
            x = x.strip()
        except AttributeError as e:
            logger_misc.warn("parse_str: AttributeError: String not number or word, {}, {}".format(x, e))
    return x
43450
def clean_int(x) -> int:
    
    try:
        return int(x)
    except ValueError:
        raise forms.ValidationError(
            "Cannot convert to integer: {}".format(repr(x)))
1292008
def one_over_x_like(x):
    
    if np.any(x < 0):
        return -np.Inf
    else:
        return -np.sum(np.log(x))
188519
def to_int(value: str, default: T = None) -> Union[int, Optional[T]]:
    
    try:
        return int(value)
    except (TypeError, ValueError):
        return default
740955
def _get_type(self, s):
        
        # TODO: what if the number is bigger than an int or float?
        if s.startswith('"') and s.endswith('"'):
            return s[1:-1]
        elif s.find('.') != -1: 
            return float(s) 
        else: 
            return int(s)
1121179
def get_int(value, default, test_fn=None):
    
    try:
        converted = int(value)
    except ValueError:
        return default

    test_fn = test_fn if test_fn else lambda x: True
    return converted if test_fn(converted) else default
517589
def _int_size(x):
    """"""
    if -0x80 <= x <= 0x7F:
        return 1
    elif -0x8000 <= x <= 0x7FFF:
        return 2
    elif -0x80000000 <= x <= 0x7FFFFFFF:
        return 4
    elif long(-0x8000000000000000) <= x <= long(0x7FFFFFFFFFFFFFFF):
        return 8
    else:
        raise RuntimeError("Cannot represent value: " + str(x))
630924
def int_or_str(v: Optional[str]) -> Union[None, int, str]:
    """"""
    if v is None:
        return
    try:
        return int(v)
    except ValueError:
        return v
240691
def _cast_value(value, _type):
    
    if _type.upper() == 'FLOAT64':
        return float64(value)
    elif _type.upper() == 'FLOAT32':
        return float32(value)
    elif _type.upper() == 'INT32':
        return int32(value)
    elif _type.upper() == 'UINT16':
        return uint16(value)
    elif _type.upper() == 'INT16':
        return int16(value)
    elif _type.upper() == 'BOOLEAN':
        return uint8(value)
    else:
        return float64(value)
689923
def _check_for_int(x):
    
    try:
        y = int(x)
    except (OverflowError, ValueError):
        pass
    else:
        # There is no way in AMF0 to distinguish between integers and floats
        if x == x and y == x:
            return y

    return x
1217950
def get_int(self, key, optional=False):
        
        return self._get_typed_value(key, int, lambda x: int(x), optional)
702455
def to_int(value, default=0):
    
    try:
        return int(value)
    except (TypeError, ValueError):
        return to_int(default, default=0)
989796
def normal_round_int(x: float) -> int:
    
    if not math.isfinite(x):
        raise ValueError("Input to normal_round_int() is not finite")
    if x >= 0:
        # noinspection PyTypeChecker
        return math.floor(x + 0.5)
    else:
        # noinspection PyTypeChecker
        return math.ceil(x - 0.5)
817621
def coerceBigInt(x):
    
    # BigInt's are easy.
    if isinstance(x, BigInt):
        return x

    # Convert ints and longs using the constructor
    elif isinstance(x, (long, int)):
        return BigInt(x)

    else:
        return None
339980
def integer(
        element_name,  # type: Text
        attribute=None,  # type: Optional[Text]
        required=True,  # type: bool
        alias=None,  # type: Optional[Text]
        default=0,  # type: Optional[int]
        omit_empty=False,  # type: bool
        hooks=None  # type: Optional[Hooks]
):
    # type: (...) -> Processor
    
    value_parser = _number_parser(int)
    return _PrimitiveValue(
        element_name,
        value_parser,
        attribute,
        required,
        alias,
        default,
        omit_empty,
        hooks
    )
1261426
def of_type(cls, iterable, types):
    

    return cls(x for x in iterable if isinstance(x, types))
422815
def num_to_var_int(x):
    
    x = int(x)
    if x < 253:
        return from_int_to_byte(x)

    elif x < 65536:
        return from_int_to_byte(253) + encode(x, 256, 2)[::-1]

    elif x < 4294967296:
        return from_int_to_byte(254) + encode(x, 256, 4)[::-1]

    else:
        return from_int_to_byte(255) + encode(x, 256, 8)[::-1]