bpo-36802: Drop awrite()/aclose(), support await write() and await cl… · python/cpython@a076e4f (original) (raw)
`@@ -22,13 +22,13 @@ streams::
`
22
22
` '127.0.0.1', 8888)
`
23
23
``
24
24
` print(f'Send: {message!r}')
`
25
``
`-
await writer.awrite(message.encode())
`
``
25
`+
await writer.write(message.encode())
`
26
26
``
27
27
` data = await reader.read(100)
`
28
28
` print(f'Received: {data.decode()!r}')
`
29
29
``
30
30
` print('Close the connection')
`
31
``
`-
await writer.aclose()
`
``
31
`+
await writer.close()
`
32
32
``
33
33
` asyncio.run(tcp_echo_client('Hello World!'))
`
34
34
``
`@@ -226,23 +226,70 @@ StreamWriter
`
226
226
`` directly; use :func:open_connection
and :func:start_server
``
227
227
` instead.
`
228
228
``
229
``
`-
.. coroutinemethod:: awrite(data)
`
``
229
`+
.. method:: write(data)
`
``
230
+
``
231
`+
The method attempts to write the data to the underlying socket immediately.
`
``
232
`+
If that fails, the data is queued in an internal write buffer until it can be
`
``
233
`+
sent.
`
``
234
+
``
235
`` +
Starting with Python 3.8, it is possible to directly await on the write()
``
``
236
`+
method::
`
``
237
+
``
238
`+
await stream.write(data)
`
``
239
+
``
240
The ``await`` pauses the current coroutine until the data is written to the
``
241
`+
socket.
`
``
242
+
``
243
`+
Below is an equivalent code that works with Python <= 3.7::
`
``
244
+
``
245
`+
stream.write(data)
`
``
246
`+
await stream.drain()
`
``
247
+
``
248
`+
.. versionchanged:: 3.8
`
``
249
Support ``await stream.write(...)`` syntax.
``
250
+
``
251
`+
.. method:: writelines(data)
`
``
252
+
``
253
`+
The method writes a list (or any iterable) of bytes to the underlying socket
`
``
254
`+
immediately.
`
``
255
`+
If that fails, the data is queued in an internal write buffer until it can be
`
``
256
`+
sent.
`
``
257
+
``
258
`` +
Starting with Python 3.8, it is possible to directly await on the write()
``
``
259
`+
method::
`
``
260
+
``
261
`+
await stream.writelines(lines)
`
``
262
+
``
263
The ``await`` pauses the current coroutine until the data is written to the
``
264
`+
socket.
`
``
265
+
``
266
`+
Below is an equivalent code that works with Python <= 3.7::
`
230
267
``
231
``
`-
Write data to the stream.
`
``
268
`+
stream.writelines(lines)
`
``
269
`+
await stream.drain()
`
232
270
``
233
``
`-
The method respects flow control, execution is paused if the write
`
234
``
`-
buffer reaches the high watermark.
`
``
271
`+
.. versionchanged:: 3.8
`
``
272
Support ``await stream.writelines()`` syntax.
235
273
``
236
``
`-
.. versionadded:: 3.8
`
``
274
`+
.. method:: close()
`
``
275
+
``
276
`+
The method closes the stream and the underlying socket.
`
``
277
+
``
278
`` +
Starting with Python 3.8, it is possible to directly await on the close()
``
``
279
`+
method::
`
``
280
+
``
281
`+
await stream.close()
`
237
282
``
238
``
`-
.. coroutinemethod:: aclose()
`
``
283
The ``await`` pauses the current coroutine until the stream and the underlying
``
284
`+
socket are closed (and SSL shutdown is performed for a secure connection).
`
239
285
``
240
``
`-
Close the stream.
`
``
286
`+
Below is an equivalent code that works with Python <= 3.7::
`
241
287
``
242
``
`-
Wait until all closing actions are complete, e.g. SSL shutdown for
`
243
``
`-
secure sockets.
`
``
288
`+
stream.close()
`
``
289
`+
await stream.wait_closed()
`
244
290
``
245
``
`-
.. versionadded:: 3.8
`
``
291
`+
.. versionchanged:: 3.8
`
``
292
Support ``await stream.close()`` syntax.
246
293
``
247
294
` .. method:: can_write_eof()
`
248
295
``
`@@ -263,21 +310,6 @@ StreamWriter
`
263
310
` Access optional transport information; see
`
264
311
`` :meth:BaseTransport.get_extra_info
for details.
``
265
312
``
266
``
`-
.. method:: write(data)
`
267
``
-
268
``
`-
Write data to the stream.
`
269
``
-
270
``
This method is not subject to flow control. Calls to ``write()`` should
271
``
`` -
be followed by :meth:drain
. The :meth:awrite
method is a
``
272
``
`-
recommended alternative the applies flow control automatically.
`
273
``
-
274
``
`-
.. method:: writelines(data)
`
275
``
-
276
``
`-
Write a list (or any iterable) of bytes to the stream.
`
277
``
-
278
``
This method is not subject to flow control. Calls to ``writelines()``
279
``
`` -
should be followed by :meth:drain
.
``
280
``
-
281
313
` .. coroutinemethod:: drain()
`
282
314
``
283
315
` Wait until it is appropriate to resume writing to the stream.
`
`@@ -293,10 +325,6 @@ StreamWriter
`
293
325
`` be resumed. When there is nothing to wait for, the :meth:drain
``
294
326
` returns immediately.
`
295
327
``
296
``
`-
.. method:: close()
`
297
``
-
298
``
`-
Close the stream.
`
299
``
-
300
328
` .. method:: is_closing()
`
301
329
``
302
330
``` Return True
if the stream is closed or in the process of
```