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

Method __init__

Lib/_pyio.py:2080–2110  ·  view source on GitHub ↗
(self, buffer, encoding=None, errors=None, newline=None,
                 line_buffering=False, write_through=False)

Source from the content-addressed store, hash-verified

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
2105 self._decoded_chars_used = 0 # offset into _decoded_chars for read()
2106 self._snapshot = None # info for reconstructing decoder state
2107 self._seekable = self._telling = self.buffer.seekable()
2108 self._has_read1 = hasattr(self.buffer, 'read1')
2109 self._configure(encoding, errors, newline,
2110 line_buffering, write_through)
2111
2112 def _check_newline(self, newline):
2113 if newline is not None and not isinstance(newline, str):

Callers 1

test_constructorMethod · 0.95

Calls 6

_check_newlineMethod · 0.95
_get_locale_encodingMethod · 0.95
_configureMethod · 0.95
text_encodingFunction · 0.85
lookupMethod · 0.45
seekableMethod · 0.45

Tested by 1

test_constructorMethod · 0.76