| 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 |
| 2081 | self._decoded_chars_used = 0 # offset into _decoded_chars for read() |
| 2082 | self._snapshot = None # info for reconstructing decoder state |
| 2083 | self._seekable = self._telling = self.buffer.seekable() |
| 2084 | self._has_read1 = hasattr(self.buffer, 'read1') |
| 2085 | self._configure(encoding, errors, newline, |
| 2086 | line_buffering, write_through) |
| 2087 | |
| 2088 | def _check_newline(self, newline): |
| 2089 | if newline is not None and not isinstance(newline, str): |