4.7.5.6. Utilities¶
Utilities and tools.
- axonius_api_client.tools.type_str(value, max_len=60, join=', ')[source]¶
Pass.
- Parameters
value (
typing.Any
) –max_len (
int
) –join (
typing.Optional
[str
]) –
- Return type
- axonius_api_client.tools.pathify(path, path_strict=True, path_encoding='utf-8', resolve=True, expanduser=True, as_file=False, as_dir=False, exts=None)[source]¶
Convert a str into a fully resolved & expanded Path object.
- Parameters
path (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) –path_strict (
bool
) –path_encoding (
str
) –resolve (
bool
) –expanduser (
bool
) –as_file (
bool
) –as_dir (
bool
) –exts (
typing.Optional
[typing.List
[str
]]) –
- Return type
- axonius_api_client.tools.is_existing_file(path, **kwargs)[source]¶
Check if the supplied value refers to an existing file.
- Parameters
path (
typing.Any
) –- Return type
- axonius_api_client.tools.listify(obj=None, split=False, split_max=-1, split_sep=re.compile(','), strip=True, strip_chars=None, encoding='utf-8', errors='replace', dictkeys=False, **kwargs)[source]¶
Force an object into a list.
Notes
- Parameters
obj (
typing.Optional
[typing.Any
]) – object to coerce to listdictkeys (
bool
) – if obj is dict, return list of keys of objsplit (
bool
) –split_max (
typing.Optional
[int
]) –split_sep (
typing.Optional
[typing.TypeVar
(PatternLike
,typing.Pattern
,str
,bytes
)]) –strip (
bool
) –strip_chars (
typing.Optional
[str
]) –encoding (
str
) –errors (
str
) –
- Return type
- axonius_api_client.tools.grouper(iterable, n, fillvalue=None)[source]¶
Split an iterable into chunks.
- Parameters
iterable (
typing.Iterable
) – iterable to split into chunks of size nn (
int
) – length to split iterable intofillvalue (
typing.Optional
[typing.Any
]) – value to use as filler for last chunk
- Return type
- axonius_api_client.tools.coerce_int(obj, max_value=None, min_value=None, allow_none=False, as_none=None, valid_values=None, errmsg=None)[source]¶
Convert an object into int.
- Parameters
obj (
typing.Any
) – object to convert to intmax_value (
typing.Optional
[int
]) –min_value (
typing.Optional
[int
]) –allow_none (
bool
) –as_none (
typing.Optional
[typing.Any
]) –valid_values (
typing.Optional
[typing.List
[int
]]) –errmsg (
typing.Optional
[str
]) –
- Raises
ToolsError – if obj is not int
- Return type
- axonius_api_client.tools.coerce_int_float(value, as_float=False, error=True, ret_value=False, as_none=None)[source]¶
Coerce a value into int or float.
- Parameters
- Returns
float or int if value is int, float, int as str, or float as str; else None
- Return type
- axonius_api_client.tools.coerce_bool(obj, errmsg=None, error=True, allow_none=False, as_none=None, as_original=False)[source]¶
Convert an object into bool.
- Parameters
obj (
typing.Any
) – object to coerce to bool, will check againstaxonius_api_client.constants.general.YES
andaxonius_api_client.constants.general.NO
errmsg (
typing.Optional
[str
]) –error (
bool
) –allow_none (
bool
) –as_none (
typing.Optional
[typing.Any
]) –as_original (
bool
) –
- Raises
ToolsError – obj is not bool
- Return type
- axonius_api_client.tools.is_str(value, not_empty=True)[source]¶
Check if value is non-empty string.
- Parameters
value (
typing.Any
) –not_empty (
bool
) –
- Return type
- axonius_api_client.tools.is_email(value)[source]¶
Check if a value is a valid email.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.is_int(obj, digit=False)[source]¶
Check if obj is int typeable.
- Parameters
obj (
typing.Any
) – object to checkdigit (
bool
) – allow checking str/bytes
- Return type
- axonius_api_client.tools.strip_right(obj, fix)[source]¶
Strip text from the right side of obj.
- Parameters
obj (
typing.Union
[typing.List
[str
],str
]) – str(s) to strip fix fromfix (
str
) – str to remove from obj(s)
- Return type
- axonius_api_client.tools.strip_left(obj, fix)[source]¶
Strip text from the left side of obj.
- Parameters
obj (
typing.Union
[typing.List
[str
],str
]) – str(s) to strip fix fromfix (
str
) – str to remove from obj(s)
- Return type
- class axonius_api_client.tools.AxJSONEncoder(*args, **kwargs)[source]¶
Bases:
JSONEncoder
Pass.
- encode(o)¶
Return a JSON string representation of a Python data structure.
>>> from json.encoder import JSONEncoder >>> JSONEncoder().encode({"foo": ["bar", "baz"]}) '{"foo": ["bar", "baz"]}'
- item_separator = ', '¶
- iterencode(o, _one_shot=False)¶
Encode the given object and yield each string representation as available.
For example:
for chunk in JSONEncoder().iterencode(bigobject): mysocket.write(chunk)
- key_separator = ': '¶
- axonius_api_client.tools.has_to_dict(obj)[source]¶
Pass.
- Parameters
obj (
typing.Any
) –- Return type
- axonius_api_client.tools.json_dump(obj, indent=2, sort_keys=False, error=True, fallback=<class 'str'>, to_dict=True, cls=<class 'axonius_api_client.tools.AxJSONEncoder'>, **kwargs)[source]¶
Serialize an object into json str.
- Parameters
obj (
typing.Any
) – object to serialize into json strindent (
typing.Optional
[int
]) – json str indent levelsort_keys (
bool
) – sort dict keyserror (
bool
) – if json error happens, raise it**kwargs – passed to
json.dumps()
fallback (
typing.Any
) –to_dict (
bool
) –cls (
typing.Type
) –
- Return type
- axonius_api_client.tools.lens(value)[source]¶
Pass.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.tlens(value)[source]¶
Pass.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.json_load(obj, error=True, load_file=True, close_fh=True, **kwargs)[source]¶
Deserialize a json str into an object.
- Parameters
obj (
typing.Union
[str
,typing.IO
,pathlib.Path
]) – str to deserialize into objerror (
bool
) – if json error happens, raise it**kwargs – passed to
json.loads()
load_file (
bool
) –close_fh (
bool
) –
- Return type
- axonius_api_client.tools.is_file_like(value)[source]¶
Pass.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.csv_load(value, encoding='utf-8-sig', restkey='extra_columns', close_fh=True, **kwargs)[source]¶
Pass.
- Parameters
value (
typing.Union
[str
,bytes
,typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
),typing.IO
]) –encoding (
str
) –restkey (
typing.Optional
[str
]) –close_fh (
bool
) –
- Return type
- axonius_api_client.tools.jsonl_loader(item, idx, error=True, **kwargs)[source]¶
Pass.
- Parameters
- Return type
- axonius_api_client.tools.jsonl_load(obj, error=True, close_fh=True, **kwargs)[source]¶
Deserialize a jsonl str into an object.
- Parameters
obj (
typing.Union
[str
,typing.List
[str
],typing.IO
]) – str to deserialize into objerror (
bool
) – if json error happens, raise it**kwargs – passed to
json.loads()
close_fh (
bool
) –
- Return type
- axonius_api_client.tools.json_log(obj, error=False, trim=100, trim_lines=True, trim_msg='\\nTrimmed {value_len} {trim_type} down to {trim}', **kwargs)[source]¶
Pass.
- Parameters
obj (
typing.Any
) –error (
bool
) –trim (
typing.Optional
[int
]) –trim_lines (
bool
) –trim_msg (
str
) –
- Return type
- axonius_api_client.tools.json_reload(obj, error=False, trim=None, trim_lines=False, trim_msg='\\nTrimmed {value_len} {trim_type} down to {trim}', **kwargs)[source]¶
Re-serialize a json str into a pretty json str.
- Parameters
obj (
typing.Any
) – str to deserialize into obj and serialize back to strerror (
bool
) – If json error happens, raise it**kwargs – passed to
json_dump()
trim (
typing.Optional
[int
]) –trim_lines (
bool
) –trim_msg (
str
) –
- Return type
- axonius_api_client.tools.text_load(value, close_fh=True)[source]¶
Pass.
- Parameters
value (
typing.Union
[str
,typing.List
[str
],typing.IO
]) –close_fh (
bool
) –
- Return type
- axonius_api_client.tools.dt_parse_uuid(value, default_tz_utc=False, allow_none=False, error=False)[source]¶
Parse the date from an object UUID.
- Parameters
- Return type
- axonius_api_client.tools.dt_parse(obj, default_tz_utc=False, allow_none=False, as_none=None, as_tz=datetime.timezone.utc)[source]¶
Parse a str, datetime, or timedelta into a datetime object.
- Parameters
obj (
typing.Union
[typing.TypeVar
(TypeDate
,str
,bytes
,datetime.datetime
,datetime.timedelta
),typing.List
[typing.TypeVar
(TypeDate
,str
,bytes
,datetime.datetime
,datetime.timedelta
)],None
]) – object or list of objects to parse into datetimedefault_tz_utc (
bool
) – if no timezone is found, assume UTCallow_none – if obj is None or “none” or “null”, return None
as_none (
typing.Optional
[typing.Any
]) – if allow_none and obj is None, return this valueas_tz (
typing.Union
[str
,datetime.tzinfo
,None
]) – if not None, convert to this timezone
- Return type
typing.Union
[datetime.datetime
,typing.List
[datetime.datetime
],None
]
- axonius_api_client.tools.dt_parse_tmpl(obj, tmpl='%Y-%m-%d')[source]¶
Parse a string into the format used by the REST API.
- Parameters
obj (
typing.Union
[str
,datetime.timedelta
,datetime.datetime
]) – date time to parse usingdt_parse()
tmpl (
str
) – strftime template to convert obj into
- Return type
- axonius_api_client.tools.dt_now(delta=None, tz=datetime.timezone.utc)[source]¶
Get the current datetime in for a specific tz.
- Parameters
delta (
typing.Optional
[datetime.timedelta
]) – convert delta into datetime str instead of returning nowtz (
typing.Optional
[datetime.timezone
]) – timezone to return datetime in
- Return type
<module ‘datetime’ from ‘/home/docs/.pyenv/versions/3.7.9/lib/python3.7/datetime.py’>
- axonius_api_client.tools.dt_now_file(fmt='%Y-%m-%dT%H-%M-%S', **kwargs)[source]¶
Pass.
- Parameters
fmt (
str
) –
- axonius_api_client.tools.dt_sec_ago(obj, exact=False, places=2)[source]¶
Get number of seconds ago a given datetime was.
- Parameters
obj (
typing.Union
[str
,datetime.timedelta
,datetime.datetime
]) – parsed bydt_parse()
into a datetime objexact (
bool
) – if True, return exact seconds, otherwise round to placesplaces (
int
) – number of places to round to
- Return type
- axonius_api_client.tools.dt_days_ago(obj, error=False, from_now=True)[source]¶
Get number of days ago a given datetime was.
- Parameters
obj (
typing.Union
[str
,datetime.timedelta
,datetime.datetime
]) – parsed bydt_sec_ago()
into seconds agoerror (
bool
) – if True, raise any errors, otherwise return Nonefrom_now (
bool
) – if True, return days from now, otherwise return days ago
- Return type
- axonius_api_client.tools.dt_min_ago(obj)[source]¶
Get number of minutes ago a given datetime was.
- Parameters
obj (
typing.Union
[str
,datetime.timedelta
,datetime.datetime
]) – parsed bydt_sec_ago()
into seconds ago- Return type
- axonius_api_client.tools.dt_days_left(obj)[source]¶
Get number of days left until a given datetime.
- Parameters
obj (
typing.Union
[str
,datetime.timedelta
,datetime.datetime
,None
]) – parsed bydt_sec_ago()
into days left- Return type
- axonius_api_client.tools.dt_within_min(obj, n=None)[source]¶
Check if given datetime is within the past n minutes.
- Parameters
obj (
typing.Union
[str
,datetime.timedelta
,datetime.datetime
]) – parsed bydt_min_ago()
into minutes agon (
typing.Union
[int
,str
,None
]) – int ofdt_min_ago()
should be greater than or equal to
- Return type
- axonius_api_client.tools.get_path(obj)[source]¶
Convert a str into a fully resolved & expanded Path object.
- Parameters
obj (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) – obj to convert into expanded and resolved absolute Path obj- Return type
- axonius_api_client.tools.path_read(obj, binary=False, is_json=False, **kwargs)[source]¶
Read data from a file.
Notes
if path filename ends with “.json”, data will be deserialized using
json_load()
- Parameters
obj (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) – path to read data form, parsed byget_path()
binary (
bool
) – read the data as binary instead of stris_json (
bool
) – deserialize data usingjson_load()
**kwargs – passed to
json_load()
- Raises
ToolsError – path does not exist as file
- Return type
- axonius_api_client.tools.get_backup_filename(path)[source]¶
Pass.
- Parameters
path (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) –- Return type
- axonius_api_client.tools.get_backup_path(path)[source]¶
Pass.
- Parameters
path (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) –- Return type
- axonius_api_client.tools.check_path_is_not_dir(path)[source]¶
Pass.
- Parameters
path (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) –- Return type
- axonius_api_client.tools.path_create_parent_dir(path, make_parent=True, protect_parent=448)[source]¶
Pass.
- Parameters
path (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) –make_parent (
bool
) –
- Return type
- axonius_api_client.tools.path_backup_file(path, backup_path=None, make_parent=True, protect_parent=448, **kwargs)[source]¶
Pass.
- Parameters
path (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) –backup_path (
typing.Optional
[typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)]) –make_parent (
bool
) –
- Return type
- axonius_api_client.tools.auto_suffix(path, data, error=False, **kwargs)[source]¶
Pass.
- Parameters
path (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) –data (
typing.Union
[bytes
,str
]) –error (
bool
) –
- Return type
- axonius_api_client.tools.path_write(obj, data, overwrite=False, backup=False, backup_path=None, binary=False, binary_encoding='utf-8', is_json=False, make_parent=True, protect_file=384, protect_parent=448, suffix_auto=True, path_default=None, use_default=False, **kwargs)[source]¶
Write data to a file.
Notes
if obj filename ends with “.json”, serializes data using
json_dump()
.
- Parameters
obj (
typing.Optional
[typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)]) – path to write data to, parsed byget_path()
data (
typing.Union
[bytes
,str
]) – data to write to objbinary (
bool
) – write the data as binary instead of strbinary_encoding (
str
) – encoding to use when switching from str/bytesis_json (
bool
) – serialize data usingjson_load()
overwrite (
bool
) – overwrite obj if existsmake_parent (
bool
) – If the parent directory does not exist, create itprotect_file – octal mode of permissions to set on file
protect_dir – octal mode of permissions to set on parent directory when creating
**kwargs – passed to
json_dump()
backup (
bool
) –backup_path (
typing.Optional
[typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)]) –suffix_auto (
bool
) –path_default (
typing.Optional
[typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)]) –use_default (
bool
) –
- Raises
ToolsError – path exists as file and overwrite is False
ToolsError – if parent path does not exist and make_parent is False
- Return type
typing.Tuple
[pathlib.Path
,typing.Tuple
[int
,typing.Optional
[pathlib.Path
]]]
- axonius_api_client.tools.longest_str(obj)[source]¶
Determine the length of the longest string in a list of strings.
- Parameters
obj (
typing.List
[str
]) – list of strings to calculate length of- Return type
- axonius_api_client.tools.split_str(obj, split=',', strip=None, do_strip=True, lower=True, empty=False)[source]¶
Split a string or list of strings into a list of strings.
- Parameters
obj (
typing.Union
[typing.List
[str
],str
]) – string or list of strings to splitsplit (
str
) – character to split onstrip (
typing.Optional
[str
]) – characters to stripdo_strip (
bool
) – strip each item from the splitlower (
bool
) – lowercase each item from the splitempty (
bool
) – remove empty items post split
- Return type
- axonius_api_client.tools.echo_debug(msg=None, **kwargs)[source]¶
Echo a message to console.
- Parameters
msg (
typing.Union
[str
,typing.List
[str
],None
]) – message to echokwargs – passed to
echo
- axonius_api_client.tools.echo_ok(msg=None, **kwargs)[source]¶
Echo a message to console.
- Parameters
msg (
typing.Union
[str
,typing.List
[str
],None
]) – message to echokwargs – passed to
echo
- axonius_api_client.tools.echo_warn(msg=None, **kwargs)[source]¶
Echo a warning message to console.
- Parameters
msg (
typing.Union
[str
,typing.List
[str
],None
]) – message to echokwargs – passed to
echo
- axonius_api_client.tools.echo_error(msg=None, abort=True, **kwargs)[source]¶
Echo an error message to console.
- Parameters
msg (
typing.Union
[str
,typing.List
[str
],None
]) – message to echoabort (
bool
) – call sys.exit(1) after echoing messagekwargs – passed to
echo
- axonius_api_client.tools.echo(msg=None, abort=False, tmpl=True, log=None, log_level='debug', log_method=None, log_args=None, log_fallback=<bound method Logger.debug of <Logger axonius_api_client.tools (DEBUG)>>, style_tmpl=None, style_args=None, joiner='\\n', do_log=True, do_echo=True, abort_code=0, **kwargs)[source]¶
Pass.
- Parameters
msg (
typing.Union
[str
,typing.List
[str
],None
]) –abort (
bool
) –tmpl (
bool
) –log (
typing.Optional
[logging.Logger
]) –log_level (
str
) –log_method (
typing.Optional
[typing.Callable
]) –log_args (
typing.Optional
[dict
]) –log_fallback (
typing.Callable
) –style_tmpl (
typing.Optional
[str
]) –style_args (
typing.Optional
[dict
]) –joiner (
str
) –do_log (
bool
) –do_echo (
bool
) –abort_code (
int
) –
- axonius_api_client.tools.calc_percent(part, whole, places=2)[source]¶
Calculate the percentage of part out of whole.
- Parameters
part (
typing.Union
[int
,float
]) – number to get percent of wholewhole (
typing.Union
[int
,float
]) – number to calculate against partplaces (
int
) – number of decimal places to return
- Return type
- axonius_api_client.tools.join_kv(obj, listjoin=', ', tmpl='{k}: {v!r}')[source]¶
Join a dictionary into key value strings.
- Parameters
obj (
typing.Union
[typing.List
[dict
],dict
]) – dict or list of dicts to stringifylistjoin (
str
) – string to use for joiningtmpl (
str
) – template to format key value pairs of dict
- Return type
- axonius_api_client.tools.get_type_str(obj)[source]¶
Get the type name of a class.
- Parameters
obj (
typing.Any
) – class or tuple of classes to get type name(s) of
- axonius_api_client.tools.check_type(value, exp, name='', exp_items=None)[source]¶
Check that a value is the appropriate type.
- Parameters
value (
typing.Any
) – value to check type ofexp (
typing.Any
) – type(s) that value should bename (
str
) – identifier of what value is forexp_items (
typing.Optional
[typing.Any
]) – if value is a list, type(s) that list items should be
- axonius_api_client.tools.check_empty(value, name='')[source]¶
Check if a value is empty.
- Parameters
value (
typing.Any
) – value to check type ofname (
str
) – identifier of what value is for
- axonius_api_client.tools.coerce_str_to_csv(value, coerce_list=False, errmsg=None)[source]¶
Coerce a string into a list of strings.
- Parameters
value (
str
) – string to seperate using commacoerce_list (
bool
) –errmsg (
typing.Optional
[str
]) –
- Return type
- axonius_api_client.tools.parse_ip_address(value)[source]¶
Parse a string into an IP address.
- Parameters
value (
str
) – ip address- Return type
- axonius_api_client.tools.parse_ip_network(value)[source]¶
Parse a string into an IP network.
- Parameters
value (
str
) – ip network- Return type
- axonius_api_client.tools.kv_dump(obj)[source]¶
Get a string representation of a dictionaries key value pairs.
- axonius_api_client.tools.bom_strip(content, strip=True, bom=b'\\xef\\xbb\\xbf')[source]¶
Remove the UTF-8 BOM marker from the beginning of a string.
- Parameters
content (
typing.Union
[str
,bytes
]) – string to remove BOM marker from if foundstrip – remove whitespace before & after removing BOM marker
bom (
bytes
) –
- Return type
- axonius_api_client.tools.read_stream(stream)[source]¶
Try to read input from a stream.
- Parameters
stream – stdin or a file descriptor to read input from
- Return type
- axonius_api_client.tools.check_gui_page_size(size=None)[source]¶
Check page size to see if it one of the valid GUI page sizes.
- Parameters
size (
typing.Optional
[int
]) – page size to check- Raises
ApiError – if size is not one of
axonius_api_client.constants.api.GUI_PAGE_SIZES
- Return type
- axonius_api_client.tools.calc_perc_gb(obj, whole_key, part_key, perc_key=None, places=2, update=True, is_kb=True)[source]¶
Calculate the GB and percent from a dict.
- Parameters
obj (
dict
) – dict to get whole_key and part_key fromwhole_key (
str
) – key to get whole value from and convert to GB and set as whole_key_gbpart_key (
str
) – key to get part value from and convert to GB and set as part_key_gbperc_key (
typing.Optional
[str
]) – key to set percent inis_kb (
bool
) – values are in kb or bytesplaces (
int
) –update (
bool
) –
- Return type
- axonius_api_client.tools.get_subcls(cls, excludes=None)[source]¶
Get all subclasses of a class.
- Parameters
cls (
type
) –excludes (
typing.Optional
[typing.List
[type
]]) –
- Return type
- axonius_api_client.tools.prettify_obj(obj, indent=0)[source]¶
Pass.
- Parameters
obj (
typing.Union
[dict
,list
]) –indent (
int
) –
- Return type
- axonius_api_client.tools.bytes_to_str(value, encoding='utf-8', ignore=False, strict=False)[source]¶
Convert value to str if value is bytes.
- Parameters
- Returns
str if value is bytes, else original value
- Return type
t.Any
- axonius_api_client.tools.strip_str(value)[source]¶
Strip a value if it is a string.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.coerce_str(value, strip=True, none='', trim=None, trim_lines=False, trim_msg='\\nTrimmed {value_len} {trim_type} down to {trim}')[source]¶
Coerce a value to a string.
- Parameters
value (
typing.Any
) –strip (
bool
) –none (
typing.Any
) –trim (
typing.Optional
[int
]) –trim_lines (
bool
) –trim_msg (
str
) –
- Return type
- axonius_api_client.tools.str_trim(value, trim=None, trim_lines=False, trim_msg='\\nTrimmed {value_len} {trim_type} down to {trim}')[source]¶
Pass.
- axonius_api_client.tools.get_cls_path(value)[source]¶
Pass.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.csv_writer(rows, columns=None, quotes='nonnumeric', dialect='excel', line_ending='\\n', stream=None, key_extra_error=False, write_headers=True, key_missing_value=None)[source]¶
Pass.
- Parameters
rows (
typing.Iterable
[dict
]) –columns (
typing.Optional
[typing.Iterable
[str
]]) –quotes (
str
) –dialect (
str
) –line_ending (
str
) –stream (
typing.Optional
[typing.IO
]) –key_extra_error (
bool
) –write_headers (
bool
) –key_missing_value (
typing.Optional
[typing.Any
]) –
- Return type
- axonius_api_client.tools.parse_int_min_max(value, default=0, min_value=None, max_value=None)[source]¶
Pass.
- axonius_api_client.tools.safe_format(value, mapping=None, as_path=False, **kwargs)[source]¶
Pass.
- Parameters
value (
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)) –mapping (
typing.Optional
[typing.Dict
[str
,str
]]) –as_path (
bool
) –
- Return type
typing.TypeVar
(PathLike
,pathlib.Path
,str
,bytes
)
- axonius_api_client.tools.get_paths_format(*args, mapping=None)[source]¶
Pass.
- Parameters
mapping (
typing.Optional
[typing.Dict
[str
,str
]]) –- Return type
- axonius_api_client.tools.int_days_map(value, names=False)[source]¶
Pass.
- Parameters
value (
typing.Union
[str
,typing.List
[typing.Union
[str
,int
]]]) –names (
bool
) –
- Return type
- axonius_api_client.tools.lowish(value)[source]¶
Pass.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.log_or_exc(msg, error=True, log=<Logger axonius_api_client.tools (DEBUG)>, log_level='exception', log_join='\\n', exc_cls=<class 'axonius_api_client.exceptions.ToolsError'>, exc_args=None, **kwargs)[source]¶
Pass.
- Parameters
msg (
typing.List
[str
]) –error (
bool
) –log (
typing.Union
[typing.Callable
,logging.Logger
]) –log_level (
str
) –log_join (
str
) –exc_cls (
Exception
) –exc_args (
typing.Optional
[dict
]) –
- axonius_api_client.tools.coerce_io(value)[source]¶
Pass.
- Parameters
value (
typing.Union
[str
,bytes
,typing.IO
]) –- Return type
- axonius_api_client.tools.extract_kvs_auto(value, **kwargs)[source]¶
Pass.
- Parameters
value (
typing.Union
[str
,bytes
,typing.IO
]) –- Return type
- axonius_api_client.tools.extract_kvs_json(value, **kwargs)[source]¶
Pass.
- Parameters
value (
typing.Union
[str
,bytes
,typing.IO
]) –- Return type
- axonius_api_client.tools.is_callable(value, attr=None, default=None)[source]¶
Pass.
- Parameters
value (
typing.Any
) –attr (
typing.Optional
[str
]) –default (
typing.Optional
[typing.Any
]) –
- Return type
- axonius_api_client.tools.extract_kvs_csv(value=None, has_headers=False, split_kv='=', delimiter=',', **kwargs)[source]¶
Pass.
- axonius_api_client.tools.tilde_re(value)[source]¶
Pass.
- Parameters
value (
typing.Any
) –- Return type
typing.Union
[typing.TypeVar
(PatternLike
,typing.Pattern
,str
,bytes
),typing.Iterable
[typing.TypeVar
(PatternLike
,typing.Pattern
,str
,bytes
)]]
- axonius_api_client.tools.coerce_str_re(value, prefix='~')[source]¶
Convert a str into a pattern if value is str and starts with prefix.
- Parameters
value (t.Any) – value to convert to pattern
prefix (str, optional) – prefix to use to indicate value should be converted to a pattern
- Returns
t.Pattern if value is str or bytes and starts with prefix, else original value
- Return type
t.Any
- axonius_api_client.tools.human_size(value, decimals=2, error=True)[source]¶
Convert bytes to human-readable.
- axonius_api_client.tools.is_pattern(value)[source]¶
Check if value is a pattern.
- Parameters
value (t.Any) – value to check
- Returns
True if value is a re.Pattern; else False
- Return type
- axonius_api_client.tools.is_tty(value)[source]¶
Pass.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.check_tty(value, errmsg='unable to prompt')[source]¶
Pass.
- Parameters
value (
typing.Any
) –errmsg (
str
) –
- axonius_api_client.tools.get_secho_args(kwargs=None, key=None, **sargs)[source]¶
Pass.
- Parameters
kwargs (
typing.Optional
[dict
]) –key (
typing.Optional
[str
]) –
- axonius_api_client.tools.confirm(msgs=None, text=None, abort=False, default=False, text_confirm='Please confirm', join='\\n', check_stdin=True, **kwargs)[source]¶
Pass.
- Parameters
msgs (
typing.Union
[str
,typing.List
[str
],None
]) –text (
typing.Optional
[str
]) –abort (
bool
) –default (
bool
) –text_confirm (
str
) –join (
str
) –check_stdin (
bool
) –
- axonius_api_client.tools.coerce_prompt_confirm(value=None, prompt=False, **kwargs)[source]¶
Pass.
- Parameters
value (
typing.Optional
[typing.Any
]) –prompt (
bool
) –
- Return type
- axonius_api_client.tools.check_confirm_prompt(reason, src, msgs=None, value=None, prompt=False, **kwargs)[source]¶
Pass.
- Parameters
reason (
str
) –src (
typing.Any
) –msgs (
typing.Optional
[typing.List
[str
]]) –value (
typing.Optional
[typing.Any
]) –prompt (
bool
) –
- axonius_api_client.tools.csv_able(value, sep=',')[source]¶
Pass.
- Parameters
value (
typing.Union
[str
,typing.List
[str
],None
]) –sep (
str
) –
- Return type
- axonius_api_client.tools.is_list(value)[source]¶
Pass.
- Parameters
value (
typing.Any
) –- Return type
- axonius_api_client.tools.style_switch(text, switch=False, args_true={'bold': True, 'fg': 'green'}, args_false={'bold': True, 'fg': 'red'})[source]¶
Pass.
- axonius_api_client.tools.parse_value_copy(default, value=None, copy_prefix='Copy of', existing=None)[source]¶
Pass.
- Parameters
default (
str
) –value (
typing.Optional
[str
]) –copy_prefix (
str
) –existing (
typing.Optional
[typing.List
[str
]]) –
- Return type
- axonius_api_client.tools.parse_refresh(value=60, elapsed=True, refresh_elapsed=None)[source]¶
Check if an object should be refreshed.
Notes
If the value is bytes, it will be converted to string. If the value is string, it will try to safely coerce to float, int, or bool. If the value is True or False it will be returned as is. If the value is a float or int and refresh_elapsed is a float or int and elapsed is True it will return True if the value is greater than refresh_elapsed.
- Parameters
value (
typing.Any
) – The value to check.elapsed (
bool
) – If True, check if the value is an int or float and if it is greater than refresh_elapsed if refresh_elapsed is an int or float.refresh_elapsed (
typing.Union
[int
,float
,None
]) – The elapsed time to check against if elapsed is True.
- Return type
- axonius_api_client.tools.get_diff_seconds(start=None, stop=None, places=5)[source]¶
Pass.
- Parameters
start (
typing.Optional
[datetime.datetime
]) –stop (
typing.Optional
[datetime.datetime
]) –places (
typing.Optional
[int
]) –
- Return type
- axonius_api_client.tools.score_prefix(value, prefix=None, join='_')[source]¶
Prefix a value.
- Parameters
value (
str
) –prefix (
typing.Optional
[typing.List
[str
]]) –join (
str
) –
- Return type
- axonius_api_client.tools.get_mm_field(value)[source]¶
Get the marshmallow field from a dataclasses field.
- Parameters
value (
typing.Any
) – The field to check.- Returns
The marshmallow field.
- Return type
marshmallow.fields.Field
- axonius_api_client.tools.get_mm_description(value)[source]¶
Get the marshmallow description from a dataclasses field.
- Parameters
value (
dataclasses.Field
) – The field to check.- Returns
The marshmallow description.
- Return type
- axonius_api_client.tools.is_nested_schema(value)[source]¶
Check if a marshmallow field is a nested schema.
- Parameters
value (
marshmallow.fields.Field
) – The field to check.- Returns
True if the field is a nested schema.
- Return type
- axonius_api_client.tools.get_nested_schema(value)[source]¶
Get the nested schema from a marshmallow field.
- Parameters
value (
marshmallow.fields.Field
) – The field to check.- Returns
The nested schema.
- Return type
marshmallow.Schema
- axonius_api_client.tools.get_hint_type(value)[source]¶
Get the type from a type hint.
- Parameters
value (
typing.Any
) – If type hint, return the type.- Returns
The type if value is a type hint, else None.
- Return type
Any
- axonius_api_client.tools.is_subclass(value, expected_types=None, as_none=False)[source]¶
Determine if value is a subclass of the type for this field.
- Parameters
value (
typing.Any
) –expected_types (
typing.Optional
[typing.Any
]) –as_none (
bool
) –
- Return type
- axonius_api_client.tools.is_subclass_safe(value, expected_type)[source]¶
Check if value is a subclass of a type.
- Parameters
value (
typing.Any
) –expected_type (
typing.Any
) –
- Return type
- axonius_api_client.tools.trim_value_repr(value, max_length=30, trim_post='... trimmed {trim_count} characters')[source]¶
Trim the value to a maximum length and appends info about the number of trimmed characters.
- Parameters
value (
typing.Any
) – The input value to be trimmed.max_length (
typing.Optional
[int
]) – The maximum allowed length of the value repr.trim_post (
typing.Optional
[str
]) – The string to add
- Returns
The trimmed value representation with info about the number of trimmed characters.
- Return type
- axonius_api_client.tools.coerce_seconds(value=None)[source]¶
Coerce a value to seconds.
- Parameters
value (
typing.Optional
[typing.TypeVar
(TypeFloat
,float
,int
,str
,bytes
)]) –- Return type
- axonius_api_client.tools.coerce_delta(value=None)[source]¶
Coerce a value to a timedelta.
- Parameters
value (
typing.Optional
[typing.TypeVar
(TypeDelta
,str
,bytes
,float
,int
,datetime.timedelta
)]) – value to coerce - if None or already a timedelta, return as is, otherwise pass tocoerce_seconds()
and return as a timedelta if it returns a float, otherwise return None- Return type
- axonius_api_client.tools.coerce_date_delta(value=None, add=None, subtract=None)[source]¶
Coerce a value to a date.
Notes
Value will be parsed by
dt_parse()
into a datetime.datetime or None. If add or subtract are provided, value will be added to or subtracted from the parsed value or now if value not provided.- Parameters
value (
typing.Optional
[typing.TypeVar
(TypeDate
,str
,bytes
,datetime.datetime
,datetime.timedelta
)]) – value to coerceadd (
typing.Optional
[typing.TypeVar
(TypeDelta
,str
,bytes
,float
,int
,datetime.timedelta
)]) – seconds to add to valuesubtract (
typing.Optional
[typing.TypeVar
(TypeDelta
,str
,bytes
,float
,int
,datetime.timedelta
)]) – seconds to subtract from value
- Returns
coerced value
- Return type