| 1 |
# Copyright (c) Twisted Matrix Laboratories. |
| 2 |
# See LICENSE for details. |
| 3 |
|
| 4 |
|
| 5 |
"""PB interop server.""" |
| 6 |
|
| 7 |
from twisted.internet import reactor |
| 8 |
from twisted.spread import flavors, pb |
| 9 |
|
| 10 |
|
| 11 |
class Interop(pb.Root): |
| 12 |
"""Test object for PB interop tests.""" |
| 13 |
|
| 14 |
def __init__(self): |
| 15 |
self.o = pb.Referenceable() |
| 16 |
|
| 17 |
def remote_int(self): |
| 18 |
return 1 |
| 19 |
|
| 20 |
def remote_string(self): |
| 21 |
return "string" |
| 22 |
|
| 23 |
def remote_unicode(self): |
| 24 |
return "string" |
| 25 |
|
| 26 |
def remote_float(self): |
| 27 |
return 1.5 |
| 28 |
|
| 29 |
def remote_list(self): |
| 30 |
return [1, 2, 3] |
| 31 |
|
| 32 |
def remote_recursive(self): |
| 33 |
l = [] |
| 34 |
l.append(l) |
| 35 |
return l |
| 36 |
|
| 37 |
def remote_dict(self): |
| 38 |
return {1: 2} |
| 39 |
|
| 40 |
def remote_reference(self): |
| 41 |
return self.o |
| 42 |
|
| 43 |
def remote_local(self, obj): |
| 44 |
d = obj.callRemote("hello") |
| 45 |
d.addCallback(self._local_success) |
| 46 |
|
| 47 |
def _local_success(self, result): |
| 48 |
if result != "hello, world": |
| 49 |
raise ValueError("{} != {}".format(result, "hello, world")) |
| 50 |
|
| 51 |
def remote_receive(self, obj): |
| 52 |
expected = [1, 1.5, "hi", "hi", {1: 2}] |
| 53 |
if obj != expected: |
| 54 |
raise ValueError(f"{obj} != {expected}") |
| 55 |
|
| 56 |
def remote_self(self, obj): |
| 57 |
if obj != self: |
| 58 |
raise ValueError(f"{obj} != {self}") |
| 59 |
|
| 60 |
def remote_copy(self, x): |
| 61 |
o = flavors.Copyable() |
| 62 |
o.x = x |
| 63 |
return o |
| 64 |
|
| 65 |
|
| 66 |
if __name__ == "__main__": |
| 67 |
reactor.listenTCP(8789, pb.PBServerFactory(Interop())) |
| 68 |
reactor.run() |