Ref : https://github.com/python/cpython/pull/25174

https://github.com/localstack/localstack/blob/5a5edcd9d9ccbd6a56f23d71e3a1131b8c814996/localstack/utils/common.py#L324
""" If ``obj`` is an instance of ``binary_type``, return
    ``obj.decode(encoding, errors)``, otherwise return ``obj`` """
    return obj.decode(encoding, errors) if isinstance(obj, six.binary_type) else obj
def to_bytes(obj, encoding=DEFAULT_ENCODING, errors='strict'):
    """ If ``obj`` is an instance of ``text_type``, return
    ``obj.encode(encoding, errors)``, otherwise return ``obj`` """
    return obj.encode(encoding, errors) if isinstance(obj, six.text_type) else obj
def str_insert(string, index, content):
    """ Insert a substring into an existing string at a certain index. """
    return '%s%s%s' % (string[:index], content, string[index:])
def str_remove(string, index, end_index=None):
    """ Remove a substring from an existing string at a certain from-to index range. """
    end_index = end_index or (index + 1)
    return '%s%s' % (string[:index], string[end_index:])
def is_sub_dict(child_dict, parent_dict):
    """ Returns whether the first dict is a sub-dict (subset) of the second dict. """
    return all(parent_dict.get(key) == val for key, val in child_dict.items())
def cleanup(files=True, env=ENV_DEV, quiet=True):
    if files:
        cleanup_tmp_files()
def cleanup_threads_and_processes(quiet=True, debug=False):
    for thread in TMP_THREADS:
        if thread:
            try:
                print_debug('[shutdown] Cleaning up thread: %s' % thread, debug)
                if hasattr(thread, 'shutdown'):
                    thread.shutdown()