def str2int(val, base=None):
    """String to integer conversion"""
    try:
        if isinstance(val, int) or val is None:
            return val
        elif base:
            return int(val, base)
        elif '0x' in val:
            return int(val, 16)
        elif '0b' in val:
            return int(val, 2)
        else:
            return int(val)
    except (ValueError, TypeError) as e:
        raise ValueError("Can't convert '%s' to int!" % val)