|
""" |
|
The _compat module is used for code which requires branching between different |
|
Python environments. It is excluded from the code coverage checks. |
|
""" |
|
|
|
import re |
|
import ssl |
|
import sys |
|
from types import ModuleType |
|
from typing import Optional |
|
|
|
|
|
|
|
|
|
try: |
|
import brotlicffi as brotli |
|
except ImportError: |
|
try: |
|
import brotli |
|
except ImportError: |
|
brotli = None |
|
|
|
|
|
zstd: Optional[ModuleType] = None |
|
try: |
|
import zstandard as zstd |
|
except (AttributeError, ImportError, ValueError): |
|
zstd = None |
|
else: |
|
|
|
|
|
|
|
|
|
_zstd_version = tuple( |
|
map(int, re.search(r"^([0-9]+)\.([0-9]+)", zstd.__version__).groups()) |
|
) |
|
if _zstd_version < (0, 18): |
|
zstd = None |
|
|
|
|
|
if sys.version_info >= (3, 10) or ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7): |
|
|
|
def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None: |
|
|
|
|
|
|
|
|
|
|
|
|
|
context.minimum_version = ssl.TLSVersion.TLSv1_2 |
|
|
|
else: |
|
|
|
def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None: |
|
|
|
|
|
context.options |= ssl.OP_NO_SSLv2 |
|
context.options |= ssl.OP_NO_SSLv3 |
|
context.options |= ssl.OP_NO_TLSv1 |
|
context.options |= ssl.OP_NO_TLSv1_1 |
|
|
|
|
|
__all__ = ["brotli", "set_minimum_tls_version_1_2"] |
|
|