def read_text_file(filename):<EOL>
with open(filename, '<STR_LIT:rb>') as fp:<EOL><INDENT>data = fp.read()<EOL><DEDENT>encodings = ['<STR_LIT:utf-8>', locale.getpreferredencoding(False), '<STR_LIT>']<EOL>for enc in encodings:<EOL><INDENT>try:<EOL><INDENT>data = data.decode(enc)  <EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>continue<EOL><DEDENT>break<EOL><DEDENT>assert not isinstance(data, bytes)  <EOL>return data<EOL>
Return the contents of *filename*.

    Try to decode the file contents with utf-8, the preferred system encoding
    (e.g., cp1252 on some Windows machines), and latin1, in that order.
    Decoding a byte string with latin1 will never raise an error. In the worst
    case, the returned string will contain some garbage characters.