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

Method save

tools/python-3.11.9-amd64/Lib/pickle.py:535–603  ·  view source on GitHub ↗
(self, obj, save_persistent_id=True)

Source from the content-addressed store, hash-verified

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

Callers 3

dumpMethod · 0.95
save_persMethod · 0.95
save_globalMethod · 0.95

Calls 12

persistent_idMethod · 0.95
save_persMethod · 0.95
getMethod · 0.95
save_globalMethod · 0.95
save_reduceMethod · 0.95
PicklingErrorClass · 0.85
commit_frameMethod · 0.80
reduceFunction · 0.70
fFunction · 0.70
idFunction · 0.50
typeClass · 0.50
writeMethod · 0.45

Tested by

no test coverage detected