~rcj/vmbuilder/jenkins_kvm-test

« back to all changes in this revision

Viewing changes to pylib/requests/packages/urllib3/__init__.py

  • Committer: Ben Howard
  • Date: 2014-08-19 20:30:00 UTC
  • Revision ID: ben.howard@ubuntu.com-20140819203000-9gfgaryo1w41orxu
12.04 does not ship with a version of python3-requests, so we need
to provided it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# urllib3/__init__.py
 
2
# Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
 
3
#
 
4
# This module is part of urllib3 and is released under
 
5
# the MIT License: http://www.opensource.org/licenses/mit-license.php
 
6
 
 
7
"""
 
8
urllib3 - Thread-safe connection pooling and re-using.
 
9
"""
 
10
 
 
11
__author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'
 
12
__license__ = 'MIT'
 
13
__version__ = 'dev'
 
14
 
 
15
 
 
16
from .connectionpool import (
 
17
    HTTPConnectionPool,
 
18
    HTTPSConnectionPool,
 
19
    connection_from_url
 
20
)
 
21
 
 
22
from . import exceptions
 
23
from .filepost import encode_multipart_formdata
 
24
from .poolmanager import PoolManager, ProxyManager, proxy_from_url
 
25
from .response import HTTPResponse
 
26
from .util import make_headers, get_host, Timeout
 
27
 
 
28
 
 
29
# Set default logging handler to avoid "No handler found" warnings.
 
30
import logging
 
31
try:  # Python 2.7+
 
32
    from logging import NullHandler
 
33
except ImportError:
 
34
    class NullHandler(logging.Handler):
 
35
        def emit(self, record):
 
36
            pass
 
37
 
 
38
logging.getLogger(__name__).addHandler(NullHandler())
 
39
 
 
40
def add_stderr_logger(level=logging.DEBUG):
 
41
    """
 
42
    Helper for quickly adding a StreamHandler to the logger. Useful for
 
43
    debugging.
 
44
 
 
45
    Returns the handler after adding it.
 
46
    """
 
47
    # This method needs to be in this __init__.py to get the __name__ correct
 
48
    # even if urllib3 is vendored within another package.
 
49
    logger = logging.getLogger(__name__)
 
50
    handler = logging.StreamHandler()
 
51
    handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
 
52
    logger.addHandler(handler)
 
53
    logger.setLevel(level)
 
54
    logger.debug('Added an stderr logging handler to logger: %s' % __name__)
 
55
    return handler
 
56
 
 
57
# ... Clean up.
 
58
del NullHandler