Beispiel #1
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 IVersionAdapter.providedBy(value):
            source = self.get_source_ver(value, snapshot)
            target = self.get_target_ver(value, snapshot)
            if target is not None:
                if target != source:
                    snapshot = value.adapt_version(snapshot, source, target)
                value.store_version(snapshot, target, self._version_atom)

        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 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 IVersionAdapter.providedBy(value):
            source = self.get_source_ver(value, snapshot)
            target = self.get_target_ver(value, snapshot)
            if target is not None:
                if target != source:
                    snapshot = value.adapt_version(snapshot, source, target)
                value.store_version(snapshot, target, self._version_atom)

        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
    def convert(self, data):
        try:
            # Pre-convert the data if a convertor was specified
            converted = self.pre_convertion(data)
            # Unpack the first level of values
            unpacked = self.unpack_data(converted)
            # Continue unpacking level by level
            self.finish_unpacking()
            # Inform object that it has migrated if this is a case
            if (IVersionAdapter.providedBy(unpacked) and self._migrated):
                unpacked.set_migrated()

            # Should be finished by now
            return unpacked
        finally:
            # Reset the state to cleanup all references
            self.reset()
Beispiel #5
0
    def convert(self, data):
        try:
            # Pre-convert the data if a convertor was specified
            converted = self.pre_convertion(data)
            # Unpack the first level of values
            unpacked = self.unpack_data(converted)
            # Continue unpacking level by level
            self.finish_unpacking()
            # Inform object that it has migrated if this is a case
            if (IVersionAdapter.providedBy(unpacked) and
                    self._migrated):
                unpacked.set_migrated()

            # Should be finished by now
            return unpacked
        finally:
            # Reset the state to cleanup all references
            self.reset()