Repository: encode/httpx
File: httpx/_config.py (Python)

Code before:

import certifi

from ._models import Headers
from ._types import HeaderTypes, TimeoutTypes
from ._urls import URL

__all__ = ["Limits", "Proxy", "SSLContext", "Timeout"]


class UnsetType:
    pass  # pragma: no cover


UNSET = UnsetType()


class SSLContext(ssl.SSLContext):
    def __init__(
        self,
        verify: bool = True,
    ) -> None:
        super().__init__()
        self._verify = verify

        # Our SSL setup here is similar to the stdlib `ssl.create_default_context()`
        # implementation, except with `certifi` used for certificate verification.
        if not verify:
            self.check_hostname = False
            self.verify_mode = ssl.CERT_NONE
            return

        self.verify_mode = ssl.CERT_REQUIRED
        self.check_hostname = True

        # Use stricter verify flags where possible.
        if hasattr(ssl, "VERIFY_X509_PARTIAL_CHAIN"):  # pragma: nocover
            self.verify_flags |= ssl.VERIFY_X509_PARTIAL_CHAIN
        if hasattr(ssl, "VERIFY_X509_STRICT"):  # pragma: nocover
            self.verify_flags |= ssl.VERIFY_X509_STRICT

        # Default to `certifi` for certificiate verification.
        self.load_verify_locations(cafile=certifi.where())

        # OpenSSL keylog file support.
        if hasattr(self, "keylog_filename"):
            keylogfile = os.environ.get("SSLKEYLOGFILE")
            if keylogfile and not sys.flags.ignore_environment:
                self.keylog_filename = keylogfile

    def __repr__(self) -> str:

Review comment (suggestion):
```suggestion
        # ssl.SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION,
        # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE
        # by default. (from `ssl.create_default_context`)
        super().__init__()
```

Code after:

import certifi

from ._models import Headers
from ._types import HeaderTypes, TimeoutTypes
from ._urls import URL

__all__ = ["Limits", "Proxy", "SSLContext", "Timeout"]


class UnsetType:
    pass  # pragma: no cover


UNSET = UnsetType()


class SSLContext(ssl.SSLContext):
    def __init__(
        self,
        verify: bool = True,
    ) -> None:
        # ssl.SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION,
        # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE
        # by default. (from `ssl.create_default_context`)
        super().__init__()
        self._verify = verify

        # Our SSL setup here is similar to the stdlib `ssl.create_default_context()`
        # implementation, except with `certifi` used for certificate verification.
        if not verify:
            self.check_hostname = False
            self.verify_mode = ssl.CERT_NONE
            return

        self.verify_mode = ssl.CERT_REQUIRED
        self.check_hostname = True

        # Use stricter verify flags where possible.
        if hasattr(ssl, "VERIFY_X509_PARTIAL_CHAIN"):  # pragma: nocover
            self.verify_flags |= ssl.VERIFY_X509_PARTIAL_CHAIN
        if hasattr(ssl, "VERIFY_X509_STRICT"):  # pragma: nocover
            self.verify_flags |= ssl.VERIFY_X509_STRICT

        # Default to `certifi` for certificiate verification.
        self.load_verify_locations(cafile=certifi.where())

        # OpenSSL keylog file support.
        if hasattr(self, "keylog_filename"):
            keylogfile = os.environ.get("SSLKEYLOGFILE")
            if keylogfile and not sys.flags.ignore_environment: