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

Function read_unicodestring1

Lib/pickletools.py:629–653  ·  view source on GitHub ↗

r""" >>> import io >>> s = 'abcd\uabcd' >>> enc = s.encode('utf-8') >>> enc b'abcd\xea\xaf\x8d' >>> n = bytes([len(enc)]) # little-endian 1-byte length >>> t = read_unicodestring1(io.BytesIO(n + enc + b'junk')) >>> s == t True >>> read_unicodestring1(io.Byte

(f)

Source from the content-addressed store, hash-verified

627
628
629def read_unicodestring1(f):
630 r"""
631 >>> import io
632 >>> s = 'abcd\uabcd'
633 >>> enc = s.encode('utf-8')
634 >>> enc
635 b'abcd\xea\xaf\x8d'
636 >>> n = bytes([len(enc)]) # little-endian 1-byte length
637 >>> t = read_unicodestring1(io.BytesIO(n + enc + b'junk'))
638 >>> s == t
639 True
640
641 >>> read_unicodestring1(io.BytesIO(n + enc[:-1]))
642 Traceback (most recent call last):
643 ...
644 ValueError: expected 7 bytes in a unicodestring1, but only 6 remain
645 """
646
647 n = read_uint1(f)
648 assert n >= 0
649 data = f.read(n)
650 if len(data) == n:
651 return str(data, 'utf-8', 'surrogatepass')
652 raise ValueError("expected %d bytes in a unicodestring1, but only %d "
653 "remain" % (n, len(data)))
654
655unicodestring1 = ArgumentDescriptor(
656 name="unicodestring1",

Callers

nothing calls this directly

Calls 3

read_uint1Function · 0.85
strFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…