MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / EncodedFile

Function EncodedFile

tools/python-3.11.9-amd64/Lib/codecs.py:932–966  ·  view source on GitHub ↗

Return a wrapped version of file which provides transparent encoding translation. Data written to the wrapped file is decoded according to the given data_encoding and then encoded to the underlying file using file_encoding. The intermediate data type w

(file, data_encoding, file_encoding=None, errors='strict')

Source from the content-addressed store, hash-verified

930 raise
931
932def EncodedFile(file, data_encoding, file_encoding=None, errors='strict'):
933
934 """ Return a wrapped version of file which provides transparent
935 encoding translation.
936
937 Data written to the wrapped file is decoded according
938 to the given data_encoding and then encoded to the underlying
939 file using file_encoding. The intermediate data type
940 will usually be Unicode but depends on the specified codecs.
941
942 Bytes read from the file are decoded using file_encoding and then
943 passed back to the caller encoded using data_encoding.
944
945 If file_encoding is not given, it defaults to data_encoding.
946
947 errors may be given to define the error handling. It defaults
948 to 'strict' which causes ValueErrors to be raised in case an
949 encoding error occurs.
950
951 The returned wrapped file object provides two extra attributes
952 .data_encoding and .file_encoding which reflect the given
953 parameters of the same name. The attributes can be used for
954 introspection by Python programs.
955
956 """
957 if file_encoding is None:
958 file_encoding = data_encoding
959 data_info = lookup(data_encoding)
960 file_info = lookup(file_encoding)
961 sr = StreamRecoder(file, data_info.encode, data_info.decode,
962 file_info.streamreader, file_info.streamwriter, errors)
963 # Add attributes to simplify introspection
964 sr.data_encoding = data_encoding
965 sr.file_encoding = file_encoding
966 return sr
967
968### Helpers for codec lookup
969

Callers 1

codecs.pyFile · 0.85

Calls 2

StreamRecoderClass · 0.85
lookupFunction · 0.70

Tested by

no test coverage detected