MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / save_str

Method save_str

tools/python-3.11.9-amd64/Lib/pickle.py:851–871  ·  view source on GitHub ↗
(self, obj)

Source from the content-addressed store, hash-verified

849 dispatch[PickleBuffer] = save_picklebuffer
850
851 def save_str(self, obj):
852 if self.bin:
853 encoded = obj.encode('utf-8', 'surrogatepass')
854 n = len(encoded)
855 if n <= 0xff and self.proto >= 4:
856 self.write(SHORT_BINUNICODE + pack("<B", n) + encoded)
857 elif n > 0xffffffff and self.proto >= 4:
858 self._write_large_bytes(BINUNICODE8 + pack("<Q", n), encoded)
859 elif n >= self.framer._FRAME_SIZE_TARGET:
860 self._write_large_bytes(BINUNICODE + pack("<I", n), encoded)
861 else:
862 self.write(BINUNICODE + pack("<I", n) + encoded)
863 else:
864 # Escape what raw-unicode-escape doesn't, but memoize the original.
865 tmp = obj.replace("\\", "\\u005c")
866 tmp = tmp.replace("\0", "\\u0000")
867 tmp = tmp.replace("\n", "\\u000a")
868 tmp = tmp.replace("\r", "\\u000d")
869 tmp = tmp.replace("\x1a", "\\u001a") # EOF on DOS
870 self.write(UNICODE + tmp.encode('raw-unicode-escape') + b'\n')
871 self.memoize(obj)
872 dispatch[str] = save_str
873
874 def save_tuple(self, obj):

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected