MCPcopy Index your code
hub / github.com/RustPython/RustPython / TextIOWrapper

Class TextIOWrapper

Lib/_pyio.py:2023–2703  ·  view source on GitHub ↗

r"""Character and line based layer over a BufferedIOBase object, buffer. encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale.getencoding(). errors determines the strictness of encoding and decoding (see the codecs.register)

Source from the content-addressed store, hash-verified

2021
2022
2023class TextIOWrapper(TextIOBase):
2024
2025 r"""Character and line based layer over a BufferedIOBase object, buffer.
2026
2027 encoding gives the name of the encoding that the stream will be
2028 decoded or encoded with. It defaults to locale.getencoding().
2029
2030 errors determines the strictness of encoding and decoding (see the
2031 codecs.register) and defaults to "strict".
2032
2033 newline can be None, '', '\n', '\r', or '\r\n'. It controls the
2034 handling of line endings. If it is None, universal newlines is
2035 enabled. With this enabled, on input, the lines endings '\n', '\r',
2036 or '\r\n' are translated to '\n' before being returned to the
2037 caller. Conversely, on output, '\n' is translated to the system
2038 default line separator, os.linesep. If newline is any other of its
2039 legal values, that newline becomes the newline when the file is read
2040 and it is returned untranslated. On output, '\n' is converted to the
2041 newline.
2042
2043 If line_buffering is True, a call to flush is implied when a call to
2044 write contains a newline character.
2045 """
2046
2047 _CHUNK_SIZE = 2048
2048
2049 # Initialize _buffer as soon as possible since it's used by __del__()
2050 # which calls close()
2051 _buffer = None
2052
2053 # The write_through argument has no effect here since this
2054 # implementation always writes through. The argument is present only
2055 # so that the signature can match the signature of the C version.
2056 def __init__(self, buffer, encoding=None, errors=None, newline=None,
2057 line_buffering=False, write_through=False):
2058 self._check_newline(newline)
2059 encoding = text_encoding(encoding)
2060
2061 if encoding == "locale":
2062 encoding = self._get_locale_encoding()
2063
2064 if not isinstance(encoding, str):
2065 raise ValueError("invalid encoding: %r" % encoding)
2066
2067 if not codecs.lookup(encoding)._is_text_encoding:
2068 msg = "%r is not a text encoding"
2069 raise LookupError(msg % encoding)
2070
2071 if errors is None:
2072 errors = "strict"
2073 else:
2074 if not isinstance(errors, str):
2075 raise ValueError("invalid errors: %r" % errors)
2076 if _CHECK_ERRORS:
2077 codecs.lookup_error(errors)
2078
2079 self._buffer = buffer
2080 self._decoded_chars = '' # buffer for text returned from decoder

Callers 7

openFunction · 0.90
parseMethod · 0.90
magic_openFunction · 0.90
_io_wrapperFunction · 0.90
stdlib_io.pyFile · 0.90
openFunction · 0.70

Calls

no outgoing calls

Tested by 1