RE: [Twisted-Python] help with InsecureJelly for unkown objects inclasses
twisted.spread.jelly.InsecureJelly: Type not allowed for object: <type 'Rect'> <rect(0, 0, 32, 32)>
That's not related to pygame, but general pb behaviour. See my question about "declare pb.Copyable once" and look at this howto: http://twistedmatrix.com/documents/current/howto/pb-copyable Best regards, Henning Hraban Ramm Südkurier Medienhaus / MediaPro Support/Admin/Development Dept.
Henning, I realize the error isn't specific to pygame in any way, I was just hoping to give everyone enough context. I'm getting the error because a pygame.Rect isn't a jellyable object. But so far I haven't been able to make a jellyable object out of it. The problem for me is that this Rect object is inside of another class (i.e. a GameState class). I can set pb.Copyable and pb.RemoteCopy on the GameState class, and it goes back and forth just fine, but *only* if I remove the pygame.Rect attributes from it. I searched the twisted site for "declare pb.Copyable once," and even just the word "Henning," but I couldn't find any threads about this. And unfortunately the howto doesn't help, since all it shows is how to send a simple class back and forth, which I can do fine. Any other suggestions for getting a class with non-standard objects in it to jelly properly? Ben Henning.Ramm@mediapro-gmbh.de wrote:
twisted.spread.jelly.InsecureJelly: Type not allowed for object: <type 'Rect'> <rect(0, 0, 32, 32)>
That's not related to pygame, but general pb behaviour. See my question about "declare pb.Copyable once" and look at this howto: http://twistedmatrix.com/documents/current/howto/pb-copyable
Best regards, Henning Hraban Ramm Südkurier Medienhaus / MediaPro Support/Admin/Development Dept.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On Thu, 17 Mar 2005 09:58:08 -0700, Ben Olsen <bolsen@verio.net> wrote:
Henning,
I realize the error isn't specific to pygame in any way, I was just hoping to give everyone enough context. I'm getting the error because a pygame.Rect isn't a jellyable object. But so far I haven't been able to make a jellyable object out of it. The problem for me is that this Rect object is inside of another class (i.e. a GameState class). I can set pb.Copyable and pb.RemoteCopy on the GameState class, and it goes back and forth just fine, but *only* if I remove the pygame.Rect attributes from it.
I searched the twisted site for "declare pb.Copyable once," and even just the word "Henning," but I couldn't find any threads about this. And unfortunately the howto doesn't help, since all it shows is how to send a simple class back and forth, which I can do fine.
Any other suggestions for getting a class with non-standard objects in it to jelly properly?
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
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, self.ball.h) 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. Ben 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@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Ben Olsen
-
Henning.Ramm@mediapro-gmbh.de
-
Jp Calderone