Sends a new message to the other party. Generates a new sequence number for the message, and provides it to the caller before the message is sent, using the context manager protocol:: with send_message(...) as seq: # The message hasn't been sent yet.
(self, message)
| 1198 | |
| 1199 | @contextlib.contextmanager |
| 1200 | def _send_message(self, message): |
| 1201 | """Sends a new message to the other party. |
| 1202 | |
| 1203 | Generates a new sequence number for the message, and provides it to the |
| 1204 | caller before the message is sent, using the context manager protocol:: |
| 1205 | |
| 1206 | with send_message(...) as seq: |
| 1207 | # The message hasn't been sent yet. |
| 1208 | ... |
| 1209 | # Now the message has been sent. |
| 1210 | |
| 1211 | Safe to call concurrently for the same channel from different threads. |
| 1212 | """ |
| 1213 | |
| 1214 | assert "seq" not in message |
| 1215 | with self: |
| 1216 | seq = next(self._seq_iter) |
| 1217 | |
| 1218 | message = MessageDict(None, message) |
| 1219 | message["seq"] = seq |
| 1220 | self._prettify(message) |
| 1221 | |
| 1222 | with self: |
| 1223 | yield seq |
| 1224 | self.stream.write_json(message) |
| 1225 | |
| 1226 | def send_request(self, command, arguments=None, on_before_send=None): |
| 1227 | """Sends a new request, and returns the OutgoingRequest object for it. |
no test coverage detected