[Twisted-Python] Patch: sending new style classes via perspective broker
Ralf Schmitt
ralf at brainbot.com
Wed Dec 10 08:38:01 EST 2003
Hi,
sending new style classes via perspective broker currently isn't
possible without extra effort. I have attached a short test program
and a patch to jelly.py, which solves that problem.
- Ralf
===========
from twisted.spread import pb
from twisted.internet import reactor, threads
from twisted.python import threadable
class Data(pb.Copyable, pb.RemoteCopy, object):
def __init__(self, s):
self.s = s
pb.setUnjellyableForClass(Data, Data)
class Echoer(pb.Root):
def remote_echo(self, st):
print "REMOTE_ECHO:", st, st.s
return st
if __name__ == '__main__':
reactor.listenTCP(8789, pb.PBServerFactory(Echoer()))
factory = pb.PBClientFactory()
reactor.connectTCP("127.0.0.1", 8789, factory)
factory.getRootObject().addCallback(lambda r: r.callRemote("echo", Data("foo")))
reactor.callLater(2, reactor.stop)
reactor.run()
===================================================================
RCS file: /cvs/Twisted/twisted/spread/jelly.py,v
retrieving revision 1.48
diff -u -r1.48 jelly.py
--- jelly.py 4 Jun 2003 00:18:03 -0000 1.48
+++ jelly.py 10 Dec 2003 12:35:48 -0000
@@ -520,6 +520,9 @@
inst = _Dummy() # XXX chomp, chomp
inst.__class__ = regClass
method = inst.unjellyFor
+ elif isinstance(regClass, type): # new style class
+ inst = object.__new__(regClass) # does not call regClass.__init__
+ method = inst.unjellyFor
else:
method = regClass # this is how it ought to be done
val = method(self, obj)
--
brainbot technologies ag
boppstrasse 64 . 55118 mainz . germany
fon +49 6131 211639-1 . fax +49 6131 211639-2
http://brainbot.com/ mailto:ralf at brainbot.com
More information about the Twisted-Python
mailing list