MCPcopy Index your code
hub / github.com/python/cpython / TextIOWrapper

Class TextIOWrapper

Lib/_pyio.py:2047–2727  ·  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

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

Callers 7

_load_testfileFunction · 0.90
openFunction · 0.90
parseMethod · 0.90
vfsopenFunction · 0.90
_io_wrapperFunction · 0.90
openFunction · 0.85

Calls

no outgoing calls

Tested by 2

_load_testfileFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…