|
4 | 4 | import socket
|
5 | 5 | import typing
|
6 | 6 | import warnings
|
| 7 | +from collections.abc import Sequence |
7 | 8 | from errno import errorcode
|
8 | 9 | from functools import partial, wraps
|
9 | 10 | from itertools import chain, count
|
10 | 11 | from sys import platform
|
11 |
| -from typing import Any, Callable, List, Optional, Sequence, TypeVar |
| 12 | +from typing import Any, Callable, Optional, TypeVar |
12 | 13 | from weakref import WeakValueDictionary
|
13 | 14 |
|
14 | 15 | from cryptography import x509
|
@@ -288,7 +289,7 @@ class _NoOverlappingProtocols:
|
288 | 289 | _ALPNSelectCallback = Callable[
|
289 | 290 | [
|
290 | 291 | "Connection",
|
291 |
| - typing.Union[List[bytes], _NoOverlappingProtocols], |
| 292 | + typing.Union[typing.List[bytes], _NoOverlappingProtocols], |
292 | 293 | ],
|
293 | 294 | None,
|
294 | 295 | ]
|
@@ -766,7 +767,7 @@ def _asFileDescriptor(obj: Any) -> int:
|
766 | 767 | raise TypeError("argument must be an int, or have a fileno() method.")
|
767 | 768 | elif fd < 0:
|
768 | 769 | raise ValueError(
|
769 |
| - "file descriptor cannot be a negative integer (%i)" % (fd,) |
| 770 | + f"file descriptor cannot be a negative integer ({fd:i})" |
770 | 771 | )
|
771 | 772 |
|
772 | 773 | return fd
|
@@ -1952,18 +1953,16 @@ def _raise_ssl_error(self, ssl: Any, result: int) -> None:
|
1952 | 1953 | # TODO: This is untested.
|
1953 | 1954 | raise WantX509LookupError()
|
1954 | 1955 | elif error == _lib.SSL_ERROR_SYSCALL:
|
1955 |
| - if _lib.ERR_peek_error() == 0: |
1956 |
| - if result < 0: |
1957 |
| - if platform == "win32": |
1958 |
| - errno = _ffi.getwinerror()[0] |
1959 |
| - else: |
1960 |
| - errno = _ffi.errno |
1961 |
| - |
1962 |
| - if errno != 0: |
1963 |
| - raise SysCallError(errno, errorcode.get(errno)) |
| 1956 | + if platform == "win32": |
| 1957 | + errno = _ffi.getwinerror()[0] |
| 1958 | + else: |
| 1959 | + errno = _ffi.errno |
| 1960 | + if _lib.ERR_peek_error() == 0 or errno != 0: |
| 1961 | + if result < 0 and errno != 0: |
| 1962 | + raise SysCallError(errno, errorcode.get(errno)) |
1964 | 1963 | raise SysCallError(-1, "Unexpected EOF")
|
1965 | 1964 | else:
|
1966 |
| - # TODO: This is untested. |
| 1965 | + # TODO: This is untested, but I think twisted hits it? |
1967 | 1966 | _raise_current_error()
|
1968 | 1967 | elif error == _lib.SSL_ERROR_SSL and _lib.ERR_peek_error() != 0:
|
1969 | 1968 | # In 3.0.x an unexpected EOF no longer triggers syscall error
|
|
0 commit comments