def test_alias(self): class OldObj(object): def __init__(self): self.x = 1 self.name = "jiba" cerealizer.register(OldObj) o = OldObj() s = cerealizer.dumps(o) imp.reload(cerealizer) class NewObj(object): def __init__(self): self.x = 2 self.name = "jiba2" cerealizer.register(NewObj) cerealizer.register_alias(NewObj, "__main__.OldObj") o = cerealizer.loads(s) assert o.__class__ is NewObj assert o.x == 1 assert o.name == "jiba"
def test_alias1(self): class OldObj(object): def __init__(self): self.x = 1 self.name = "jiba" cerealizer.register(OldObj) o = OldObj() s = cerealizer.dumps(o) reload(cerealizer) class NewObj(object): def __init__(self): self.x = 2 self.name = "jiba2" cerealizer.register(NewObj) cerealizer.register_alias(NewObj, "__main__.OldObj") o = cerealizer.loads(s) assert o.__class__ is NewObj assert o.x == 1 assert o.name == "jiba"
def register_all(extras = []): """! Register our known serializables. @param extras extra class/mod names to allow serialization @good OK 20080102 bryon """ global _already_called if _already_called: return _already_called = True for module_name, class_names in chain(known, extras): before = sys.modules if type(class_names) == str: class_names = [ class_names ] module = __import__(module_name, globals(), locals(), class_names) for class_name in class_names: clas = getattr(module, class_name) # this has to be ugly to maintain backwards crypto compatibility # internal classnames that cerealizer picks up/picked up on changed from PyCrypto 2.0.1 -> 2.1.0 # as such we need to alias both the generated and read it classnames. # if any more changes need to happen here, or this gets called more than once per process # or we start multiprocessing for whatever reason, register_all will need a refactoring. if class_name == '_RSAobj': register(clas, classname = 'Crypto.PublicKey.RSA.RSAobj') else: register(clas) if module_name in aliases: for alias in aliases[module_name]: clas = getattr(module,alias[0]) register_alias(clas, '.'.join((module_name, alias[1]))) sys.modules = before
#cerealizer.register_class(_soya.Traveling) #cerealizer.register_class(_soya.PythonCoordSyst) cerealizer.register_class(_soya.FlagSubFire) #cerealizer.register_class(_soya.Position) #cerealizer.register_class(_soya.ModelBuilder) #cerealizer.register_class(_soya._CObj) cerealizer.register_class(soya.DisplayList) if hasattr(soya, "Sound"): # Has sound / OpenAL support cerealizer.register_class(soya.WAVSound, SavedInAPathHandler(soya.WAVSound)) cerealizer.register_class(soya.OGGVorbisSound, SavedInAPathHandler(soya.OGGVorbisSound)) cerealizer.register_class(soya.SoundPlayer) # Aliases for backward compatibility cerealizer.register_alias(soya.Body , "soya.Cal3dVolume") cerealizer.register_alias(soya.Body , "soya.Cal3dBody") cerealizer.register_alias(soya.Body , "soya.Volume") cerealizer.register_alias(soya.Model , "soya.Shape") cerealizer.register_alias(soya.SimpleModel , "soya.SimpleShape") cerealizer.register_alias(soya.SolidModel , "soya.SolidShape") cerealizer.register_alias(soya.CellShadingModel , "soya.CellShadingShape") cerealizer.register_alias(soya.TreeModel , "soya.TreeShape") cerealizer.register_alias(soya.AnimatedModel , "soya.Cal3dShape") cerealizer.register_alias(soya.Terrain , "soya.Land") cerealizer.register_alias(soya.SimpleModelBuilder , "soya.SimpleShapifier") cerealizer.register_alias(soya.SimpleModelBuilder , "_soya.SimpleShapifier") cerealizer.register_alias(soya.SolidModelBuilder , "soya.SolidShapifier") cerealizer.register_alias(soya.SolidModelBuilder , "_soya.SolidShapifier") cerealizer.register_alias(soya.CellShadingModelBuilder, "soya.CellShadingShapifier") cerealizer.register_alias(soya.CellShadingModelBuilder, "_soya.CellShadingShapifier")