Utils Module


TcEx Utilities Module

class tcex.utils.utils.Utils[source]

Bases: AesOperations, DatetimeOperations, StringOperations, Variables

TcEx Utilities Class

static find_line_in_code(needle: str, code: str, trigger_start: Optional[Pattern[AnyStr]] = None, trigger_stop: Optional[Pattern[AnyStr]] = None) str[source]

Return matching line of code in a class definition.

  • needle – The string to search for.

  • code – The contents of the Python file to search.

  • trigger_start – The regex pattern to use to trigger the search.

  • trigger_stop – The regex pattern to use to stop the search.

static flatten_list(lst: List[Any]) List[Any][source]

Flatten a list

Will work for lists of lists to arbitrary depth and for lists with a mix of lists and single values

static is_cidr(possible_cidr_range: str) bool[source]

Return True if the provided value is a valid CIDR block.


possible_cidr_range – The cidr value to validate.

static is_ip(possible_ip: str) bool[source]

Return True if the provided value is a valid IP address.


possible_ip – The IP value to validate.

mapper(data: Union[list, dict], mapping: dict)[source]

Yield something …

static printable_cred(cred: str, visible: Optional[int] = 1, mask_char: Optional[str] = '*', mask_char_count: Optional[int] = 4) str[source]

Return a printable (masked) version of the provided credential.

  • cred – The cred to print.

  • visible – The number of characters at the beginning and ending of the cred to not mask.

  • mask_char – The character to use in the mask.

  • mask_char_count – How many mask character to insert (obscure cred length).

static remove_none(dict_: Dict[Any, Optional[Any]]) Dict[Any, Any][source]

Remove any mappings from a dict with a None value.

static standardize_asn(asn: str) str[source]

Return the ASN formatted for ThreatConnect.


asn – The asn value to standardize.