|
11 | 11 | import sys |
12 | 12 | import threading |
13 | 13 | from contextlib import suppress |
| 14 | +from warnings import warn as _warn |
14 | 15 |
|
15 | 16 |
|
16 | 17 | try: |
17 | 18 | import ssl |
18 | 19 | except ImportError: |
19 | 20 | ssl = None |
20 | 21 |
|
21 | | -try: |
22 | | - from _pyio import DEFAULT_BUFFER_SIZE |
23 | | -except ImportError: |
24 | | - try: |
25 | | - from io import DEFAULT_BUFFER_SIZE |
26 | | - except ImportError: |
27 | | - DEFAULT_BUFFER_SIZE = -1 |
28 | | - |
29 | 22 | from .. import errors |
30 | | -from ..makefile import StreamReader, StreamWriter |
31 | 23 | from ..server import HTTPServer |
32 | 24 | from . import Adapter |
33 | 25 |
|
34 | 26 |
|
| 27 | +# WPS413 is to suppress linter error: |
| 28 | +# bad magic module function: __getattr__ |
| 29 | +# DEFAULT_BUFFER_SIZE is deprecated so this module method will be removed |
| 30 | +# in a future release |
| 31 | +def __getattr__(name): # noqa: WPS413 |
| 32 | + if name == 'DEFAULT_BUFFER_SIZE': |
| 33 | + _warn( |
| 34 | + ( |
| 35 | + '`DEFAULT_BUFFER_SIZE` is deprecated and ' |
| 36 | + 'will be removed in a future release.' |
| 37 | + ), |
| 38 | + DeprecationWarning, |
| 39 | + stacklevel=2, |
| 40 | + ) |
| 41 | + from io import DEFAULT_BUFFER_SIZE |
| 42 | + |
| 43 | + return DEFAULT_BUFFER_SIZE |
| 44 | + raise AttributeError(f'module {__name__!r} has no attribute {name!r}') |
| 45 | + |
| 46 | + |
35 | 47 | def _assert_ssl_exc_contains(exc, *msgs): |
36 | 48 | """Check whether SSL exception contains either of messages provided.""" |
37 | 49 | if len(msgs) < 1: |
@@ -247,9 +259,6 @@ def __init__( |
247 | 259 | private_key_password=private_key_password, |
248 | 260 | ) |
249 | 261 |
|
250 | | - if private_key_password is None: |
251 | | - private_key_password = self._prompt_for_tls_password |
252 | | - |
253 | 262 | self.context = ssl.create_default_context( |
254 | 263 | purpose=ssl.Purpose.CLIENT_AUTH, |
255 | 264 | cafile=certificate_chain, |
@@ -496,7 +505,19 @@ def _make_env_dn_dict(self, env_prefix, cert_value): |
496 | 505 | env['%s_%s_%i' % (env_prefix, attr_code, i)] = val |
497 | 506 | return env |
498 | 507 |
|
499 | | - def makefile(self, sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE): |
500 | | - """Return socket file object.""" |
501 | | - cls = StreamReader if 'r' in mode else StreamWriter |
502 | | - return cls(sock, mode, bufsize) |
| 508 | + def makefile(self, sock, mode='r', bufsize=-1): |
| 509 | + """ |
| 510 | + Return socket file object. |
| 511 | +
|
| 512 | + ``makefile`` is now deprecated and will be removed in a future |
| 513 | + version. |
| 514 | + """ |
| 515 | + _warn( |
| 516 | + 'The `makefile` method is deprecated and will be removed in a future version. ' |
| 517 | + 'The connection socket should be fully wrapped by the adapter ' |
| 518 | + 'before being passed to the HTTPConnection constructor.', |
| 519 | + DeprecationWarning, |
| 520 | + stacklevel=2, |
| 521 | + ) |
| 522 | + |
| 523 | + return sock.makefile(mode, bufsize) |
0 commit comments