def Unserialize(data): """ We expect here a string containing a whole packet object in text form. Here is used a special libraries in ``twisted.spread``: ``banana`` and ``jelly`` to do that work. This stuff is placed in the ``lib.misc.StringToObject``. So return a real object in the memory from given string. All class fields are loaded, signature can be verified to be sure - it was truly original string. """ if data is None: return None # lg.out(10, 'signed.Unserialize %d bytes, type is %s' % (len(data), str(type(data)))) newobject = misc.StringToObject(data) if newobject is None: lg.warn("result is None") return None if not isinstance(newobject, types.InstanceType): lg.warn("not an instance: " + str(newobject)) return None if not str(newobject.__class__).count('signed.Packet'): lg.warn("not a packet: " + str(newobject.__class__)) return None if not hasattr(newobject, 'KeyID'): setattr(newobject, 'KeyID', None) if not hasattr(newobject, 'Packets'): setattr(newobject, 'Packets', []) return newobject
def Unserialize(data, decrypt_key=None): """ A method to create a ``encrypted.Block`` instance from input string. """ newobject = misc.StringToObject(data) setattr(newobject, 'DecryptKey', decrypt_key) return newobject
def deserialize(input_string): try: message_obj = misc.StringToObject(input_string) except: lg.exc() return None if not hasattr(message_obj, 'sender'): setattr(message_obj, 'sender', None) return message_obj