Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / requests / packages / urllib3 / __init__.py @ 564

History | View | Annotate | Download (2.59 KB)

1
"""
2
urllib3 - Thread-safe connection pooling and re-using.
3
"""
4

    
5
from __future__ import absolute_import
6
import warnings
7

    
8
from .connectionpool import (
9
    HTTPConnectionPool,
10
    HTTPSConnectionPool,
11
    connection_from_url
12
)
13

    
14
from . import exceptions
15
from .filepost import encode_multipart_formdata
16
from .poolmanager import PoolManager, ProxyManager, proxy_from_url
17
from .response import HTTPResponse
18
from .util.request import make_headers
19
from .util.url import get_host
20
from .util.timeout import Timeout
21
from .util.retry import Retry
22

    
23

    
24
# Set default logging handler to avoid "No handler found" warnings.
25
import logging
26
try:  # Python 2.7+
27
    from logging import NullHandler
28
except ImportError:
29
    class NullHandler(logging.Handler):
30
        def emit(self, record):
31
            pass
32

    
33
__author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'
34
__license__ = 'MIT'
35
__version__ = '1.13.1'
36

    
37
__all__ = (
38
    'HTTPConnectionPool',
39
    'HTTPSConnectionPool',
40
    'PoolManager',
41
    'ProxyManager',
42
    'HTTPResponse',
43
    'Retry',
44
    'Timeout',
45
    'add_stderr_logger',
46
    'connection_from_url',
47
    'disable_warnings',
48
    'encode_multipart_formdata',
49
    'get_host',
50
    'make_headers',
51
    'proxy_from_url',
52
)
53

    
54
logging.getLogger(__name__).addHandler(NullHandler())
55

    
56

    
57
def add_stderr_logger(level=logging.DEBUG):
58
    """
59
    Helper for quickly adding a StreamHandler to the logger. Useful for
60
    debugging.
61

62
    Returns the handler after adding it.
63
    """
64
    # This method needs to be in this __init__.py to get the __name__ correct
65
    # even if urllib3 is vendored within another package.
66
    logger = logging.getLogger(__name__)
67
    handler = logging.StreamHandler()
68
    handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
69
    logger.addHandler(handler)
70
    logger.setLevel(level)
71
    logger.debug('Added a stderr logging handler to logger: %s' % __name__)
72
    return handler
73

    
74
# ... Clean up.
75
del NullHandler
76

    
77

    
78
# SecurityWarning's always go off by default.
79
warnings.simplefilter('always', exceptions.SecurityWarning, append=True)
80
# SubjectAltNameWarning's should go off once per host
81
warnings.simplefilter('default', exceptions.SubjectAltNameWarning)
82
# InsecurePlatformWarning's don't vary between requests, so we keep it default.
83
warnings.simplefilter('default', exceptions.InsecurePlatformWarning,
84
                      append=True)
85
# SNIMissingWarnings should go off only once.
86
warnings.simplefilter('default', exceptions.SNIMissingWarning)
87

    
88

    
89
def disable_warnings(category=exceptions.HTTPWarning):
90
    """
91
    Helper for quickly disabling all urllib3 warnings.
92
    """
93
    warnings.simplefilter('ignore', category)