[Twisted-Python] pb.setFactoryForClass()

proposal for new functionality in pb: In addition to the existing pb.setCopierForClass() I'd like a pb.setFactoryForClass() which would take a factory method instead of a class as its argument. This would allow serialized objects to be re-constructed on the other end of network connections by a factory instead of just be creating a new class. I have a use case where objects are created locally on both the client and server and these objects need to be passed as arguments to remote method calls. The best way to do it seems to be to send a unique ID over the wire and have a factory method transform the ID into the correct object on the other side. A trivial example: class Thing(pb.Copyable) allIDs = {} def __init__(self, id): self.id = id Thing.allIDs[id] = self def getStateToJellyFor(self, perspective): return {"id":self.id} def thingFactory(state): return Thing.allIDs.get(state["id"],None) pb.setFactoryToCopyFor("Thing", thingFactory) Things could then be send over the network as very small objects (just IDs) as long as both side have already loaded all the "Things" from local storage. ---- "If it's not running programs or fusing atoms, it's just bending space.", Ken Macleod "That's it, I'm outta here.", Homer Simpson's Brain Sean Riley sean@ninjaneering.com

From: "Sean Riley" <sean@twistedmatrix.com> Subject: [Twisted-Python] pb.setFactoryForClass() Date: Sat, 15 Jun 2002 13:24:59 -0500
proposal for new functionality in pb:
In addition to the existing pb.setCopierForClass() I'd like a pb.setFactoryForClass() which would take a factory method instead of a class as its argument.
Though this is its first mention on the mailing list, I've already accepted this proposal and put it on my task list -- I just added it to CVS (it had been sitting on my local drive for a little while). -- | <`'> | Glyph Lefkowitz: Traveling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
participants (2)
-
Glyph Lefkowitz
-
Sean Riley