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

https://github.com/localstack/localstack/blob/5a5edcd9d9ccbd6a56f23d71e3a1131b8c814996/localstack/utils/common.py#L324
mode = 'a' if append else 'w+'
    if not isinstance(content, six.string_types):
        mode = mode + 'b'
    
    mkdir(os.path.dirname(file))
    
    with open(file, mode) as f:
        f.write(content)
        f.flush()
def load_file(file_path, default=None, mode=None):
    if not os.path.isfile(file_path):
        return default
    if not mode:
        mode = 'r'
    with open(file_path, mode) as f:
        result = f.read()
    return result
def get_or_create_file(file_path, content=None):
    if os.path.exists(file_path):
        return load_file(file_path)
    content = '{}' if content is None else content
    try:
        save_file(file_path, content)
        return content
    except Exception:
        pass
def to_str(obj, encoding=DEFAULT_ENCODING, errors='strict'):