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