MCPcopy Index your code
hub / github.com/python/cpython / ChannelAction

Class ChannelAction

Lib/test/test__interpchannels.py:122–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120
121
122class ChannelAction(namedtuple('ChannelAction', 'action end interp')):
123
124 def __new__(cls, action, end=None, interp=None):
125 if not end:
126 end = 'both'
127 if not interp:
128 interp = 'main'
129 self = super().__new__(cls, action, end, interp)
130 return self
131
132 def __init__(self, *args, **kwargs):
133 if self.action == 'use':
134 if self.end not in ('same', 'opposite', 'send', 'recv'):
135 raise ValueError(self.end)
136 elif self.action in ('close', 'force-close'):
137 if self.end not in ('both', 'same', 'opposite', 'send', 'recv'):
138 raise ValueError(self.end)
139 else:
140 raise ValueError(self.action)
141 if self.interp not in ('main', 'same', 'other', 'extra'):
142 raise ValueError(self.interp)
143
144 def resolve_end(self, end):
145 if self.end == 'same':
146 return end
147 elif self.end == 'opposite':
148 return 'recv' if end == 'send' else 'send'
149 else:
150 return self.end
151
152 def resolve_interp(self, interp, other, extra):
153 if self.interp == 'same':
154 return interp
155 elif self.interp == 'other':
156 if other is None:
157 raise RuntimeError
158 return other
159 elif self.interp == 'extra':
160 if extra is None:
161 raise RuntimeError
162 return extra
163 elif self.interp == 'main':
164 if interp.name == 'main':
165 return interp
166 elif other and other.name == 'main':
167 return other
168 else:
169 raise RuntimeError
170 # Per __init__(), there aren't any others.
171
172
173class ChannelState(namedtuple('ChannelState', 'pending closed')):

Callers 4

_iter_use_action_setsMethod · 0.85
_closeMethod · 0.85

Calls 1

namedtupleFunction · 0.90

Tested by 4

_iter_use_action_setsMethod · 0.68
_closeMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…