Path: blob/master/venv/Lib/site-packages/urllib3/__init__.py
811 views
"""1urllib3 - Thread-safe connection pooling and re-using.2"""3from __future__ import absolute_import4import warnings56from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url78from . import exceptions9from .filepost import encode_multipart_formdata10from .poolmanager import PoolManager, ProxyManager, proxy_from_url11from .response import HTTPResponse12from .util.request import make_headers13from .util.url import get_host14from .util.timeout import Timeout15from .util.retry import Retry161718# Set default logging handler to avoid "No handler found" warnings.19import logging20from logging import NullHandler2122__author__ = "Andrey Petrov ([email protected])"23__license__ = "MIT"24__version__ = "1.25.9"2526__all__ = (27"HTTPConnectionPool",28"HTTPSConnectionPool",29"PoolManager",30"ProxyManager",31"HTTPResponse",32"Retry",33"Timeout",34"add_stderr_logger",35"connection_from_url",36"disable_warnings",37"encode_multipart_formdata",38"get_host",39"make_headers",40"proxy_from_url",41)4243logging.getLogger(__name__).addHandler(NullHandler())444546def add_stderr_logger(level=logging.DEBUG):47"""48Helper for quickly adding a StreamHandler to the logger. Useful for49debugging.5051Returns the handler after adding it.52"""53# This method needs to be in this __init__.py to get the __name__ correct54# even if urllib3 is vendored within another package.55logger = logging.getLogger(__name__)56handler = logging.StreamHandler()57handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s"))58logger.addHandler(handler)59logger.setLevel(level)60logger.debug("Added a stderr logging handler to logger: %s", __name__)61return handler626364# ... Clean up.65del NullHandler666768# All warning filters *must* be appended unless you're really certain that they69# shouldn't be: otherwise, it's very hard for users to use most Python70# mechanisms to silence them.71# SecurityWarning's always go off by default.72warnings.simplefilter("always", exceptions.SecurityWarning, append=True)73# SubjectAltNameWarning's should go off once per host74warnings.simplefilter("default", exceptions.SubjectAltNameWarning, append=True)75# InsecurePlatformWarning's don't vary between requests, so we keep it default.76warnings.simplefilter("default", exceptions.InsecurePlatformWarning, append=True)77# SNIMissingWarnings should go off only once.78warnings.simplefilter("default", exceptions.SNIMissingWarning, append=True)798081def disable_warnings(category=exceptions.HTTPWarning):82"""83Helper for quickly disabling all urllib3 warnings.84"""85warnings.simplefilter("ignore", category)868788