Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dffc45

Browse files
committed
Update asyncio from the Tulip project
Major changes: - StreamReader.readexactly() now raises an IncompleteReadError if the end of stream is reached before we received enough bytes, instead of returning less bytes than requested. - Unit tests use the main asyncio module instead of submodules like events - _UnixWritePipeTransport now also supports character devices, as _UnixReadPipeTransport. Patch written by Jonathan Slenders. - Export more symbols: BaseEventLoop, BaseProactorEventLoop, BaseSelectorEventLoop, Queue and Queue sublasses, Empty, Full
1 parent 75a5ec8 commit 8dffc45

17 files changed

Lines changed: 931 additions & 887 deletions

Lib/asyncio/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,32 @@
1818
import _overlapped # Will also be exported.
1919

2020
# This relies on each of the submodules having an __all__ variable.
21-
from .futures import *
21+
from .base_events import *
2222
from .events import *
23+
from .futures import *
2324
from .locks import *
24-
from .transports import *
25+
from .proactor_events import *
2526
from .protocols import *
27+
from .queues import *
28+
from .selector_events import *
2629
from .streams import *
2730
from .tasks import *
31+
from .transports import *
2832

2933
if sys.platform == 'win32': # pragma: no cover
3034
from .windows_events import *
3135
else:
3236
from .unix_events import * # pragma: no cover
3337

3438

35-
__all__ = (futures.__all__ +
39+
__all__ = (base_events.__all__ +
3640
events.__all__ +
41+
futures.__all__ +
3742
locks.__all__ +
38-
transports.__all__ +
43+
proactor_events.__all__ +
3944
protocols.__all__ +
45+
queues.__all__ +
46+
selector_events.__all__ +
4047
streams.__all__ +
41-
tasks.__all__)
48+
tasks.__all__ +
49+
transports.__all__)

Lib/asyncio/proactor_events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
proactor is only implemented on Windows with IOCP.
55
"""
66

7+
__all__ = ['BaseProactorEventLoop']
8+
79
import socket
810

911
from . import base_events

Lib/asyncio/selector_events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
also includes support for signal handling, see the unix_events sub-module.
55
"""
66

7+
__all__ = ['BaseSelectorEventLoop']
8+
79
import collections
810
import errno
911
import socket

Lib/asyncio/streams.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Stream-related things."""
22

33
__all__ = ['StreamReader', 'StreamWriter', 'StreamReaderProtocol',
4-
'open_connection', 'start_server',
4+
'open_connection', 'start_server', 'IncompleteReadError',
55
]
66

77
import collections
@@ -14,6 +14,19 @@
1414

1515
_DEFAULT_LIMIT = 2**16
1616

17+
class IncompleteReadError(EOFError):
18+
"""
19+
Incomplete read error. Attributes:
20+
21+
- partial: read bytes string before the end of stream was reached
22+
- expected: total number of expected bytes
23+
"""
24+
def __init__(self, partial, expected):
25+
EOFError.__init__(self, "%s bytes read on a total of %s expected bytes"
26+
% (len(partial), expected))
27+
self.partial = partial
28+
self.expected = expected
29+
1730

1831
@tasks.coroutine
1932
def open_connection(host=None, port=None, *,
@@ -403,12 +416,9 @@ def readexactly(self, n):
403416
while n > 0:
404417
block = yield from self.read(n)
405418
if not block:
406-
break
419+
partial = b''.join(blocks)
420+
raise IncompleteReadError(partial, len(partial) + n)
407421
blocks.append(block)
408422
n -= len(block)
409423

410-
# TODO: Raise EOFError if we break before n == 0? (That would
411-
# be a change in specification, but I've always had to add an
412-
# explicit size check to the caller.)
413-
414424
return b''.join(blocks)

Lib/asyncio/unix_events.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,11 @@ def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
259259
self._fileno = pipe.fileno()
260260
mode = os.fstat(self._fileno).st_mode
261261
is_socket = stat.S_ISSOCK(mode)
262-
is_pipe = stat.S_ISFIFO(mode)
263-
if not (is_socket or is_pipe):
264-
raise ValueError("Pipe transport is for pipes/sockets only.")
262+
if not (is_socket or
263+
stat.S_ISFIFO(mode) or
264+
stat.S_ISCHR(mode)):
265+
raise ValueError("Pipe transport is only for "
266+
"pipes, sockets and character devices")
265267
_set_nonblocking(self._fileno)
266268
self._protocol = protocol
267269
self._buffer = []

0 commit comments

Comments
 (0)