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

Function read_string4

Lib/pickletools.py:438–458  ·  view source on GitHub ↗

r""" >>> import io >>> read_string4(io.BytesIO(b"\x00\x00\x00\x00abc")) '' >>> read_string4(io.BytesIO(b"\x03\x00\x00\x00abcdef")) 'abc' >>> read_string4(io.BytesIO(b"\x00\x00\x00\x03abcdef")) Traceback (most recent call last): ... ValueError: expected 50331648 by

(f)

Source from the content-addressed store, hash-verified

436
437
438def read_string4(f):
439 r"""
440 >>> import io
441 >>> read_string4(io.BytesIO(b"\x00\x00\x00\x00abc"))
442 ''
443 >>> read_string4(io.BytesIO(b"\x03\x00\x00\x00abcdef"))
444 'abc'
445 >>> read_string4(io.BytesIO(b"\x00\x00\x00\x03abcdef"))
446 Traceback (most recent call last):
447 ...
448 ValueError: expected 50331648 bytes in a string4, but only 6 remain
449 """
450
451 n = read_int4(f)
452 if n < 0:
453 raise ValueError("string4 byte count < 0: %d" % n)
454 data = f.read(n)
455 if len(data) == n:
456 return data.decode("latin-1")
457 raise ValueError("expected %d bytes in a string4, but only %d remain" %
458 (n, len(data)))
459
460string4 = ArgumentDescriptor(
461 name="string4",

Callers

nothing calls this directly

Calls 3

read_int4Function · 0.85
readMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…