[Twisted-Python] help with InsecureJelly for unkown objects inclasses--solution

Ben Olsen bolsen at verio.net
Thu Mar 17 15:03:43 EST 2005

Thanks Jp, someone else had that suggestion too, and it ended up working 
just fine. Using getStateToCopy and setCopyableState, I can convert a 
pygame.Rect to a tuple before sending, then convert it back when 
receiving. For those curious, the class looks something like this:

class GameState(pb.Copyable, pb.RemoteCopy):
    def __init__(self, id):
        ... define various game state properties ...
        self.ball = Rect([0,0,32,32])

    def getStateToCopy(self):
        ret = self.__dict__.copy()
        del ret['ball']
        ret['balltuple'] = (self.ball.x, self.ball.y, self.ball.w, 
        return ret
    def setCopyableState(self, state):
        self.ball = Rect(state['balltuple'])
        return self.__dict__

This class is inherited on both server and client. This makes passing 
the pygame.Rect transparent, so no work is required on either the server 
or client side.


Jp Calderone wrote:

>  One approach is to override getStateToCopy (or jellyFor, or getStateToCopyFor, or __getstate__, or several of the above, or all of the above, depending) on your GameState class.  Your implementation can do something like convert the rect to a tuple (or something else easily jellyable).  Similarly, your unjellier can convert the tuple back to a rect.
>  Jp
>Twisted-Python mailing list
>Twisted-Python at twistedmatrix.com

More information about the Twisted-Python mailing list