Wraps a Transport. This exposes write(), writelines(), [can_]write_eof(), get_extra_info() and close(). It adds drain() which returns an optional Future on which you can wait for flow control. It also adds a transport property which references the Transport directly.
| 307 | |
| 308 | |
| 309 | class StreamWriter: |
| 310 | """Wraps a Transport. |
| 311 | |
| 312 | This exposes write(), writelines(), [can_]write_eof(), |
| 313 | get_extra_info() and close(). It adds drain() which returns an |
| 314 | optional Future on which you can wait for flow control. It also |
| 315 | adds a transport property which references the Transport |
| 316 | directly. |
| 317 | """ |
| 318 | |
| 319 | def __init__(self, transport, protocol, reader, loop): |
| 320 | self._transport = transport |
| 321 | self._protocol = protocol |
| 322 | # drain() expects that the reader has an exception() method |
| 323 | assert reader is None or isinstance(reader, StreamReader) |
| 324 | self._reader = reader |
| 325 | self._loop = loop |
| 326 | self._complete_fut = self._loop.create_future() |
| 327 | self._complete_fut.set_result(None) |
| 328 | |
| 329 | def __repr__(self): |
| 330 | info = [self.__class__.__name__, f'transport={self._transport!r}'] |
| 331 | if self._reader is not None: |
| 332 | info.append(f'reader={self._reader!r}') |
| 333 | return '<{}>'.format(' '.join(info)) |
| 334 | |
| 335 | @property |
| 336 | def transport(self): |
| 337 | return self._transport |
| 338 | |
| 339 | def write(self, data): |
| 340 | self._transport.write(data) |
| 341 | |
| 342 | def writelines(self, data): |
| 343 | self._transport.writelines(data) |
| 344 | |
| 345 | def write_eof(self): |
| 346 | return self._transport.write_eof() |
| 347 | |
| 348 | def can_write_eof(self): |
| 349 | return self._transport.can_write_eof() |
| 350 | |
| 351 | def close(self): |
| 352 | return self._transport.close() |
| 353 | |
| 354 | def is_closing(self): |
| 355 | return self._transport.is_closing() |
| 356 | |
| 357 | async def wait_closed(self): |
| 358 | await self._protocol._get_close_waiter(self) |
| 359 | |
| 360 | def get_extra_info(self, name, default=None): |
| 361 | return self._transport.get_extra_info(name, default) |
| 362 | |
| 363 | async def drain(self): |
| 364 | """Flush the write buffer. |
| 365 | |
| 366 | The intended use is to write |
no outgoing calls
no test coverage detected