|
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 |
@@ -1955,18 +1956,16 @@ def _raise_ssl_error(self, ssl: Any, result: int) -> None: |
1955 | 1956 | # TODO: This is untested. |
1956 | 1957 | raise WantX509LookupError() |
1957 | 1958 | elif error == _lib.SSL_ERROR_SYSCALL: |
1958 | | - if _lib.ERR_peek_error() == 0: |
1959 | | - if result < 0: |
1960 | | - if platform == "win32": |
1961 | | - errno = _ffi.getwinerror()[0] |
1962 | | - else: |
1963 | | - errno = _ffi.errno |
1964 | | - |
1965 | | - if errno != 0: |
1966 | | - raise SysCallError(errno, errorcode.get(errno)) |
| 1959 | + if platform == "win32": |
| 1960 | + errno = _ffi.getwinerror()[0] |
| 1961 | + else: |
| 1962 | + errno = _ffi.errno |
| 1963 | + if _lib.ERR_peek_error() == 0 or errno != 0: |
| 1964 | + if result < 0 and errno != 0: |
| 1965 | + raise SysCallError(errno, errorcode.get(errno)) |
1967 | 1966 | raise SysCallError(-1, "Unexpected EOF") |
1968 | 1967 | else: |
1969 | | - # TODO: This is untested. |
| 1968 | + # TODO: This is untested, but I think twisted hits it? |
1970 | 1969 | _raise_current_error() |
1971 | 1970 | elif error == _lib.SSL_ERROR_SSL and _lib.ERR_peek_error() != 0: |
1972 | 1971 | # In 3.0.x an unexpected EOF no longer triggers syscall error |
|
0 commit comments