

def reopen_encoded(fileobj, mode='r', fallback_encoding=None):
    'Makes sure that a file was opened with some valid encoding.\n\n    Arguments:\n        fileobj (file): The file-object.\n        mode (str, optional): The mode in which to re-open the file.\n        fallback_encoding (str, optional): The encoding in which to re-open\n            the file if it does not specify an encoding itself.\n\n    Returns:\n        file: The re-opened file.\n\n    '
    encoding = determine_encoding(fileobj.name, fallback_encoding)
    fileobj.close()
    return open(fileobj.name, mode, encoding=encoding)

dataset/ETHPy150Open c-w/Gutenberg/gutenberg/_util/os.py reopen_encoded/original