The sessions Module

requests.session

This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies).

class cloudfusion.third_party.requests_1_2_3.requests.sessions.Session

Bases: cloudfusion.third_party.requests_1_2_3.requests.sessions.SessionRedirectMixin

A Requests session.

Provides cookie persistience, connection-pooling, and configuration.

Basic Usage:

>>> import requests
>>> s = requests.Session()
>>> s.get('http://httpbin.org/get')
200
auth = None

Default Authentication tuple or object to attach to Request.

cert = None

SSL certificate default.

close()

Closes all adapters and as such the session

delete(url, **kwargs)

Sends a DELETE request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
get(url, **kwargs)

Sends a GET request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
get_adapter(url)

Returns the appropriate connnection adapter for the given URL.

head(url, **kwargs)

Sends a HEAD request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
headers = None

A case-insensitive dictionary of headers to be sent on each Request sent from this Session.

hooks = None

Event-handling hooks.

max_redirects = None

Maximum number of redirects allowed. If the request exceeds this limit, a TooManyRedirects exception is raised.

mount(prefix, adapter)

Registers a connection adapter to a prefix.

Adapters are sorted in descending order by key length.

options(url, **kwargs)

Sends a OPTIONS request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
params = None

Dictionary of querystring data to attach to each Request. The dictionary values may be lists for representing multivalued query parameters.

patch(url, data=None, **kwargs)

Sends a PATCH request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
post(url, data=None, **kwargs)

Sends a POST request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
proxies = None

Dictionary mapping protocol to the URL of the proxy (e.g. {‘http’: ‘foo.bar:3128’}) to be used on each Request.

put(url, data=None, **kwargs)

Sends a PUT request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
request(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None)

Constructs a Request, prepares it and sends it. Returns Response object.

Parameters:
  • method – method for the new Request object.
  • url – URL for the new Request object.
  • params – (optional) Dictionary or bytes to be sent in the query string for the Request.
  • data – (optional) Dictionary or bytes to send in the body of the Request.
  • headers – (optional) Dictionary of HTTP Headers to send with the Request.
  • cookies – (optional) Dict or CookieJar object to send with the Request.
  • files – (optional) Dictionary of ‘filename’: file-like-objects for multipart encoding upload.
  • auth – (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.
  • timeout – (optional) Float describing the timeout of the request.
  • allow_redirects – (optional) Boolean. Set to True by default.
  • proxies – (optional) Dictionary mapping protocol to the URL of the proxy.
  • stream – (optional) whether to immediately download the response content. Defaults to False.
  • verify – (optional) if True, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
  • cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
send(request, **kwargs)

Send a given PreparedRequest.

stream = None

Stream response content default.

trust_env = None

Should we trust the environment?

verify = None

SSL Verification default.

class cloudfusion.third_party.requests_1_2_3.requests.sessions.SessionRedirectMixin

Bases: object

resolve_redirects(resp, req, stream=False, timeout=None, verify=True, cert=None, proxies=None)

Receives a Response. Returns a generator of Responses.

cloudfusion.third_party.requests_1_2_3.requests.sessions.merge_setting(request_setting, session_setting, dict_class=<class 'cloudfusion.third_party.requests_1_2_3.requests.packages.urllib3.packages.ordered_dict.OrderedDict'>)

Determines appropriate setting for a given request, taking into account the explicit setting on that request, and the setting in the session. If a setting is a dictionary, they will be merged together using dict_class

cloudfusion.third_party.requests_1_2_3.requests.sessions.session()

Returns a Session for context-management.

The adapters Module

requests.adapters

This module contains the transport adapters that Requests uses to define and maintain connections.

class cloudfusion.third_party.requests_1_2_3.requests.adapters.BaseAdapter

Bases: object

The Base Transport Adapter

close()
send()
class cloudfusion.third_party.requests_1_2_3.requests.adapters.HTTPAdapter(pool_connections=10, pool_maxsize=10, max_retries=0, pool_block=False)

Bases: cloudfusion.third_party.requests_1_2_3.requests.adapters.BaseAdapter

The built-in HTTP Adapter for urllib3.

Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the Session class under the covers.

Parameters:
  • pool_connections – The number of urllib3 connection pools to cache.
  • pool_maxsize – The maximum number of connections to save in the pool.
  • max_retries – The maximum number of retries each connection should attempt.
  • pool_block – Whether the connection pool should block for connections.

Usage:

>>> import requests
>>> s = requests.Session()
>>> a = requests.adapters.HTTPAdapter()
>>> s.mount('http://', a)
add_headers(request, **kwargs)

Add any headers needed by the connection. Currently this adds a Proxy-Authorization header.

This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • request – The PreparedRequest to add headers to.
  • kwargs – The keyword arguments from the call to send().
build_response(req, resp)

Builds a Response object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter

Parameters:
  • req – The PreparedRequest used to generate the response.
  • resp – The urllib3 response object.
cert_verify(conn, url, verify, cert)

Verify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • conn – The urllib3 connection object associated with the cert.
  • url – The requested URL.
  • verify – Whether we should actually verify the certificate.
  • cert – The SSL certificate to verify.
close()

Disposes of any internal state.

Currently, this just closes the PoolManager, which closes pooled connections.

get_connection(url, proxies=None)

Returns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • url – The URL to connect to.
  • proxies – (optional) A Requests-style dictionary of proxies used on this request.
init_poolmanager(connections, maxsize, block=False)

Initializes a urllib3 PoolManager. This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • connections – The number of urllib3 connection pools to cache.
  • maxsize – The maximum number of connections to save in the pool.
  • block – Block when no free connections are available.
request_url(request, proxies)

Obtain the url to use when making the final request.

If the message is being sent through a proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL.

This shoudl not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • request – The PreparedRequest being sent.
  • proxies – A dictionary of schemes to proxy URLs.
send(request, stream=False, timeout=None, verify=True, cert=None, proxies=None)

Sends PreparedRequest object. Returns Response object.

Parameters:
  • request – The PreparedRequest being sent.
  • stream – (optional) Whether to stream the request content.
  • timeout – (optional) The timeout on the request.
  • verify – (optional) Whether to verify SSL certificates.
  • vert – (optional) Any user-provided SSL certificate to be trusted.
  • proxies – (optional) The proxies dictionary to apply to the request.

The cookies Module

Compatibility code to be able to use cookielib.CookieJar with requests.

requests.utils imports from here, so be careful with imports.

exception cloudfusion.third_party.requests_1_2_3.requests.cookies.CookieConflictError

Bases: exceptions.RuntimeError

There are two cookies that meet the criteria specified in the cookie jar. Use .get and .set and include domain and path args in order to be more specific.

class cloudfusion.third_party.requests_1_2_3.requests.cookies.MockRequest(request)

Bases: object

Wraps a requests.Request to mimic a urllib2.Request.

The code in cookielib.CookieJar expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie.

The original request object is read-only. The client is responsible for collecting the new headers via get_new_headers() and interpreting them appropriately. You probably want get_cookie_header, defined below.

add_header(key, val)

cookielib has no legitimate use for this method; add it back if you find one.

add_unredirected_header(name, value)
get_full_url()
get_header(name, default=None)
get_host()
get_new_headers()
get_origin_req_host()
get_type()
has_header(name)
is_unverifiable()
origin_req_host
unverifiable
class cloudfusion.third_party.requests_1_2_3.requests.cookies.MockResponse(headers)

Bases: object

Wraps a httplib.HTTPMessage to mimic a urllib.addinfourl.

...what? Basically, expose the parsed HTTP headers from the server response the way cookielib expects to see them.

Make a MockResponse for cookielib to read.

Parameters:headers – a httplib.HTTPMessage or analogous carrying the headers
getheaders(name)
info()
class cloudfusion.third_party.requests_1_2_3.requests.cookies.RequestsCookieJar(policy=None)

Bases: cookielib.CookieJar, _abcoll.MutableMapping

Compatibility class; is a cookielib.CookieJar, but exposes a dict interface.

This is the CookieJar we create by default for requests and sessions that don’t specify one, since some clients may expect response.cookies and session.cookies to support dict operations.

Don’t use the dict interface internally; it’s just for compatibility with with external client code. All requests code should work out of the box with externally provided instances of CookieJar, e.g., LWPCookieJar and FileCookieJar.

Caution: dictionary operations that are normally O(1) may be O(n).

Unlike a regular CookieJar, this class is pickleable.

_abc_cache = <_weakrefset.WeakSet object at 0x37fb350>
_abc_negative_cache = <_weakrefset.WeakSet object at 0x37fbb90>
_abc_negative_cache_version = 25
_abc_registry = <_weakrefset.WeakSet object at 0x37fb610>
_find(name, domain=None, path=None)

Requests uses this method internally to get cookie values. Takes as args name and optional domain and path. Returns a cookie.value. If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies.

_find_no_duplicates(name, domain=None, path=None)

__get_item__ and get call _find_no_duplicates – never used in Requests internally. Takes as args name and optional domain and path. Returns a cookie.value. Throws KeyError if cookie is not found and CookieConflictError if there are multiple cookies that match name and optionally domain and path.

copy()

Return a copy of this RequestsCookieJar.

get(name, default=None, domain=None, path=None)

Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. Caution: operation is O(n), not O(1).

get_dict(domain=None, path=None)

Takes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements.

items()

Dict-like items() that returns a list of name-value tuples from the jar. See keys() and values(). Allows client-code to call “dict(RequestsCookieJar) and get a vanilla python dict of key value pairs.

keys()

Dict-like keys() that returns a list of names of cookies from the jar. See values() and items().

list_domains()

Utility method to list all the domains in the jar.

list_paths()

Utility method to list all the paths in the jar.

multiple_domains()

Returns True if there are multiple domains in the jar. Returns False otherwise.

set(name, value, **kwargs)

Dict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains.

update(other)

Updates this jar with cookies from another CookieJar or dict-like

values()

Dict-like values() that returns a list of values of cookies from the jar. See keys() and items().

cloudfusion.third_party.requests_1_2_3.requests.cookies.cookiejar_from_dict(cookie_dict, cookiejar=None)

Returns a CookieJar from a key/value dictionary.

Parameters:cookie_dict – Dict of key/values to insert into CookieJar.

Make a cookie from underspecified parameters.

By default, the pair of name and value will be set for the domain ‘’ and sent on every request (this is sometimes called a “supercookie”).

cloudfusion.third_party.requests_1_2_3.requests.cookies.extract_cookies_to_jar(jar, request, response)

Extract the cookies from the response into a CookieJar.

Parameters:
  • jar – cookielib.CookieJar (not necessarily a RequestsCookieJar)
  • request – our own requests.Request object
  • response – urllib3.HTTPResponse object

Produce an appropriate Cookie header string to be sent with request, or None.

Convert a Morsel object into a Cookie containing the one k/v pair.

Unsets a cookie by name, by default over all domains and paths.

Wraps CookieJar.clear(), is O(n).

The auth Module

requests.auth

This module contains the authentication handlers for Requests.

class cloudfusion.third_party.requests_1_2_3.requests.auth.AuthBase

Bases: object

Base class that all auth implementations derive from

class cloudfusion.third_party.requests_1_2_3.requests.auth.HTTPBasicAuth(username, password)

Bases: cloudfusion.third_party.requests_1_2_3.requests.auth.AuthBase

Attaches HTTP Basic Authentication to the given Request object.

class cloudfusion.third_party.requests_1_2_3.requests.auth.HTTPDigestAuth(username, password)

Bases: cloudfusion.third_party.requests_1_2_3.requests.auth.AuthBase

Attaches HTTP Digest Authentication to the given Request object.

build_digest_header(method, url)
handle_401(r, **kwargs)

Takes the given response and tries digest-auth, if needed.

class cloudfusion.third_party.requests_1_2_3.requests.auth.HTTPProxyAuth(username, password)

Bases: cloudfusion.third_party.requests_1_2_3.requests.auth.HTTPBasicAuth

Attaches HTTP Proxy Authentication to a given Request object.

cloudfusion.third_party.requests_1_2_3.requests.auth._basic_auth_str(username, password)

Returns a Basic Auth string.

The models Module

requests.models

This module contains the primary objects that power Requests.

class cloudfusion.third_party.requests_1_2_3.requests.models.PreparedRequest

Bases: cloudfusion.third_party.requests_1_2_3.requests.models.RequestEncodingMixin, cloudfusion.third_party.requests_1_2_3.requests.models.RequestHooksMixin

The fully mutable PreparedRequest object, containing the exact bytes that will be sent to the server.

Generated from either a Request object or manually.

Usage:

>>> import requests
>>> req = requests.Request('GET', 'http://httpbin.org/get')
>>> r = req.prepare()
<PreparedRequest [GET]>

>>> s = requests.Session()
>>> s.send(r)
<Response [200]>
body = None

request body to send to the server.

headers = None

dictionary of HTTP headers.

hooks = None

dictionary of callback hooks, for internal usage.

method = None

HTTP verb to send to the server.

prepare_auth(auth, url='')

Prepares the given HTTP auth data.

prepare_body(data, files)

Prepares the given HTTP body data.

prepare_content_length(body)
prepare_cookies(cookies)

Prepares the given HTTP cookie data.

prepare_headers(headers)

Prepares the given HTTP headers.

prepare_hooks(hooks)

Prepares the given hooks.

prepare_method(method)

Prepares the given HTTP method.

prepare_url(url, params)

Prepares the given HTTP URL.

url = None

HTTP URL to send the request to.

class cloudfusion.third_party.requests_1_2_3.requests.models.Request(method=None, url=None, headers=None, files=None, data={}, params={}, auth=None, cookies=None, hooks=None)

Bases: cloudfusion.third_party.requests_1_2_3.requests.models.RequestHooksMixin

A user-created Request object.

Used to prepare a PreparedRequest, which is sent to the server.

Parameters:
  • method – HTTP method to use.
  • url – URL to send.
  • headers – dictionary of headers to send.
  • files – dictionary of {filename: fileobject} files to multipart upload.
  • data – the body to attach the request. If a dictionary is provided, form-encoding will take place.
  • params – dictionary of URL parameters to append to the URL.
  • auth – Auth handler or (user, pass) tuple.
  • cookies – dictionary or CookieJar of cookies to attach to this request.
  • hooks – dictionary of callback hooks, for internal usage.

Usage:

>>> import requests
>>> req = requests.Request('GET', 'http://httpbin.org/get')
>>> req.prepare()
<PreparedRequest [GET]>
prepare()

Constructs a PreparedRequest for transmission and returns it.

class cloudfusion.third_party.requests_1_2_3.requests.models.RequestEncodingMixin

Bases: object

static _encode_files(files, data)

Build the body for a multipart/form-data request.

Will successfully encode files when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but abritrary if parameters are supplied as a dict.

static _encode_params(data)

Encode parameters in a piece of data.

Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict.

path_url

Build the path URL to use.

class cloudfusion.third_party.requests_1_2_3.requests.models.RequestHooksMixin

Bases: object

deregister_hook(event, hook)

Deregister a previously registered hook. Returns True if the hook existed, False if not.

register_hook(event, hook)

Properly register a hook.

class cloudfusion.third_party.requests_1_2_3.requests.models.Response

Bases: object

The Response object, which contains a server’s response to an HTTP request.

apparent_encoding

The apparent encoding, provided by the lovely Charade library (Thanks, Ian!).

close()
content

Content of the response, in bytes.

cookies = None

A CookieJar of Cookies the server sent back.

elapsed = None

The amount of time elapsed between sending the request and the arrival of the response (as a timedelta)

encoding = None

Encoding to decode with when accessing r.text.

headers = None

Case-insensitive Dictionary of Response Headers. For example, headers['content-encoding'] will return the value of a 'Content-Encoding' response header.

history = None

A list of Response objects from the history of the Request. Any redirect responses will end up here. The list is sorted from the oldest to the most recent request.

iter_content(chunk_size=1, decode_unicode=False)

Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place.

iter_lines(chunk_size=512, decode_unicode=None)

Iterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses.

json(**kwargs)

Returns the json-encoded content of a response, if any.

Parameters:**kwargs – Optional arguments that json.loads takes.

Returns the parsed header links of the response, if any.

ok
raise_for_status()

Raises stored HTTPError, if one occurred.

raw = None

File-like object representation of response (for advanced usage). Requires that ``stream=True` on the request.

status_code = None

Integer Code of responded HTTP Status.

text

Content of the response, in unicode.

if Response.encoding is None and chardet module is available, encoding will be guessed.

url = None

Final URL location of Response.

The api Module

requests.api

This module implements the Requests API.

copyright:
  1. 2012 by Kenneth Reitz.
license:

Apache2, see LICENSE for more details.

cloudfusion.third_party.requests_1_2_3.requests.api.delete(url, **kwargs)

Sends a DELETE request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
cloudfusion.third_party.requests_1_2_3.requests.api.get(url, **kwargs)

Sends a GET request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
cloudfusion.third_party.requests_1_2_3.requests.api.head(url, **kwargs)

Sends a HEAD request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
cloudfusion.third_party.requests_1_2_3.requests.api.options(url, **kwargs)

Sends a OPTIONS request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
cloudfusion.third_party.requests_1_2_3.requests.api.patch(url, data=None, **kwargs)

Sends a PATCH request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
cloudfusion.third_party.requests_1_2_3.requests.api.post(url, data=None, **kwargs)

Sends a POST request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
cloudfusion.third_party.requests_1_2_3.requests.api.put(url, data=None, **kwargs)

Sends a PUT request. Returns Response object.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
cloudfusion.third_party.requests_1_2_3.requests.api.request(method, url, **kwargs)

Constructs and sends a Request. Returns Response object.

Parameters:
  • method – method for the new Request object.
  • url – URL for the new Request object.
  • params – (optional) Dictionary or bytes to be sent in the query string for the Request.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • headers – (optional) Dictionary of HTTP Headers to send with the Request.
  • cookies – (optional) Dict or CookieJar object to send with the Request.
  • files – (optional) Dictionary of ‘name’: file-like-objects (or {‘name’: (‘filename’, fileobj)}) for multipart encoding upload.
  • auth – (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
  • timeout – (optional) Float describing the timeout of the request.
  • allow_redirects – (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
  • proxies – (optional) Dictionary mapping protocol to the URL of the proxy.
  • verify – (optional) if True, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
  • stream – (optional) if False, the response content will be immediately downloaded.
  • cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.

Usage:

>>> import requests
>>> req = requests.request('GET', 'http://httpbin.org/get')
<Response [200]>

The utils Module

requests.utils

This module provides utility functions that are used within Requests that are also useful for external consumption.

cloudfusion.third_party.requests_1_2_3.requests.utils.add_dict_to_cookiejar(cj, cookie_dict)

Returns a CookieJar from a key/value dictionary.

Parameters:
  • cj – CookieJar to insert cookies into.
  • cookie_dict – Dict of key/values to insert into CookieJar.
cloudfusion.third_party.requests_1_2_3.requests.utils.default_headers()
cloudfusion.third_party.requests_1_2_3.requests.utils.default_user_agent()

Return a string representing the default user agent.

cloudfusion.third_party.requests_1_2_3.requests.utils.dict_from_cookiejar(cj)

Returns a key/value dictionary from a CookieJar.

Parameters:cj – CookieJar object to extract cookies from.
cloudfusion.third_party.requests_1_2_3.requests.utils.dict_to_sequence(d)

Returns an internal sequence dictionary update.

cloudfusion.third_party.requests_1_2_3.requests.utils.from_key_val_list(value)

Take an object and test to see if it can be represented as a dictionary. Unless it can not be represented as such, return an OrderedDict, e.g.,

>>> from_key_val_list([('key', 'val')])
OrderedDict([('key', 'val')])
>>> from_key_val_list('string')
ValueError: need more than 1 value to unpack
>>> from_key_val_list({'key': 'val'})
OrderedDict([('key', 'val')])
cloudfusion.third_party.requests_1_2_3.requests.utils.get_auth_from_url(url)

Given a url with authentication components, extract them into a tuple of username,password.

cloudfusion.third_party.requests_1_2_3.requests.utils.get_encoding_from_headers(headers)

Returns encodings from given HTTP Header Dict.

Parameters:headers – dictionary to extract encoding from.
cloudfusion.third_party.requests_1_2_3.requests.utils.get_encodings_from_content(content)

Returns encodings from given content string.

Parameters:content – bytestring to extract encodings from.
cloudfusion.third_party.requests_1_2_3.requests.utils.get_environ_proxies(url)

Return a dict of environment proxies.

cloudfusion.third_party.requests_1_2_3.requests.utils.get_netrc_auth(url)

Returns the Requests tuple auth for a given url from netrc.

cloudfusion.third_party.requests_1_2_3.requests.utils.get_unicode_from_response(r)

Returns the requested content back in unicode.

Parameters:r – Response object to get unicode content from.

Tried:

  1. charset from content-type
  2. every encodings from <meta ... charset=XXX>
  3. fall back and replace all unicode characters
cloudfusion.third_party.requests_1_2_3.requests.utils.guess_filename(obj)

Tries to guess the filename of the given object.

cloudfusion.third_party.requests_1_2_3.requests.utils.guess_json_utf(data)
cloudfusion.third_party.requests_1_2_3.requests.utils.iter_slices(string, slice_length)

Iterate over slices of a string.

cloudfusion.third_party.requests_1_2_3.requests.utils.parse_dict_header(value)

Parse lists of key, value pairs as described by RFC 2068 Section 2 and convert them into a python dict:

>>> d = parse_dict_header('foo="is a fish", bar="as well"')
>>> type(d) is dict
True
>>> sorted(d.items())
[('bar', 'as well'), ('foo', 'is a fish')]

If there is no value for a key it will be None:

>>> parse_dict_header('key_without_value')
{'key_without_value': None}

To create a header from the dict again, use the dump_header() function.

Parameters:value – a string with a dict header.
Returns:dict

Return a dict of parsed link headers proxies.

i.e. Link: <http:/.../front.jpeg>; rel=front; type=”image/jpeg”,<http://.../back.jpeg>; rel=back;type=”image/jpeg”

cloudfusion.third_party.requests_1_2_3.requests.utils.parse_list_header(value)

Parse lists as described by RFC 2068 Section 2.

In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Quotes are removed automatically after parsing.

It basically works like parse_set_header() just that items may appear multiple times and case sensitivity is preserved.

The return value is a standard list:

>>> parse_list_header('token, "quoted value"')
['token', 'quoted value']

To create a header from the list again, use the dump_header() function.

Parameters:value – a string with a list header.
Returns:list
cloudfusion.third_party.requests_1_2_3.requests.utils.prepend_scheme_if_needed(url, new_scheme)

Given a URL that may or may not have a scheme, prepend the given scheme. Does not replace a present scheme with the one provided as an argument.

cloudfusion.third_party.requests_1_2_3.requests.utils.requote_uri(uri)

Re-quote the given URI.

This function passes the given URI through an unquote/quote cycle to ensure that it is fully and consistently quoted.

cloudfusion.third_party.requests_1_2_3.requests.utils.stream_decode_response_unicode(iterator, r)

Stream decodes a iterator.

cloudfusion.third_party.requests_1_2_3.requests.utils.super_len(o)
cloudfusion.third_party.requests_1_2_3.requests.utils.to_key_val_list(value)

Take an object and test to see if it can be represented as a dictionary. If it can be, return a list of tuples, e.g.,

>>> to_key_val_list([('key', 'val')])
[('key', 'val')]
>>> to_key_val_list({'key': 'val'})
[('key', 'val')]
>>> to_key_val_list('string')
ValueError: cannot encode objects that are not 2-tuples.
cloudfusion.third_party.requests_1_2_3.requests.utils.unquote_header_value(value, is_filename=False)

Unquotes a header value. (Reversal of quote_header_value()). This does not use the real unquoting but what browsers are actually using for quoting.

Parameters:value – the header value to unquote.
cloudfusion.third_party.requests_1_2_3.requests.utils.unquote_unreserved(uri)

Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded.

The certs Module

certs.py

This module returns the preferred default CA certificate bundle.

If you are packaging Requests, e.g., for a Linux distribution or a managed environment, you can change the definition of where() to return a separately packaged CA bundle.

cloudfusion.third_party.requests_1_2_3.requests.certs.where()

Return the preferred certificate bundle.

The exceptions Module

requests.exceptions

This module contains the set of Requests’ exceptions.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.ConnectionError

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException

A Connection error occurred.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.HTTPError(*args, **kwargs)

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException

An HTTP error occurred.

Initializes HTTPError with optional response object.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.InvalidSchema

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException, exceptions.ValueError

See defaults.py for valid schemas.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.InvalidURL

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException, exceptions.ValueError

The URL provided was somehow invalid.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.MissingSchema

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException, exceptions.ValueError

The URL schema (e.g. http or https) is missing.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException

Bases: exceptions.RuntimeError

There was an ambiguous exception that occurred while handling your request.

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

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.ConnectionError

An SSL error occurred.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.Timeout

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException

The request timed out.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.TooManyRedirects

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException

Too many redirects.

exception cloudfusion.third_party.requests_1_2_3.requests.exceptions.URLRequired

Bases: cloudfusion.third_party.requests_1_2_3.requests.exceptions.RequestException

A valid URL is required to make a request.

The structures Module

requests.structures

Data structures that power Requests.

class cloudfusion.third_party.requests_1_2_3.requests.structures.CaseInsensitiveDict(data=None, **kwargs)

Bases: _abcoll.MutableMapping

A case-insensitive dict-like object.

Implements all methods and operations of collections.MutableMapping as well as dict’s copy. Also provides lower_items.

All keys are expected to be strings. The structure remembers the case of the last key to be set, and iter(instance), keys(), items(), iterkeys(), and iteritems() will contain case-sensitive keys. However, querying and contains testing is case insensitive:

cid = CaseInsensitiveDict() cid[‘Accept’] = ‘application/json’ cid[‘aCCEPT’] == ‘application/json’ # True list(cid) == [‘Accept’] # True

For example, headers['content-encoding'] will return the value of a 'Content-Encoding' response header, regardless of how the header name was originally stored.

If the constructor, .update, or equality comparison operations are given keys that have equal ``.lower()``s, the behavior is undefined.

_abc_cache = <_weakrefset.WeakSet object at 0x4b65950>
_abc_negative_cache = <_weakrefset.WeakSet object at 0x4b659d0>
_abc_negative_cache_version = 25
_abc_registry = <_weakrefset.WeakSet object at 0x4b65810>
copy()
lower_items()

Like iteritems(), but with all lowercase keys.

class cloudfusion.third_party.requests_1_2_3.requests.structures.IteratorProxy(i)

Bases: object

docstring for IteratorProxy

read(n)
class cloudfusion.third_party.requests_1_2_3.requests.structures.LookupDict(name=None)

Bases: dict

Dictionary lookup object.

get(key, default=None)

The hooks Module

requests.hooks

This module provides the capabilities for the Requests hooks system.

Available hooks:

response:
The response generated from a Request.
cloudfusion.third_party.requests_1_2_3.requests.hooks.default_hooks()
cloudfusion.third_party.requests_1_2_3.requests.hooks.dispatch_hook(key, hooks, hook_data, **kwargs)

Dispatches a hook dictionary on a given piece of data.