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

Method _read_chunk

Lib/_pyio.py:2316–2356  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

2314 self._decoded_chars_used -= n
2315
2316 def _read_chunk(self):
2317 """
2318 Read and decode the next chunk of data from the BufferedReader.
2319 """
2320
2321 # The return value is True unless EOF was reached. The decoded
2322 # string is placed in self._decoded_chars (replacing its previous
2323 # value). The entire input chunk is sent to the decoder, though
2324 # some of it may remain buffered in the decoder, yet to be
2325 # converted.
2326
2327 if self._decoder is None:
2328 raise ValueError("no decoder")
2329
2330 if self._telling:
2331 # To prepare for tell(), we need to snapshot a point in the
2332 # file where the decoder's input buffer is empty.
2333
2334 dec_buffer, dec_flags = self._decoder.getstate()
2335 # Given this, we know there was a valid snapshot point
2336 # len(dec_buffer) bytes ago with decoder state (b'', dec_flags).
2337
2338 # Read a chunk, decode it, and put the result in self._decoded_chars.
2339 if self._has_read1:
2340 input_chunk = self.buffer.read1(self._CHUNK_SIZE)
2341 else:
2342 input_chunk = self.buffer.read(self._CHUNK_SIZE)
2343 eof = not input_chunk
2344 decoded_chars = self._decoder.decode(input_chunk, eof)
2345 self._set_decoded_chars(decoded_chars)
2346 if decoded_chars:
2347 self._b2cratio = len(input_chunk) / len(self._decoded_chars)
2348 else:
2349 self._b2cratio = 0.0
2350
2351 if self._telling:
2352 # At the snapshot point, len(dec_buffer) bytes before the read,
2353 # the next input to be decoded is dec_buffer + input_chunk.
2354 self._snapshot = (dec_flags, dec_buffer + input_chunk)
2355
2356 return not eof
2357
2358 def _pack_cookie(self, position, dec_flags=0,
2359 bytes_to_feed=0, need_eof=False, chars_to_skip=0):

Callers 2

readMethod · 0.95
readlineMethod · 0.95

Calls 6

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

Tested by

no test coverage detected