| 120 | |
| 121 | |
| 122 | class 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 | |
| 173 | class ChannelState(namedtuple('ChannelState', 'pending closed')): |
searching dependent graphs…