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

Method _read_chunk

Lib/_pyio.py:2340–2380  ·  view source on GitHub ↗

Read and decode the next chunk of data from the BufferedReader.

(self)

Source from the content-addressed store, hash-verified

2338 self._decoded_chars_used -= n
2339
2340 def _read_chunk(self):
2341 """
2342 Read and decode the next chunk of data from the BufferedReader.
2343 """
2344
2345 # The return value is True unless EOF was reached. The decoded
2346 # string is placed in self._decoded_chars (replacing its previous
2347 # value). The entire input chunk is sent to the decoder, though
2348 # some of it may remain buffered in the decoder, yet to be
2349 # converted.
2350
2351 if self._decoder is None:
2352 raise ValueError("no decoder")
2353
2354 if self._telling:
2355 # To prepare for tell(), we need to snapshot a point in the
2356 # file where the decoder's input buffer is empty.
2357
2358 dec_buffer, dec_flags = self._decoder.getstate()
2359 # Given this, we know there was a valid snapshot point
2360 # len(dec_buffer) bytes ago with decoder state (b'', dec_flags).
2361
2362 # Read a chunk, decode it, and put the result in self._decoded_chars.
2363 if self._has_read1:
2364 input_chunk = self.buffer.read1(self._CHUNK_SIZE)
2365 else:
2366 input_chunk = self.buffer.read(self._CHUNK_SIZE)
2367 eof = not input_chunk
2368 decoded_chars = self._decoder.decode(input_chunk, eof)
2369 self._set_decoded_chars(decoded_chars)
2370 if decoded_chars:
2371 self._b2cratio = len(input_chunk) / len(self._decoded_chars)
2372 else:
2373 self._b2cratio = 0.0
2374
2375 if self._telling:
2376 # At the snapshot point, len(dec_buffer) bytes before the read,
2377 # the next input to be decoded is dec_buffer + input_chunk.
2378 self._snapshot = (dec_flags, dec_buffer + input_chunk)
2379
2380 return not eof
2381
2382 def _pack_cookie(self, position, dec_flags=0,
2383 bytes_to_feed=0, need_eof=False, chars_to_skip=0):

Callers 2

readMethod · 0.95
readlineMethod · 0.95

Calls 5

_set_decoded_charsMethod · 0.95
getstateMethod · 0.45
read1Method · 0.45
readMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected