The util Module

class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.Url

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.Url

Datastructure for representing an HTTP URL. Used as a return value for parse_url().

hostname

For backwards-compatibility with urlparse. We’re nice like that.

request_uri

Absolute path including the query string.

slots = ()
cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.assert_fingerprint(cert, fingerprint)

Checks if given fingerprint matches the supplied certificate.

Parameters:
  • cert – Certificate as bytes object.
  • fingerprint – Fingerprint as string of hexdigits, can be interspersed by colons.
cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.get_host(url)

Deprecated. Use parse_url() instead.

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.is_connection_dropped(conn)

Returns True if the connection is dropped and should be closed.

Parameters:connhttplib.HTTPConnection object.

Note: For platforms like AppEngine, this will always return False to let the platform handle connection recycling transparently for us.

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.make_headers(keep_alive=None, accept_encoding=None, user_agent=None, basic_auth=None)

Shortcuts for generating request headers.

Parameters:
  • keep_alive – If True, adds ‘connection: keep-alive’ header.
  • accept_encoding – Can be a boolean, list, or string. True translates to ‘gzip,deflate’. List will get joined by comma. String will be used as provided.
  • user_agent – String representing the user-agent you want, such as “python-urllib3/0.6”
  • basic_auth – Colon-separated username:password string for ‘authorization: basic ...’ auth header.

Example:

>>> make_headers(keep_alive=True, user_agent="Batman/1.0")
{'connection': 'keep-alive', 'user-agent': 'Batman/1.0'}
>>> make_headers(accept_encoding=True)
{'accept-encoding': 'gzip,deflate'}
cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.parse_url(url)

Given a url, return a parsed Url namedtuple. Best-effort is performed to parse incomplete urls. Fields not provided will be None.

Partly backwards-compatible with urlparse.

Example:

>>> parse_url('http://google.com/mail/')
Url(scheme='http', host='google.com', port=None, path='/', ...)
>>> parse_url('google.com:80')
Url(scheme=None, host='google.com', port=80, path=None, ...)
>>> parse_url('/foo?bar')
Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...)
cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.resolve_cert_reqs(candidate)

Resolves the argument to a numeric constant, which can be passed to the wrap_socket function/method from the ssl module. Defaults to ssl.CERT_NONE. If given a string it is assumed to be the name of the constant in the ssl module or its abbrevation. (So you can specify REQUIRED instead of CERT_REQUIRED. If it’s neither None nor a string we assume it is already the numeric constant which can directly be passed to wrap_socket.

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.resolve_ssl_version(candidate)

like resolve_cert_reqs

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.split_first(s, delims)

Given a string and an iterable of delimiters, split on the first found delimiter. Return two split parts and the matched delimiter.

If not found, then the first part is the full input string.

Example:

>>> split_first('foo/bar?baz', '?/=')
('foo', 'bar?baz', '/')
>>> split_first('foo/bar?baz', '123')
('foo/bar?baz', '', None)

Scales linearly with number of delims. Not ideal for large number of delims.

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.util.ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None, ca_certs=None, server_hostname=None, ssl_version=None)

The response Module

class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.response.DeflateDecoder

Bases: object

decompress(data)
class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.response.HTTPResponse(body='', headers=None, status=0, version=0, reason=None, strict=0, preload_content=True, decode_content=True, original_response=None, pool=None, connection=None)

Bases: object

HTTP Response container.

Backwards-compatible to httplib’s HTTPResponse but the response body is loaded and decoded on-demand when the data property is accessed.

Extra parameters for behaviour not present in httplib.HTTPResponse:

Parameters:
  • preload_content – If True, the response’s body will be preloaded during construction.
  • decode_content – If True, attempts to decode specific content-encoding’s based on headers (like ‘gzip’ and ‘deflate’) will be skipped and raw data will be used instead.
  • original_response – When this HTTPResponse wrapper is generated from an httplib.HTTPResponse object, it’s convenient to include the original for debug purposes. It’s otherwise unused.
CONTENT_DECODERS = ['gzip', 'deflate']
data
classmethod from_httplib(ResponseCls, r, **response_kw)

Given an httplib.HTTPResponse instance r, return a corresponding urllib3.response.HTTPResponse object.

Remaining parameters are passed to the HTTPResponse constructor, along with original_response=r.

get_redirect_location()

Should we redirect and where to?

Returns:Truthy redirect location string if we got a redirect status code and valid location. None if redirect status and no location. False if not a redirect status code.
getheader(name, default=None)
getheaders()
read(amt=None, decode_content=None, cache_content=False)

Similar to httplib.HTTPResponse.read(), but with two additional parameters: decode_content and cache_content.

Parameters:
  • amt – How much of the content to read. If specified, caching is skipped because it doesn’t make sense to cache partial content as the full response.
  • decode_content – If True, will attempt to decode the body based on the ‘content-encoding’ header.
  • cache_content – If True, will save the returned data such that the same result is returned despite of the state of the underlying file object. This is useful if you want the .data property to continue working after having .read() the file object. (Overridden if amt is set.)
release_conn()
cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.response._get_decoder(mode)

The connectionpool Module

class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.connectionpool.ConnectionPool(host, port=None)

Bases: object

Base class for all connection pools, such as HTTPConnectionPool and HTTPSConnectionPool.

QueueCls

alias of LifoQueue

scheme = None
class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.connectionpool.HTTPConnectionPool(host, port=None, strict=False, timeout=None, maxsize=1, block=False, headers=None)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.connectionpool.ConnectionPool, cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.request.RequestMethods

Thread-safe connection pool for one host.

Parameters:
  • host – Host used for this HTTP Connection (e.g. “localhost”), passed into httplib.HTTPConnection.
  • port – Port used for this HTTP Connection (None is equivalent to 80), passed into httplib.HTTPConnection.
  • strict – Causes BadStatusLine to be raised if the status line can’t be parsed as a valid HTTP/1.0 or 1.1 status line, passed into httplib.HTTPConnection.
  • timeout – Socket timeout for each individual connection, can be a float. None disables timeout.
  • maxsize – Number of connections to save that can be reused. More than 1 is useful in multithreaded situations. If block is set to false, more connections will be created but they will not be saved once they’ve been used.
  • block – If set to True, no more than maxsize connections will be used at a time. When no free connections are available, the call will block until a connection has been released. This is a useful side effect for particular multithreaded situations where one does not want to use more than maxsize connections per host to prevent flooding.
  • headers – Headers to include with all requests, unless other headers are given explicitly.
_get_conn(timeout=None)

Get a connection. Will return a pooled connection if one is available.

If no connections are available and :prop:`.block` is False, then a fresh connection is returned.

Parameters:timeout – Seconds to wait before giving up and raising urllib3.exceptions.EmptyPoolError if the pool is empty and :prop:`.block` is True.
_make_request(conn, method, url, timeout=<object object at 0x4e04a70>, **httplib_request_kw)

Perform a request on a given httplib connection object taken from our pool.

_new_conn()

Return a fresh httplib.HTTPConnection.

_put_conn(conn)

Put a connection back into the pool.

Parameters:conn – Connection object for the current host and port as returned by _new_conn() or _get_conn().

If the pool is already full, the connection is closed and discarded because we exceeded maxsize. If connections are discarded frequently, then maxsize should be increased.

If the pool is closed, then the connection will be closed and discarded.

close()

Close all pooled connections and disable the pool.

is_same_host(url)

Check if the given url is a member of the same host as this connection pool.

scheme = 'http'
urlopen(method, url, body=None, headers=None, retries=3, redirect=True, assert_same_host=True, timeout=<object object at 0x4e04a70>, pool_timeout=None, release_conn=None, **response_kw)

Get a connection from the pool and perform an HTTP request. This is the lowest level call for making a request, so you’ll need to specify all the raw details.

Note

More commonly, it’s appropriate to use a convenience method provided by RequestMethods, such as request().

Note

release_conn will only behave as expected if preload_content=False because we want to make preload_content=False the default behaviour someday soon without breaking backwards compatibility.

Parameters:
  • method – HTTP request method (such as GET, POST, PUT, etc.)
  • body – Data to send in the request body (useful for creating POST requests, see HTTPConnectionPool.post_url for more convenience).
  • headers – Dictionary of custom headers to send, such as User-Agent, If-None-Match, etc. If None, pool headers are used. If provided, these headers completely replace any pool-specific headers.
  • retries – Number of retries to allow before raising a MaxRetryError exception.
  • redirect – If True, automatically handle redirects (status codes 301, 302, 303, 307). Each redirect counts as a retry.
  • assert_same_host – If True, will make sure that the host of the pool requests is consistent else will raise HostChangedError. When False, you can use the pool on an HTTP proxy and request foreign hosts.
  • timeout – If specified, overrides the default timeout for this one request.
  • pool_timeout – If set and the pool is set to block=True, then this method will block for pool_timeout seconds and raise EmptyPoolError if no connection is available within the time period.
  • release_conn – If False, then the urlopen call will not release the connection back into the pool once a response is received (but will release if you read the entire contents of the response such as when preload_content=True). This is useful if you’re not preloading the response’s content immediately. You will need to call r.release_conn() on the response r to return the connection back into the pool. If None, it takes the value of response_kw.get('preload_content', True).
  • **response_kw – Additional parameters are passed to urllib3.response.HTTPResponse.from_httplib()
class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.connectionpool.HTTPSConnectionPool(host, port=None, strict=False, timeout=None, maxsize=1, block=False, headers=None, key_file=None, cert_file=None, cert_reqs=None, ca_certs=None, ssl_version=None, assert_hostname=None, assert_fingerprint=None)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.connectionpool.HTTPConnectionPool

Same as HTTPConnectionPool, but HTTPS.

When Python is compiled with the ssl module, then VerifiedHTTPSConnection is used, which can verify certificates, instead of httplib.HTTPSConnection.

VerifiedHTTPSConnection uses one of assert_fingerprint, assert_hostname and host in this order to verify connections.

The key_file, cert_file, cert_reqs, ca_certs and ssl_version are only used if ssl is available and are fed into urllib3.util.ssl_wrap_socket() to upgrade the connection socket into an SSL socket.

_new_conn()

Return a fresh httplib.HTTPSConnection.

scheme = 'https'
class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.connectionpool.VerifiedHTTPSConnection(host, port=None, key_file=None, cert_file=None, strict=None, timeout=<object object at 0x2ade38bfa230>, source_address=None)

Bases: httplib.HTTPSConnection

Based on httplib.HTTPSConnection but wraps the socket with SSL certification.

ca_certs = None
cert_reqs = None
connect()
set_cert(key_file=None, cert_file=None, cert_reqs=None, ca_certs=None, assert_hostname=None, assert_fingerprint=None)
ssl_version = None
cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.connectionpool.connection_from_url(url, **kw)

Given a url, return an ConnectionPool instance of its host.

This is a shortcut for not having to parse out the scheme, host, and port of the url before creating an ConnectionPool instance.

Parameters:
  • url – Absolute URL string that must include the scheme. Port is optional.
  • **kw – Passes additional parameters to the constructor of the appropriate ConnectionPool. Useful for specifying things like timeout, maxsize, headers, etc.

Example:

>>> conn = connection_from_url('http://google.com/')
>>> r = conn.request('GET', '/')

The poolmanager Module

class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.poolmanager.PoolManager(num_pools=10, headers=None, **connection_pool_kw)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.request.RequestMethods

Allows for arbitrary requests while transparently keeping track of necessary connection pools for you.

Parameters:
  • num_pools – Number of connection pools to cache before discarding the least recently used pool.
  • headers – Headers to include with all requests, unless other headers are given explicitly.
  • **connection_pool_kw – Additional parameters are used to create fresh urllib3.connectionpool.ConnectionPool instances.

Example:

>>> manager = PoolManager(num_pools=2)
>>> r = manager.request('GET', 'http://google.com/')
>>> r = manager.request('GET', 'http://google.com/mail')
>>> r = manager.request('GET', 'http://yahoo.com/')
>>> len(manager.pools)
2
_new_pool(scheme, host, port)

Create a new ConnectionPool based on host, port and scheme.

This method is used to actually create the connection pools handed out by connection_from_url() and companion methods. It is intended to be overridden for customization.

clear()

Empty our store of pools and direct them all to close.

This will not affect in-flight connections, but they will not be re-used after completion.

connection_from_host(host, port=None, scheme='http')

Get a ConnectionPool based on the host, port, and scheme.

If port isn’t given, it will be derived from the scheme using urllib3.connectionpool.port_by_scheme.

connection_from_url(url)

Similar to urllib3.connectionpool.connection_from_url() but doesn’t pass any additional parameters to the urllib3.connectionpool.ConnectionPool constructor.

Additional parameters are taken from the PoolManager constructor.

urlopen(method, url, redirect=True, **kw)

Same as urllib3.connectionpool.HTTPConnectionPool.urlopen() with custom cross-host redirect logic and only sends the request-uri portion of the url.

The given url parameter must be absolute, such that an appropriate urllib3.connectionpool.ConnectionPool can be chosen for it.

class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.poolmanager.ProxyManager(proxy_pool)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.request.RequestMethods

Given a ConnectionPool to a proxy, the ProxyManager’s urlopen method will make requests to any url through the defined proxy. The ProxyManager class will automatically set the ‘Host’ header if it is not provided.

_set_proxy_headers(url, headers=None)

Sets headers needed by proxies: specifically, the Accept and Host headers. Only sets headers not provided by the user.

urlopen(method, url, **kw)

Same as HTTP(S)ConnectionPool.urlopen, url must be absolute.

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.poolmanager.proxy_from_url(url, **pool_kw)

The urllib3 Package

urllib3 - Thread-safe connection pooling and re-using.

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.add_stderr_logger(level=10)

Helper for quickly adding a StreamHandler to the logger. Useful for debugging.

Returns the handler after adding it.

The _collections Module

class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3._collections.RecentlyUsedContainer(maxsize=10, dispose_func=None)

Bases: _abcoll.MutableMapping

Provides a thread-safe dict-like container which maintains up to maxsize keys while throwing away the least-recently-used keys beyond maxsize.

Parameters:
  • maxsize – Maximum number of recent elements to retain.
  • dispose_func – Every time an item is evicted from the container, dispose_func(value) is called. Callback which will get called
ContainerCls

alias of OrderedDict

_abc_cache = <_weakrefset.WeakSet object at 0x3b7dfd0>
_abc_negative_cache = <_weakrefset.WeakSet object at 0x3b7d390>
_abc_negative_cache_version = 25
_abc_registry = <_weakrefset.WeakSet object at 0x3b7d510>
clear()
keys()

The filepost Module

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.filepost.choose_boundary()

Our embarassingly-simple replacement for mimetools.choose_boundary.

cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.filepost.encode_multipart_formdata(fields, boundary=None)

Encode a dictionary of fields using the multipart/form-data MIME format.

Parameters:
  • fields

    Dictionary of fields or list of (key, value) or (key, value, MIME type) field tuples. The key is treated as the field name, and the value as the body of the form-data bytes. If the value is a tuple of two elements, then the first element is treated as the filename of the form-data section and a suitable MIME type is guessed based on the filename. If the value is a tuple of three elements, then the third element is treated as an explicit MIME type of the form-data section.

    Field names and filenames must be unicode.

  • boundary – If not specified, then a random boundary will be generated using mimetools.choose_boundary().
cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.filepost.get_content_type(filename)
cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.filepost.iter_fields(fields)

Iterate over fields.

Supports list of (k, v) tuples and dicts.

The request Module

class cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.request.RequestMethods(headers=None)

Bases: object

Convenience mixin for classes who implement a urlopen() method, such as HTTPConnectionPool and PoolManager.

Provides behavior for making common types of HTTP request methods and decides which type of request field encoding to use.

Specifically,

request_encode_url() is for sending requests whose fields are encoded in the URL (such as GET, HEAD, DELETE).

request_encode_body() is for sending requests whose fields are encoded in the body of the request using multipart or www-orm-urlencoded (such as for POST, PUT, PATCH).

request() is for making any kind of request, it will look up the appropriate encoding format and use one of the above two methods to make the request.

Initializer parameters:

Parameters:headers – Headers to include with all requests, unless other headers are given explicitly.
_encode_body_methods = set(['PUT', 'POST', 'TRACE', 'PATCH'])
_encode_url_methods = set(['HEAD', 'GET', 'OPTIONS', 'DELETE'])
request(method, url, fields=None, headers=None, **urlopen_kw)

Make a request using urlopen() with the appropriate encoding of fields based on the method used.

This is a convenience method that requires the least amount of manual effort. It can be used in most situations, while still having the option to drop down to more specific methods when necessary, such as request_encode_url(), request_encode_body(), or even the lowest level urlopen().

request_encode_body(method, url, fields=None, headers=None, encode_multipart=True, multipart_boundary=None, **urlopen_kw)

Make a request using urlopen() with the fields encoded in the body. This is useful for request methods like POST, PUT, PATCH, etc.

When encode_multipart=True (default), then urllib3.filepost.encode_multipart_formdata() is used to encode the payload with the appropriate content type. Otherwise urllib.urlencode() is used with the ‘application/x-www-form-urlencoded’ content type.

Multipart encoding must be used when posting files, and it’s reasonably safe to use it in other times too. However, it may break request signing, such as with OAuth.

Supports an optional fields parameter of key/value strings AND key/filetuple. A filetuple is a (filename, data, MIME type) tuple where the MIME type is optional. For example:

fields = {
    'foo': 'bar',
    'fakefile': ('foofile.txt', 'contents of foofile'),
    'realfile': ('barfile.txt', open('realfile').read()),
    'typedfile': ('bazfile.bin', open('bazfile').read(),
                  'image/jpeg'),
    'nonamefile': 'contents of nonamefile field',
}

When uploading a file, providing a filename (the first parameter of the tuple) is optional but recommended to best mimick behavior of browsers.

Note that if headers are supplied, the ‘Content-Type’ header will be overwritten because it depends on the dynamic random boundary string which is used to compose the body of the request. The random boundary string can be explicitly set with the multipart_boundary parameter.

request_encode_url(method, url, fields=None, **urlopen_kw)

Make a request using urlopen() with the fields encoded in the url. This is useful for request methods like GET, HEAD, DELETE, etc.

urlopen(method, url, body=None, headers=None, encode_multipart=True, multipart_boundary=None, **kw)

The exceptions Module

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.ClosedPoolError(pool, message)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.PoolError

Raised when a request enters a pool after the pool has been closed.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.DecodeError

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.HTTPError

Raised when automatic decoding based on Content-Type fails.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.EmptyPoolError(pool, message)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.PoolError

Raised when a pool runs out of connections and no more are allowed.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.HTTPError

Bases: exceptions.Exception

Base exception used by this module.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.HostChangedError(pool, url, retries=3)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.RequestError

Raised when an existing pool gets a request for a foreign host.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.LocationParseError(location)

Bases: exceptions.ValueError, cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.HTTPError

Raised when get_host or similar fails to parse the URL input.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.MaxRetryError(pool, url, reason=None)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.RequestError

Raised when the maximum number of retries is exceeded.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.PoolError(pool, message)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.HTTPError

Base exception for errors caused within a pool.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.RequestError(pool, url, message)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.PoolError

Base exception for PoolErrors that have associated URLs.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.SSLError

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.HTTPError

Raised when SSL certificate fails in an HTTPS connection.

exception cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.TimeoutError(pool, url, message)

Bases: cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.exceptions.RequestError

Raised when a socket timeout occurs.