39 lines
930 B
Python
39 lines
930 B
Python
import random, string
|
|
|
|
from . import logging
|
|
|
|
|
|
def boolean(v, fail=True):
|
|
if type(v) in [dict, list, tuple]:
|
|
raise ValueError(f'Value is not a string, boolean, int, or nonetype: {value}')
|
|
|
|
'''make the value lowercase if it's a string'''
|
|
value = v.lower() if type(value) == str else v
|
|
|
|
if value in [1, True, 'on', 'y', 'yes', 'true', 'enable']:
|
|
'''convert string to True'''
|
|
return True
|
|
|
|
elif value in [0, False, None, 'off', 'n', 'no', 'false', 'disable', '']:
|
|
'''convert string to False'''
|
|
return False
|
|
|
|
elif not fail:
|
|
'''just return the value'''
|
|
return value
|
|
|
|
else:
|
|
raise ValueError(f'Value cannot be converted to a boolean: {value}')
|
|
|
|
|
|
def randomgen(chars=20):
|
|
if type(chars) != int:
|
|
raise TypeError(f'Character length must be an integer, not a {type(char)}')
|
|
|
|
return ''.join(random.choices(string.ascii_letters + string.digits, k=chars))
|
|
|
|
|
|
def merp():
|
|
logging.setLevel('MERP')
|
|
logging.merp('heck')
|