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

Method save_str

Lib/pickle.py:926–946  ·  view source on GitHub ↗
(self, obj)

Source from the content-addressed store, hash-verified

924 dispatch[PickleBuffer] = save_picklebuffer
925
926 def save_str(self, obj):
927 if self.bin:
928 encoded = obj.encode('utf-8', 'surrogatepass')
929 n = len(encoded)
930 if n <= 0xff and self.proto >= 4:
931 self.write(SHORT_BINUNICODE + pack("<B", n) + encoded)
932 elif n > 0xffffffff and self.proto >= 4:
933 self._write_large_bytes(BINUNICODE8 + pack("<Q", n), encoded)
934 elif n >= self.framer._FRAME_SIZE_TARGET:
935 self._write_large_bytes(BINUNICODE + pack("<I", n), encoded)
936 else:
937 self.write(BINUNICODE + pack("<I", n) + encoded)
938 else:
939 # Escape what raw-unicode-escape doesn't, but memoize the original.
940 tmp = obj.replace("\\", "\\u005c")
941 tmp = tmp.replace("\0", "\\u0000")
942 tmp = tmp.replace("\n", "\\u000a")
943 tmp = tmp.replace("\r", "\\u000d")
944 tmp = tmp.replace("\x1a", "\\u001a") # EOF on DOS
945 self.write(UNICODE + tmp.encode('raw-unicode-escape') + b'\n')
946 self.memoize(obj)
947 dispatch[str] = save_str
948
949 def save_tuple(self, obj):

Callers

nothing calls this directly

Calls 6

memoizeMethod · 0.95
packFunction · 0.90
lenFunction · 0.85
encodeMethod · 0.45
writeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected