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

Mike C. Fletcher mcfletch at rogers.com
Tue Dec 20 22:58:49 EST 2005


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





More information about the Twisted-Python mailing list