Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """
  2. urllib3 - Thread-safe connection pooling and re-using.
  3. """
  4. from __future__ import absolute_import
  5. import warnings
  6. from .connectionpool import (
  7. HTTPConnectionPool,
  8. HTTPSConnectionPool,
  9. connection_from_url
  10. )
  11. from . import exceptions
  12. from .filepost import encode_multipart_formdata
  13. from .poolmanager import PoolManager, ProxyManager, proxy_from_url
  14. from .response import HTTPResponse
  15. from .util.request import make_headers
  16. from .util.url import get_host
  17. from .util.timeout import Timeout
  18. from .util.retry import Retry
  19. # Set default logging handler to avoid "No handler found" warnings.
  20. import logging
  21. try: # Python 2.7+
  22. from logging import NullHandler
  23. except ImportError:
  24. class NullHandler(logging.Handler):
  25. def emit(self, record):
  26. pass
  27. __author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'
  28. __license__ = 'MIT'
  29. __version__ = '1.23'
  30. __all__ = (
  31. 'HTTPConnectionPool',
  32. 'HTTPSConnectionPool',
  33. 'PoolManager',
  34. 'ProxyManager',
  35. 'HTTPResponse',
  36. 'Retry',
  37. 'Timeout',
  38. 'add_stderr_logger',
  39. 'connection_from_url',
  40. 'disable_warnings',
  41. 'encode_multipart_formdata',
  42. 'get_host',
  43. 'make_headers',
  44. 'proxy_from_url',
  45. )
  46. logging.getLogger(__name__).addHandler(NullHandler())
  47. def add_stderr_logger(level=logging.DEBUG):
  48. """
  49. Helper for quickly adding a StreamHandler to the logger. Useful for
  50. debugging.
  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. # ... Clean up.
  63. del NullHandler
  64. # All warning filters *must* be appended unless you're really certain that they
  65. # shouldn't be: otherwise, it's very hard for users to use most Python
  66. # mechanisms to silence them.
  67. # SecurityWarning's always go off by default.
  68. warnings.simplefilter('always', exceptions.SecurityWarning, append=True)
  69. # SubjectAltNameWarning's should go off once per host
  70. warnings.simplefilter('default', exceptions.SubjectAltNameWarning, append=True)
  71. # InsecurePlatformWarning's don't vary between requests, so we keep it default.
  72. warnings.simplefilter('default', exceptions.InsecurePlatformWarning,
  73. append=True)
  74. # SNIMissingWarnings should go off only once.
  75. warnings.simplefilter('default', exceptions.SNIMissingWarning, append=True)
  76. def disable_warnings(category=exceptions.HTTPWarning):
  77. """
  78. Helper for quickly disabling all urllib3 warnings.
  79. """
  80. warnings.simplefilter('ignore', category)