1 | n/a | from idlelib import rpc |
---|
2 | n/a | |
---|
3 | n/a | def remote_object_tree_item(item): |
---|
4 | n/a | wrapper = WrappedObjectTreeItem(item) |
---|
5 | n/a | oid = id(wrapper) |
---|
6 | n/a | rpc.objecttable[oid] = wrapper |
---|
7 | n/a | return oid |
---|
8 | n/a | |
---|
9 | n/a | class WrappedObjectTreeItem: |
---|
10 | n/a | # Lives in PYTHON subprocess |
---|
11 | n/a | |
---|
12 | n/a | def __init__(self, item): |
---|
13 | n/a | self.__item = item |
---|
14 | n/a | |
---|
15 | n/a | def __getattr__(self, name): |
---|
16 | n/a | value = getattr(self.__item, name) |
---|
17 | n/a | return value |
---|
18 | n/a | |
---|
19 | n/a | def _GetSubList(self): |
---|
20 | n/a | sub_list = self.__item._GetSubList() |
---|
21 | n/a | return list(map(remote_object_tree_item, sub_list)) |
---|
22 | n/a | |
---|
23 | n/a | class StubObjectTreeItem: |
---|
24 | n/a | # Lives in IDLE process |
---|
25 | n/a | |
---|
26 | n/a | def __init__(self, sockio, oid): |
---|
27 | n/a | self.sockio = sockio |
---|
28 | n/a | self.oid = oid |
---|
29 | n/a | |
---|
30 | n/a | def __getattr__(self, name): |
---|
31 | n/a | value = rpc.MethodProxy(self.sockio, self.oid, name) |
---|
32 | n/a | return value |
---|
33 | n/a | |
---|
34 | n/a | def _GetSubList(self): |
---|
35 | n/a | sub_list = self.sockio.remotecall(self.oid, "_GetSubList", (), {}) |
---|
36 | n/a | return [StubObjectTreeItem(self.sockio, oid) for oid in sub_list] |
---|