|
25 | 25 |
|
26 | 26 | __all__ = ('BaseConnector', 'TCPConnector', 'ProxyConnector', 'UnixConnector')
|
27 | 27 |
|
28 |
| -PY_341 = sys.version_info >= (3, 4, 1) |
29 | 28 | PY_343 = sys.version_info >= (3, 4, 3)
|
30 | 29 |
|
31 | 30 | HASHFUNC_BY_DIGESTLEN = {
|
@@ -53,24 +52,23 @@ def __init__(self, connector, key, request, transport, protocol, loop):
|
53 | 52 | if loop.get_debug():
|
54 | 53 | self._source_traceback = traceback.extract_stack(sys._getframe(1))
|
55 | 54 |
|
56 |
| - if PY_341: |
57 |
| - def __del__(self, _warnings=warnings): |
58 |
| - if self._transport is not None: |
59 |
| - if hasattr(self._loop, 'is_closed'): |
60 |
| - if self._loop.is_closed(): |
61 |
| - return |
62 |
| - |
63 |
| - self._connector._release( |
64 |
| - self._key, self._request, self._transport, self._protocol, |
65 |
| - should_close=True) |
66 |
| - |
67 |
| - _warnings.warn("Unclosed connection {!r}".format(self), |
68 |
| - ResourceWarning) |
69 |
| - context = {'client_connection': self, |
70 |
| - 'message': 'Unclosed connection'} |
71 |
| - if self._source_traceback is not None: |
72 |
| - context['source_traceback'] = self._source_traceback |
73 |
| - self._loop.call_exception_handler(context) |
| 55 | + def __del__(self, _warnings=warnings): |
| 56 | + if self._transport is not None: |
| 57 | + if hasattr(self._loop, 'is_closed'): |
| 58 | + if self._loop.is_closed(): |
| 59 | + return |
| 60 | + |
| 61 | + self._connector._release( |
| 62 | + self._key, self._request, self._transport, self._protocol, |
| 63 | + should_close=True) |
| 64 | + |
| 65 | + _warnings.warn("Unclosed connection {!r}".format(self), |
| 66 | + ResourceWarning) |
| 67 | + context = {'client_connection': self, |
| 68 | + 'message': 'Unclosed connection'} |
| 69 | + if self._source_traceback is not None: |
| 70 | + context['source_traceback'] = self._source_traceback |
| 71 | + self._loop.call_exception_handler(context) |
74 | 72 |
|
75 | 73 | @property
|
76 | 74 | def loop(self):
|
@@ -142,22 +140,21 @@ def __init__(self, *, conn_timeout=None, keepalive_timeout=30,
|
142 | 140 |
|
143 | 141 | self.cookies = http.cookies.SimpleCookie()
|
144 | 142 |
|
145 |
| - if PY_341: |
146 |
| - def __del__(self, _warnings=warnings): |
147 |
| - if self._closed: |
148 |
| - return |
149 |
| - if not self._conns: |
150 |
| - return |
| 143 | + def __del__(self, _warnings=warnings): |
| 144 | + if self._closed: |
| 145 | + return |
| 146 | + if not self._conns: |
| 147 | + return |
151 | 148 |
|
152 |
| - self.close() |
| 149 | + self.close() |
153 | 150 |
|
154 |
| - _warnings.warn("Unclosed connector {!r}".format(self), |
155 |
| - ResourceWarning) |
156 |
| - context = {'connector': self, |
157 |
| - 'message': 'Unclosed connector'} |
158 |
| - if self._source_traceback is not None: |
159 |
| - context['source_traceback'] = self._source_traceback |
160 |
| - self._loop.call_exception_handler(context) |
| 151 | + _warnings.warn("Unclosed connector {!r}".format(self), |
| 152 | + ResourceWarning) |
| 153 | + context = {'connector': self, |
| 154 | + 'message': 'Unclosed connector'} |
| 155 | + if self._source_traceback is not None: |
| 156 | + context['source_traceback'] = self._source_traceback |
| 157 | + self._loop.call_exception_handler(context) |
161 | 158 |
|
162 | 159 | @property
|
163 | 160 | def force_close(self):
|
@@ -372,9 +369,6 @@ def _create_connection(self, req):
|
372 | 369 | raise NotImplementedError()
|
373 | 370 |
|
374 | 371 |
|
375 |
| -_SSL_OP_NO_COMPRESSION = getattr(ssl, "OP_NO_COMPRESSION", 0) |
376 |
| -_SSH_HAS_CREATE_DEFAULT_CONTEXT = hasattr(ssl, 'create_default_context') |
377 |
| - |
378 | 372 | _marker = object()
|
379 | 373 |
|
380 | 374 |
|
@@ -455,19 +449,10 @@ def ssl_context(self):
|
455 | 449 | sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
456 | 450 | sslcontext.options |= ssl.OP_NO_SSLv2
|
457 | 451 | sslcontext.options |= ssl.OP_NO_SSLv3
|
458 |
| - sslcontext.options |= _SSL_OP_NO_COMPRESSION |
| 452 | + sslcontext.options |= ssl.OP_NO_COMPRESSION |
459 | 453 | sslcontext.set_default_verify_paths()
|
460 |
| - elif _SSH_HAS_CREATE_DEFAULT_CONTEXT: |
461 |
| - # Python 3.4+ |
462 |
| - sslcontext = ssl.create_default_context() |
463 | 454 | else:
|
464 |
| - # Fallback for Python 3.3. |
465 |
| - sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) |
466 |
| - sslcontext.options |= ssl.OP_NO_SSLv2 |
467 |
| - sslcontext.options |= ssl.OP_NO_SSLv3 |
468 |
| - sslcontext.options |= _SSL_OP_NO_COMPRESSION |
469 |
| - sslcontext.set_default_verify_paths() |
470 |
| - sslcontext.verify_mode = ssl.CERT_REQUIRED |
| 455 | + sslcontext = ssl.create_default_context() |
471 | 456 | self._ssl_context = sslcontext
|
472 | 457 | return self._ssl_context
|
473 | 458 |
|
|
0 commit comments