def get_polymorphic_class(data): try: kls = ClassTypedSerializer.getClass( data[Deserializer.POLIMORPHIC_KEYWORD]) except KeyError: raise BiiSerializationException("Cant deserialize object without know his class!! " \ + str(data)) return kls
def deserialize(data): try: si = ServerInfo() si.version = ClientVersion(data[ServerInfo.VERSION]) si.last_compatible = ClientVersion(data[ServerInfo.COMPATIBLE]) si.download_url = data[ServerInfo.URL] si.messages = data[ServerInfo.MESSAGES] return si except Exception as e: raise BiiSerializationException(e)
def deserialize(data): try: hive = Hive() hive.hive_dependencies = HiveDependencies.deserialize( data[Hive.SERIAL_HIVE_DEPENDENCIES]) hive._cells = SetDeserializer(BlockCellName).deserialize(data[Hive.SERIAL_CELLS_KEY]) hive.settings = Settings.deserialize(data[Hive.SERIAL_SETTINGS]) return hive except Exception as e: raise BiiSerializationException(e)
def deserialize(data): try: names = ListDeserializer(BlockCellName).deserialize( data[Closure.SERIAL_NAMES]) d = ResourceDeserializer(CellDeserializer(ID), ContentDeserializer(ID)) resources = ListDeserializer(d).deserialize( data[Closure.SERIAL_RESOURCES]) versions = ListDeserializer(BlockVersion).deserialize( data[Closure.SERIAL_VERSIONS]) return Closure(dict(zip(names, zip(resources, versions)))) except Exception as e: raise BiiSerializationException(e)
def deserialize(self, data): '''From dictionary to object Content''' if data is None: return None try: return Content( id_=self.id_type.deserialize(data[Content.SERIAL_ID_KEY]), load=Blob.deserialize(data[Content.SERIAL_LOAD_KEY]), parser=Parser.deserialize(data[Content.SERIAL_PARSER_KEY]), is_parsed=data[Content.SERIAL_IS_PARSED_KEY], ) except Exception as e: raise BiiSerializationException( 'Could not deserialize Content: %s' % str(e))
def deserialize(data): try: res = HiveDependencies() res.dep_table = BlockVersionTable.deserialize( data[HiveDependencies.SERIAL_DEP_TABLE]) res.references = References.deserialize( data[HiveDependencies.SERIAL_REFERENCES]) res.closure = Closure.deserialize( data[HiveDependencies.SERIAL_CLOSURE]) res.src_graph = BlockVersionGraph.deserialize( data[HiveDependencies.SERIAL_SRC_GRAPH]) res.dep_graph = BlockVersionGraph.deserialize( data[HiveDependencies.SERIAL_DEP_GRAPH]) return res except Exception as e: raise BiiSerializationException(e)
def assign_class_type(self, ret, obj, key=Deserializer.POLIMORPHIC_KEYWORD): '''For serialized class names''' if obj is None: return ret # print "OBJETO TIPADO!!" if not isinstance(obj, type): obj = obj.__class__ tp = ClassTypedSerializer.getValue(obj) #print "DE CLASE: " + str(obj.__class__)+" ->"+str(tp)+" ->"+str(obj) if tp is None: raise BiiSerializationException("Add class for %s" % str(obj)) self.append_values(ret, {key: tp})
def deserialize(self, data): if data is None: return None try: kls = Deserializer.get_polymorphic_class(data) r = kls.deserialize(data) r.name = BlockCellName(data[Cell.SERIAL_NAME_KEY]) r.root = ID.deserialize(data[Cell.SERIAL_ROOT_KEY]) r.ID = self.id_type.deserialize(data[Cell.SERIAL_ID_KEY]) r.type = BiiType(data[Cell.SERIAL_TYPE_KEY]) r.hasMain = data[Cell.SERIAL_MAIN_KEY] try: r.dependencies.cell_name = r.name except AttributeError: pass return r except Exception as e: tb = traceback.format_exc() logger.warning(tb) raise BiiSerializationException(e)