mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
asyncio: Improve default writelines().
This commit is contained in:
parent
afbf827875
commit
f10345e102
2 changed files with 20 additions and 6 deletions
|
@ -1,5 +1,9 @@
|
|||
"""Abstract Transport class."""
|
||||
|
||||
import sys
|
||||
|
||||
PY34 = sys.version_info >= (3, 4)
|
||||
|
||||
__all__ = ['ReadTransport', 'WriteTransport', 'Transport']
|
||||
|
||||
|
||||
|
@ -85,11 +89,15 @@ class WriteTransport(BaseTransport):
|
|||
def writelines(self, list_of_data):
|
||||
"""Write a list (or any iterable) of data bytes to the transport.
|
||||
|
||||
The default implementation just calls write() for each item in
|
||||
the list/iterable.
|
||||
The default implementation concatenates the arguments and
|
||||
calls write() on the result.
|
||||
"""
|
||||
for data in list_of_data:
|
||||
self.write(data)
|
||||
if not PY34:
|
||||
# In Python 3.3, bytes.join() doesn't handle memoryview.
|
||||
list_of_data = (
|
||||
bytes(data) if isinstance(data, memoryview) else data
|
||||
for data in list_of_data)
|
||||
self.write(b''.join(list_of_data))
|
||||
|
||||
def write_eof(self):
|
||||
"""Close the write end after flushing buffered data.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue