Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
__init__.py103 linesDownload Raw Back to urllib3
1"""2Python HTTP library with thread-safe connection pooling, file post support, user friendly, and more3"""4from __future__ import absolute_import5 6# Set default logging handler to avoid "No handler found" warnings.7import logging8import warnings9from logging import NullHandler10 11from . import exceptions12from ._version import __version__13from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url14from .filepost import encode_multipart_formdata15from .poolmanager import PoolManager, ProxyManager, proxy_from_url16from .response import HTTPResponse17from .util.request import make_headers18from .util.retry import Retry19from .util.timeout import Timeout20from .util.url import get_host21 22# === NOTE TO REPACKAGERS AND VENDORS ===23# Please delete this block, this logic is only24# for urllib3 being distributed via PyPI.25# See: https://github.com/urllib3/urllib3/issues/268026try:27    import urllib3_secure_extra  # type: ignore # noqa: F40128except ImportError:29    pass30else:31    warnings.warn(32        "'urllib3[secure]' extra is deprecated and will be removed "33        "in a future release of urllib3 2.x. Read more in this issue: "34        "https://github.com/urllib3/urllib3/issues/2680",35        category=DeprecationWarning,36        stacklevel=2,37    )38 39__author__ = "Andrey Petrov (andrey.petrov@shazow.net)"40__license__ = "MIT"41__version__ = __version__42 43__all__ = (44    "HTTPConnectionPool",45    "HTTPSConnectionPool",46    "PoolManager",47    "ProxyManager",48    "HTTPResponse",49    "Retry",50    "Timeout",51    "add_stderr_logger",52    "connection_from_url",53    "disable_warnings",54    "encode_multipart_formdata",55    "get_host",56    "make_headers",57    "proxy_from_url",58)59 60logging.getLogger(__name__).addHandler(NullHandler())61 62 63def add_stderr_logger(level=logging.DEBUG):64    """65    Helper for quickly adding a StreamHandler to the logger. Useful for66    debugging.67 68    Returns the handler after adding it.69    """70    # This method needs to be in this __init__.py to get the __name__ correct71    # even if urllib3 is vendored within another package.72    logger = logging.getLogger(__name__)73    handler = logging.StreamHandler()74    handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s"))75    logger.addHandler(handler)76    logger.setLevel(level)77    logger.debug("Added a stderr logging handler to logger: %s", __name__)78    return handler79 80 81# ... Clean up.82del NullHandler83 84 85# All warning filters *must* be appended unless you're really certain that they86# shouldn't be: otherwise, it's very hard for users to use most Python87# mechanisms to silence them.88# SecurityWarning's always go off by default.89warnings.simplefilter("always", exceptions.SecurityWarning, append=True)90# SubjectAltNameWarning's should go off once per host91warnings.simplefilter("default", exceptions.SubjectAltNameWarning, append=True)92# InsecurePlatformWarning's don't vary between requests, so we keep it default.93warnings.simplefilter("default", exceptions.InsecurePlatformWarning, append=True)94# SNIMissingWarnings should go off only once.95warnings.simplefilter("default", exceptions.SNIMissingWarning, append=True)96 97 98def disable_warnings(category=exceptions.HTTPWarning):99    """100    Helper for quickly disabling all urllib3 warnings.101    """102    warnings.simplefilter("ignore", category)103 
codekingpro/portable-devtools · Team Ai