-
Notifications
You must be signed in to change notification settings - Fork 0
/
exposed.py
56 lines (40 loc) · 1.46 KB
/
exposed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from twisted.protocols import amp
from zope import interface
class _ExposingArgument(object):
"""
Superclass for exposing arguments.
"""
optional = True
def toBox(self, name, strings, objects, proto):
"""A no-op.
The exposed value is specific to the local connection. It
can't be serialized back to the other side, so this method
does nothing.
"""
@interface.implementer(amp.IArgumentType)
class ExposedBoxSender(_ExposingArgument):
"""
AMP argument that exposes the box sender to a responder function.
This only works with protocols (usually responder locators) that expose
their box sender a the ``_exposedBoxSender`` attribute.
"""
def fromBox(self, name, strings, objects, proto):
"""
Exposes the cooperating protocol's box sender.
This exposes ``proto``'s ``_exposedBoxSender`` attribute on
``objects`` under ``name``.
"""
objects[name] = proto._exposedBoxSender
@interface.implementer(amp.IArgumentType)
class ExposedProtocol(_ExposingArgument):
"""
AMP argument that exposes the protocol instance to a responder function.
"""
def fromBox(self, name, strings, objects, proto):
"""
Exposes the protocol.
This exposes ``proto`` on ``objects`` under ``name``.
"""
objects[name] = proto
EXPOSED_BOX_SENDER = "boxSender", ExposedBoxSender()
EXPOSED_PROTOCOL = "protocol", ExposedProtocol()