def _adapt_snapshot(self, restorator, snapshot): if self._source_ver is not None: # TODO: If external adapter is needed change this to a cast if IVersionAdapter.providedBy(restorator): adapter = IVersionAdapter(restorator) snapshot = adapter.adapt_version(snapshot, self._source_ver, self._target_ver) return snapshot
def flatten_instance(self, value, caps, freezing): self.check_capabilities(Capabilities.instance_values, value, caps, freezing) referenceable = getattr(value, "referenceable", True) if referenceable: deref = self._prepare(value) if deref is not None: return deref snapshot = value.snapshot() if self._source_ver is not None: # TODO: If external adapter is needed change this to a cast if IVersionAdapter.providedBy(value): adapter = IVersionAdapter(value) snapshot = adapter.adapt_version(snapshot, self._source_ver, self._target_ver) dump = self.flatten_value(snapshot, caps, freezing) if freezing: packer, data = self.pack_frozen_instance, [dump] else: packer, data = (self.pack_instance, [[self.pack_type_name, value.type_name], dump]) if referenceable: return self._preserve(value, packer, data) else: return packer, data
def _adapt_snapshot(self, restorator, snapshot): try: adapter = IVersionAdapter(restorator) except TypeError: pass else: target = self.get_target_ver(restorator, snapshot) source = self.get_source_ver(restorator, snapshot) if target is not None and target != source: snapshot = adapter.adapt_version(snapshot, source, target) return snapshot