absfuyu.tools.generator module
Absfuyu: Generator
This generate stuff (Not python’s generator
)
Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)
Features:
Generate random string
Generate key
Generate check digit
Generate combinations of list in range
- class absfuyu.tools.generator.Charset[source]
Bases:
object
Character set data class
- DEFAULT = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
- ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
- FULL = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
- UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'
- DIGIT = '0123456789'
- SPECIAL = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
- ALL = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
- PRODUCT_KEY = 'BCDFGHJKMNPQRTVWXY2346789'
- class absfuyu.tools.generator.Generator[source]
Bases:
BaseClass
Generator that generate stuffs
- static generate_string(charset: str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', size: int = 8, times: int = 1, unique: bool = False, string_type_if_1: bool = False)[source]
Generate a list of random string from character set (Random string generator)
- Parameters:
charset (str) –
Use custom character set or character sets already defined in
Charset
Charset.DEFAULT
: character in [a-zA-Z0-9] (default)Charset.ALPHABET
: character in [a-zA-Z]Charset.FULL
: character in [a-zA-Z0-9] + special charactersCharset.UPPERCASE
: character in [A-Z]Charset.LOWERCASE
: character in [a-z]Charset.DIGIT
: character in [0-9]Charset.SPECIAL
: character in [!@#$%^&*()_+=-]Charset.ALL
: character in every printable character
size (int) – Length of each string in list (Default:
8
)times (int) – How many random string generated (Default:
1
)unique (bool) – Each generated text is unique (Default:
False
)string_type_if_1 (bool) – Return a
str
type result iftimes == 1
(Default:False
)
- Returns:
list – List of random string generated
str – When
string_type_if_1
isTrue
None – When invalid option
Example:
>>> Generator.generate_string(times=3) ['67Xfh1fv', 'iChcGz9P', 'u82fNzlm']
- classmethod generate_key(charset: str = 'BCDFGHJKMNPQRTVWXY2346789', letter_per_block: int = 5, number_of_block: int = 5, sep: str = '-') str [source]
Generate custom key
- Parameters:
charset (str) – Character set (Default:
Charset.PRODUCT_KEY
)letter_per_block (int) – Number of letter per key block (Default:
5
)number_of_block (int) – Number of key block (Default:
5
)sep (str) – Key block separator (Default:
-
)
- Returns:
Generated key
- Return type:
str
Example:
>>> Generator.generate_key(letter_per_block=10, number_of_block=2) 'VKKPJVYD2H-M7R687QCV2'
- static generate_check_digit(number: int) int [source]
Check digit generator
“A check digit is a form of redundancy check used for error detection on identification numbers, such as bank account numbers, which are used in an application where they will at least sometimes be input manually. It is analogous to a binary parity bit used to check for errors in computer-generated data. It consists of one or more digits (or letters) computed by an algorithm from the other digits (or letters) in the sequence input. With a check digit, one can detect simple errors in the input of a series of characters (usually digits) such as a single mistyped digit or some permutations of two successive digits.” (Wikipedia)
This function use Luhn’s algorithm to calculate
- Parameters:
number (int) – Number to calculate check digit
- Returns:
Check digit
- Return type:
int
Example:
>>> Generator.generate_check_digit("4129984562545") 7
- static combinations_range(sequence: list, *, min_len: int = 1, max_len: int = 0) list[tuple] [source]
Generate all combinations of a
sequence
frommin_len
tomax_len
- Parameters:
sequence (list) – A sequence that need to generate combination
min_len (int) – Minimum
r
ofcombinations
(Default:1
)max_len (int) – Maximum
r
ofcombinations
(Default:0
- len ofsequence
)
- Returns:
A list of all combinations from range(
min_len
,max_len
) ofsequence
- Return type:
list[tuple]
Example:
>>> Generator.combinations_range([1, 2, 3], min_len=2) [(1, 2), (1, 3), (2, 3), (1, 2, 3)]