[Twisted-Python] Transporting pb.Copyable classes?

Jasper Phillips jasper at peak.org
Wed Apr 21 17:03:47 EDT 2004


On Wed, 21 Apr 2004 exarkun at divmod.com wrote:

> On Wed, 21 Apr 2004 09:57:47 -0700 (PDT), Jasper Phillips <jasper at peak.org> wrote:
> > 
> > All this seems to me like frantic contortion to avoid a bug in jelly.
> > Shouldn't it be able to translate passed class objects into the remote
> > version, provided they have been properly registered?  Is there some reason
> > why not that I am missing?
> 
>   Indeed.  While I would do this differently, jelly should certainly be
>   able to handle your approach.  Let's get into specifics, shall we?
>   Here's some code:

I may end up doing it differently, but one thing at a time!  I'm in the
midst of upgrading to new cred, and already have plenty of scope with which
to hang myself. ;-)

I'm not particularily attached to the static class approach, it just
happened to be what came to mind when prototyping.  I'm definitely curious
now what you would do...  I've been programming in a vacuum for quite a
while. :-(


> >>> from twisted.spread import jelly
> >>> class Foo: pass
> ... 
> >>> f = Foo()
> >>> f.bar = Foo
> >>> jelly.jelly(f)
> ['__main__.Foo', ['dictionary', ['bar', ['class', '__main__.Foo']]]]
> 
>   So far, so good.
> 
> >>> from twisted.spread import pb     
> >>> class Foo(pb.Copyable):
> ...     pass
> ... 
> >>> f = Foo()
> >>> f.bar = Foo
> >>> jelly.jelly(f)
> ['__main__.Foo', ['dictionary', ['bar', ['class', '__main__.Foo']]]]
> 
>   Hmm, that works too.  I expected it not to, actually.  I suppose
>   something you're doing with globalSecurity or setCopierForClassTree()
>   may be mucking things up.

This test case doesn't seem quite right...  Why doesn't it fail since Foo
hasn't been registered?  Hmmm, looks like jelly()'s taster arg defaults to
DummySecurityOptions()...

What about registering Foo, and then calling with jelly.globalSecurity?:
---- Code ----
from twisted.spread import jelly, pb

class Foo( pb.Copyable ):  pass
jelly.setUnjellyableForClass( Foo, Foo )
#jelly.globalSecurity.allowInstancesOf( Foo )  # uncomment to fix

if __name__ == '__main__':
    f = Foo()
    f.bar = Foo
    print jelly.jelly( f, taster=jelly.globalSecurity )

---- End Code ----

This gives the Insecure Jelly exception I'm seeing, from jelly.py:482...
However, comment out `f.bar = Foo` or uncomment allowInstancesOf() and it
works.

Oh, and I'm using twisted 1.2 and python 2.3.3.


[snip]
>   Posting a demonstrative test case would be excellent :)  I suspect there
>   is no bug in jelly, just a disagreement in expectations which can easily
>   be resolved once there is a concrete example to talk about.

Is this a decent example?  As for a fix, it looks like the solution is there
in SecurityOptions.allowsInstancesOf(), but that it's just not exposed.

-Jasper





More information about the Twisted-Python mailing list