add options for misc.RandomGen and create dbus classes
This commit is contained in:
parent
a1f7b8942c
commit
e7fd9aa78a
|
@ -38,14 +38,20 @@ def Boolean(v, return_value=False):
|
|||
return True
|
||||
|
||||
|
||||
def RandomGen(length=20, chars=None):
|
||||
def RandomGen(length=20, letters=True, digits=True, extra=None):
|
||||
if not isinstance(length, int):
|
||||
raise TypeError(f'Character length must be an integer, not {type(length)}')
|
||||
|
||||
characters = string.ascii_letters + string.digits
|
||||
characters = ''
|
||||
|
||||
if chars:
|
||||
characters += chars
|
||||
if letters:
|
||||
characters += string.ascii_letters
|
||||
|
||||
if digits:
|
||||
characters += string.digits
|
||||
|
||||
if extra:
|
||||
characters += extra
|
||||
|
||||
return ''.join(random.choices(characters, k=length))
|
||||
|
||||
|
|
Loading…
Reference in a new issue