toolchest.decor

class toolchest.decor.PrettyTable(column_names)[source]

Bases: object

add_row(row)[source]
get_string()[source]
class toolchest.decor.Spinner(startmsg='', endmsg='')[source]

Bases: object

toolchest.decor.ask_yesno(message)[source]
toolchest.decor.box(msg)[source]
toolchest.decor.color_string(string, color)[source]
toolchest.decor.exithandler(sig, frame)[source]
toolchest.decor.line(msg)[source]
toolchest.decor.usleep(msec)[source]

toolchest.genericargs

class toolchest.genericargs.GenericArgs[source]

Bases: dict

toolchest.hash

toolchest.hash.generate_hash(list_to_hash, validator=<function validate_string>)[source]

Takes a list of strings in any order, sorts them for consistency, and generates a cryptographic hash to provide a unique representation of this combination of strings.

Parameters
  • list_to_hash (list) – List of Strings to turn into a hash

  • validator (func) – A function to use to validate the format of items in the list of Strings. This function should throw a ValueError if the pattern does not match.

Returns

A String that is a hash of the passed in list.

Raises

ValueError – If the passed in list cannot be validated with the passed in validator, a ValueError is thrown.

toolchest.introspect

Methods related to introspection of a class

toolchest.introspect.build_attrs(instance)[source]

Build a dict of attributes on a given instance

Parameters

instance – An instance of some class

Returns

Dict of all object attributes that are properties

toolchest.introspect.build_repr(instance)[source]

Generic way to implement a __repr__ method for classes using properties

Parameters

instance – An instance of some class

Returns

String that can be eval’ed to an object

toolchest.introspect.check_if_property(instance, prop)[source]

Check if a given value is a property on the specified class instance

Parameters
  • instance – An instance of some class

  • prop – A value to check

Returns

True or False

toolchest.strutil

toolchest.strutil.list_or_splitstr(arg)[source]
toolchest.strutil.regex_chars(arg)[source]
toolchest.strutil.regex_match(pattern, arg)[source]
toolchest.strutil.split_file(arg)[source]

toolchest.yaml

Yaml related tools

class toolchest.yaml.IndentDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)[source]

Bases: yaml.dumper.Dumper

Custom yaml dumper to ensure elements are indented

increase_indent(flow=False, indentless=False)[source]
toolchest.yaml.parse(yaml_data, logger=None)[source]

Safely parse yaml data

Parameters
  • yaml_data – A string of yaml data to be parsed

  • logger – Optional logger for potential errors

Returns

A dictionary formed out of the yaml data

toolchest.yaml.write(filename, yaml_data, sort_keys=False)[source]

Write out yaml data to a file

Parameters
  • filename – The name of the file to write the data

  • yaml_data – A string of yaml data to be parsed

  • sort_keys – Have the yaml data’s keys sorted on write

Returns

None