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

Method save

Lib/pickle.py:546–618  ·  view source on GitHub ↗
(self, obj, save_persistent_id=True)

Source from the content-addressed store, hash-verified

544 return GET + repr(i).encode("ascii") + b'\n'
545
546 def save(self, obj, save_persistent_id=True):
547 self.framer.commit_frame()
548
549 # Check for persistent id (defined by a subclass)
550 if save_persistent_id:
551 pid = self.persistent_id(obj)
552 if pid is not None:
553 self.save_pers(pid)
554 return
555
556 # Check the memo
557 x = self.memo.get(id(obj))
558 if x is not None:
559 self.write(self.get(x[0]))
560 return
561
562 rv = NotImplemented
563 reduce = getattr(self, "reducer_override", _NoValue)
564 if reduce is not _NoValue:
565 rv = reduce(obj)
566
567 if rv is NotImplemented:
568 # Check the type dispatch table
569 t = type(obj)
570 f = self.dispatch.get(t)
571 if f is not None:
572 f(self, obj) # Call unbound method with explicit self
573 return
574
575 # Check private dispatch table if any, or else
576 # copyreg.dispatch_table
577 reduce = getattr(self, 'dispatch_table', dispatch_table).get(t, _NoValue)
578 if reduce is not _NoValue:
579 rv = reduce(obj)
580 else:
581 # Check for a class with a custom metaclass; treat as regular
582 # class
583 if issubclass(t, type):
584 self.save_global(obj)
585 return
586
587 # Check for a __reduce_ex__ method, fall back to __reduce__
588 reduce = getattr(obj, "__reduce_ex__", _NoValue)
589 if reduce is not _NoValue:
590 rv = reduce(self.proto)
591 else:
592 reduce = getattr(obj, "__reduce__", _NoValue)
593 if reduce is not _NoValue:
594 rv = reduce()
595 else:
596 raise PicklingError(f"Can't pickle {_T(t)} object")
597
598 # Check for string returned by reduce(), meaning "save as global"
599 if isinstance(rv, str):
600 self.save_global(obj, rv)
601 return
602
603 try:

Callers 3

dumpMethod · 0.95
save_persMethod · 0.95
save_globalMethod · 0.95

Calls 15

persistent_idMethod · 0.95
save_persMethod · 0.95
getMethod · 0.95
save_globalMethod · 0.95
save_reduceMethod · 0.95
idFunction · 0.85
getattrFunction · 0.85
issubclassFunction · 0.85
PicklingErrorClass · 0.85
_TFunction · 0.85
isinstanceFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected