Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
11194c87
Unverified
Kaydet (Commit)
11194c87
authored
Eyl 13, 2018
tarafından
Andrew Svetlov
Kaydeden (comit)
GitHub
Eyl 13, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-34666: Implement stream.awrite() and stream.aclose() (GH-9274)
üst
413118eb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
22 deletions
+79
-22
asyncio-stream.rst
Doc/library/asyncio-stream.rst
+45
-21
streams.py
Lib/asyncio/streams.py
+9
-1
test_streams.py
Lib/test/test_asyncio/test_streams.py
+22
-0
2018-09-13-11-49-52.bpo-34666.3uLtWv.rst
...S.d/next/Library/2018-09-13-11-49-52.bpo-34666.3uLtWv.rst
+3
-0
No files found.
Doc/library/asyncio-stream.rst
Dosyayı görüntüle @
11194c87
...
...
@@ -20,13 +20,13 @@ streams::
'127.0.0.1', 8888)
print(f'Send: {message!r}')
writer.
write(message.encode())
await writer.a
write(message.encode())
data = await reader.read(100)
print(f'Received: {data.decode()!r}')
print('Close the connection')
writer.
close()
await writer.a
close()
asyncio.run(tcp_echo_client('Hello World!'))
...
...
@@ -229,14 +229,57 @@ StreamWriter
directly; use :func:`open_connection` and :func:`start_server`
instead.
.. coroutinemethod:: awrite(data)
Write *data* to the stream.
The method respects control-flow, execution is paused if write
buffer reaches high-water limit.
.. versionadded:: 3.8
.. coroutinemethod:: aclose()
Close the stream.
Wait for finishing all closing actions, e.g. SSL shutdown for
secure sockets.
.. versionadded:: 3.8
.. method:: can_write_eof()
Return *True* if the underlying transport supports
the :meth:`write_eof` method, *False* otherwise.
.. method:: write_eof()
Close the write end of the stream after the buffered write
data is flushed.
.. attribute:: transport
Return the underlying asyncio transport.
.. method:: get_extra_info(name, default=None)
Access optional transport information; see
:meth:`BaseTransport.get_extra_info` for details.
.. method:: write(data)
Write *data* to the stream.
This method doesn't apply control-flow. The call should be
followed by :meth:`drain`.
.. method:: writelines(data)
Write a list (or any iterable) of bytes to the stream.
This method doesn't apply control-flow. The call should be
followed by :meth:`drain`.
.. coroutinemethod:: drain()
Wait until it is appropriate to resume writing to the stream.
...
...
@@ -272,25 +315,6 @@ StreamWriter
.. versionadded:: 3.7
.. method:: can_write_eof()
Return *True* if the underlying transport supports
the :meth:`write_eof` method, *False* otherwise.
.. method:: write_eof()
Close the write end of the stream after the buffered write
data is flushed.
.. attribute:: transport
Return the underlying asyncio transport.
.. method:: get_extra_info(name, default=None)
Access optional transport information; see
:meth:`BaseTransport.get_extra_info` for details.
Examples
========
...
...
Lib/asyncio/streams.py
Dosyayı görüntüle @
11194c87
...
...
@@ -348,7 +348,7 @@ class StreamWriter:
# a reader can be garbage collected
# after connection closing
self
.
_protocol
.
_untrack_reader
()
return
self
.
_transport
.
close
()
self
.
_transport
.
close
()
def
is_closing
(
self
):
return
self
.
_transport
.
is_closing
()
...
...
@@ -381,6 +381,14 @@ class StreamWriter:
await
sleep
(
0
,
loop
=
self
.
_loop
)
await
self
.
_protocol
.
_drain_helper
()
async
def
aclose
(
self
):
self
.
close
()
await
self
.
wait_closed
()
async
def
awrite
(
self
,
data
):
self
.
write
(
data
)
await
self
.
drain
()
class
StreamReader
:
...
...
Lib/test/test_asyncio/test_streams.py
Dosyayı görüntüle @
11194c87
...
...
@@ -964,6 +964,28 @@ os.close(fd)
'call "stream.close()" explicitly.'
,
messages
[
0
][
'message'
])
def
test_async_writer_api
(
self
):
messages
=
[]
self
.
loop
.
set_exception_handler
(
lambda
loop
,
ctx
:
messages
.
append
(
ctx
))
with
test_utils
.
run_test_server
()
as
httpd
:
rd
,
wr
=
self
.
loop
.
run_until_complete
(
asyncio
.
open_connection
(
*
httpd
.
address
,
loop
=
self
.
loop
))
f
=
wr
.
awrite
(
b
'GET / HTTP/1.0
\r\n\r\n
'
)
self
.
loop
.
run_until_complete
(
f
)
f
=
rd
.
readline
()
data
=
self
.
loop
.
run_until_complete
(
f
)
self
.
assertEqual
(
data
,
b
'HTTP/1.0 200 OK
\r\n
'
)
f
=
rd
.
read
()
data
=
self
.
loop
.
run_until_complete
(
f
)
self
.
assertTrue
(
data
.
endswith
(
b
'
\r\n\r\n
Test message'
))
f
=
wr
.
aclose
()
self
.
loop
.
run_until_complete
(
f
)
self
.
assertEqual
(
messages
,
[])
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS.d/next/Library/2018-09-13-11-49-52.bpo-34666.3uLtWv.rst
0 → 100644
Dosyayı görüntüle @
11194c87
Implement ``asyncio.StreamWriter.awrite`` and
``asyncio.StreamWriter.aclose()`` coroutines. Methods are needed for
providing a consistent stream API with control flow switched on by default.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment