[Twisted-Python] Allowing a type to be transmitted by jelly?

This is one of those problems where I've got a solution, but it *seems* like it should be something that can be done that's a little less drastic. Here's the problem: Want to expose a simple data-type (in this case a sub-class of tuple, the PySNMP OID object) to allow for transmission across pb queries and returns. Now, I've tried quite a number of iterations on this, from: jelly.globalSecurity.allowInstancesOf( oid.OID, ) through using classes like this: class PBTypeAllowingServerFactory( pb.PBServerFactory ): """Allow various types to be transported""" def buildProtocol(self, addr): """Return a Broker attached to me (as the service provider). """ broker = pb.PBServerFactory.buildProtocol( self, addr ) broker.security.allowInstancesOf( oid.OID, ) return broker class PBTypeAllowingClientFactory( pb.PBClientFactory ): def clientConnectionMade(self, broker): """Expand the types allowed to be communicated""" broker.security.allowInstancesOf( oid.OID, ) return pb.PBClientFactory.clientConnectionMade( self, broker ) but whenever I try using jelly for the encoding it complains that: Traceback (most recent call last): File "/home/mcfletch/pylive/Twisted/twisted/internet/defer.py", line 190, in addCallbacks self._runCallbacks() File "/home/mcfletch/pylive/Twisted/twisted/internet/defer.py", line 358, in _runCallbacks self.result = callback(self.result, *args, **kw) File "/home/mcfletch/pylive/cinemon/cinespread/metaperspective.py", line 216, in callWhenFree return perspective.callRemote( *args, **named ).addErrback( File "/home/mcfletch/pylive/Twisted/twisted/spread/pb.py", line 382, in callRemote _name, args, kw) --- <exception caught here> --- File "/home/mcfletch/pylive/Twisted/twisted/spread/pb.py", line 857, in _sendMessage netArgs = self.serialize(args, perspective=perspective, method=message) File "/home/mcfletch/pylive/Twisted/twisted/spread/pb.py", line 811, in serialize return jelly(object, self.security, None, self) File "/home/mcfletch/pylive/Twisted/twisted/spread/jelly.py", line 896, in jelly return _Jellier(taster, persistentStore, invoker).jelly(object) File "/home/mcfletch/pylive/Twisted/twisted/spread/jelly.py", line 480, in jelly sxp.append(self.jelly(item)) File "/home/mcfletch/pylive/Twisted/twisted/spread/jelly.py", line 476, in jelly sxp.append(self.jelly(item)) File "/home/mcfletch/pylive/Twisted/twisted/spread/jelly.py", line 511, in jelly raise InsecureJelly("Type not allowed for object: %s %s" % twisted.spread.jelly.InsecureJelly: Type not allowed for object: <class 'cinemon.snmp.oidobject.OID'> .1.3.6.1.2.1.1.4.0 to hack around it I've built my own generic (security restricted) pickle-like system, and freeze the parameters and return values before passing them across pb... which just seems *so* wrong. My system is almost as large as jelly, and is just entirely redundant code other than its allowing me to add new classes to the set allowed. Anyway, I'm sure I'm once again missing something blindingly obvious, but given that I missed the logical equivalent of turning on the power switch earlier I thought I'd ask if someone had a recipe for this type of operation. BTW, this seems like something that should be covered in the tutorial for pb, as it would seem like a common need to add a low-level object-type or two to the set allowed. Freezer-isn't-so-wonderful-I-want-to-use-it-pointlessly y'rs, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com

hi, this is from the pb docs: http://twistedmatrix.com/projects/core/documentation/howto/pb-copyable.html class ReceiverPond(pb.RemoteCopy, LilyPond): pass pb.setUnjellyableForClass(CopyPond, ReceiverPond)# <--- Did you forget this? I only got this error, when i forgot this line. wow, reimplementing jelly?!! seems like you should have asked before :) Johann

Johann Borck wrote:
Thanks for the pointer. I've read that document, and may just be missing the point here. I don't want all of the thousands upon thousands of OID objects to be lugging around extra dictionaries inherited from pb.RemoteCopy (they're just tuples of integers, implemented as such because they are so extremely common in the system). I want the objects to actually *be* OID objects on the client end. That is, what I'm looking for is a way to tell jelly "when you see an object like this, linearise it like this, and reconstitute it like this", rather than creating a different type Y and using that in place of the object on the client side. Yes, probably should have asked before reimplementing jelly, but I was wanting to get a spike test done that evening. Thanks all, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com

From what I know, tuples jelly just fine. I think that what you're serializing isn't a tuple, but rather a cinemon.snmp.oidobject.OID, or something that contains a reference to that. Is that a tuple? if it is, how is it defined?

Micky Latowicki wrote:
cinemon.snmp.oidobject.OID and pysnmp.asn1.oid.OID are tuple sub-classes with __slots__ defined to () such that they have the internal layout of tuples. That's done to improve the efficiency of PySNMP, TwistedSNMP and Cinemon, the classes just add new methods, no new data is stored in the instance's object structure. Bald tuples do, indeed, transmit fine, but sub-classes do not. Enjoy, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com

Itamar Shtull-Trauring wrote:
Aw, you're just trying to make me feel better about reimplementing jelly, I'm sure :) . Guess I'll wait for newpb to emerge and go back to freezing everything until then. Have fun, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com

hi, this is from the pb docs: http://twistedmatrix.com/projects/core/documentation/howto/pb-copyable.html class ReceiverPond(pb.RemoteCopy, LilyPond): pass pb.setUnjellyableForClass(CopyPond, ReceiverPond)# <--- Did you forget this? I only got this error, when i forgot this line. wow, reimplementing jelly?!! seems like you should have asked before :) Johann

Johann Borck wrote:
Thanks for the pointer. I've read that document, and may just be missing the point here. I don't want all of the thousands upon thousands of OID objects to be lugging around extra dictionaries inherited from pb.RemoteCopy (they're just tuples of integers, implemented as such because they are so extremely common in the system). I want the objects to actually *be* OID objects on the client end. That is, what I'm looking for is a way to tell jelly "when you see an object like this, linearise it like this, and reconstitute it like this", rather than creating a different type Y and using that in place of the object on the client side. Yes, probably should have asked before reimplementing jelly, but I was wanting to get a spike test done that evening. Thanks all, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com

From what I know, tuples jelly just fine. I think that what you're serializing isn't a tuple, but rather a cinemon.snmp.oidobject.OID, or something that contains a reference to that. Is that a tuple? if it is, how is it defined?

Micky Latowicki wrote:
cinemon.snmp.oidobject.OID and pysnmp.asn1.oid.OID are tuple sub-classes with __slots__ defined to () such that they have the internal layout of tuples. That's done to improve the efficiency of PySNMP, TwistedSNMP and Cinemon, the classes just add new methods, no new data is stored in the instance's object structure. Bald tuples do, indeed, transmit fine, but sub-classes do not. Enjoy, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com

Itamar Shtull-Trauring wrote:
Aw, you're just trying to make me feel better about reimplementing jelly, I'm sure :) . Guess I'll wait for newpb to emerge and go back to freezing everything until then. Have fun, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com
participants (5)
-
Itamar Shtull-Trauring
-
Johann Borck
-
Micky Latowicki
-
Mike C. Fletcher
-
Mike C. Fletcher