Sends the given message to the client of this Web Socket.
(
self, message: Union[str, bytes, Dict[str, Any]], binary: bool = False
)
| 1061 | return self.stream.write(frame) |
| 1062 | |
| 1063 | def write_message( |
| 1064 | self, message: Union[str, bytes, Dict[str, Any]], binary: bool = False |
| 1065 | ) -> "Future[None]": |
| 1066 | """Sends the given message to the client of this Web Socket.""" |
| 1067 | if binary: |
| 1068 | opcode = 0x2 |
| 1069 | else: |
| 1070 | opcode = 0x1 |
| 1071 | if isinstance(message, dict): |
| 1072 | message = tornado.escape.json_encode(message) |
| 1073 | message = tornado.escape.utf8(message) |
| 1074 | assert isinstance(message, bytes) |
| 1075 | self._message_bytes_out += len(message) |
| 1076 | flags = 0 |
| 1077 | if self._compressor: |
| 1078 | message = self._compressor.compress(message) |
| 1079 | flags |= self.RSV1 |
| 1080 | # For historical reasons, write methods in Tornado operate in a semi-synchronous |
| 1081 | # mode in which awaiting the Future they return is optional (But errors can |
| 1082 | # still be raised). This requires us to go through an awkward dance here |
| 1083 | # to transform the errors that may be returned while presenting the same |
| 1084 | # semi-synchronous interface. |
| 1085 | try: |
| 1086 | fut = self._write_frame(True, opcode, message, flags=flags) |
| 1087 | except StreamClosedError: |
| 1088 | raise WebSocketClosedError() |
| 1089 | |
| 1090 | async def wrapper() -> None: |
| 1091 | try: |
| 1092 | await fut |
| 1093 | except StreamClosedError: |
| 1094 | raise WebSocketClosedError() |
| 1095 | |
| 1096 | return asyncio.ensure_future(wrapper()) |
| 1097 | |
| 1098 | def write_ping(self, data: bytes) -> None: |
| 1099 | """Send ping frame.""" |
nothing calls this directly
no test coverage detected