Пример #1
0
 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
Пример #2
0
    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
Пример #3
0
Файл: base.py Проект: f3at/feat
 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