comparison env/lib/python3.9/site-packages/urllib3/__init__.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """
2 Python HTTP library with thread-safe connection pooling, file post support, user friendly, and more
3 """
4 from __future__ import absolute_import
5
6 # Set default logging handler to avoid "No handler found" warnings.
7 import logging
8 import warnings
9 from logging import NullHandler
10
11 from . import exceptions
12 from ._version import __version__
13 from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
14 from .filepost import encode_multipart_formdata
15 from .poolmanager import PoolManager, ProxyManager, proxy_from_url
16 from .response import HTTPResponse
17 from .util.request import make_headers
18 from .util.retry import Retry
19 from .util.timeout import Timeout
20 from .util.url import get_host
21
22 __author__ = "Andrey Petrov (andrey.petrov@shazow.net)"
23 __license__ = "MIT"
24 __version__ = __version__
25
26 __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 )
42
43 logging.getLogger(__name__).addHandler(NullHandler())
44
45
46 def add_stderr_logger(level=logging.DEBUG):
47 """
48 Helper for quickly adding a StreamHandler to the logger. Useful for
49 debugging.
50
51 Returns the handler after adding it.
52 """
53 # This method needs to be in this __init__.py to get the __name__ correct
54 # even if urllib3 is vendored within another package.
55 logger = logging.getLogger(__name__)
56 handler = logging.StreamHandler()
57 handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s"))
58 logger.addHandler(handler)
59 logger.setLevel(level)
60 logger.debug("Added a stderr logging handler to logger: %s", __name__)
61 return handler
62
63
64 # ... Clean up.
65 del NullHandler
66
67
68 # All warning filters *must* be appended unless you're really certain that they
69 # shouldn't be: otherwise, it's very hard for users to use most Python
70 # mechanisms to silence them.
71 # SecurityWarning's always go off by default.
72 warnings.simplefilter("always", exceptions.SecurityWarning, append=True)
73 # SubjectAltNameWarning's should go off once per host
74 warnings.simplefilter("default", exceptions.SubjectAltNameWarning, append=True)
75 # InsecurePlatformWarning's don't vary between requests, so we keep it default.
76 warnings.simplefilter("default", exceptions.InsecurePlatformWarning, append=True)
77 # SNIMissingWarnings should go off only once.
78 warnings.simplefilter("default", exceptions.SNIMissingWarning, append=True)
79
80
81 def disable_warnings(category=exceptions.HTTPWarning):
82 """
83 Helper for quickly disabling all urllib3 warnings.
84 """
85 warnings.simplefilter("ignore", category)