This module provides utility functions that are used within Requests that are also useful for external consumption.
Function | add_dict_to_cookiejar |
Returns a CookieJar from a key/value dictionary. |
Function | dict_from_cookiejar |
Returns a key/value dictionary from a CookieJar. |
Function | get_encoding_from_headers |
Returns encodings from given HTTP Header Dict. |
Function | get_encodings_from_content |
Returns encodings from given content string. |
Function | get_unicode_from_response |
Returns the requested content back in unicode. |
Constant | DEFAULT_ACCEPT_ENCODING |
Undocumented |
Constant | DEFAULT_CA_BUNDLE_PATH |
Undocumented |
Constant | DEFAULT_PORTS |
Undocumented |
Constant | NETRC_FILES |
Undocumented |
Constant | UNRESERVED_SET |
Undocumented |
Function | _parse_content_type_header |
Returns content type and parameters from given header |
Function | address_in_network |
This function allows you to check if an IP belongs to a network subnet |
Function | atomic_open |
Write a file to the disk in an atomic fashion |
Function | check_header_validity |
Verifies that header value is a string which doesn't contain leading whitespace or return characters. This prevents unintended header injection. |
Function | default_headers |
|
Function | default_user_agent |
Return a string representing the default user agent. |
Function | dict_to_sequence |
Returns an internal sequence dictionary update. |
Function | dotted_netmask |
Converts mask from /xx format to xxx.xxx.xxx.xxx |
Function | extract_zipped_paths |
Replace nonexistent paths that look like they refer to a member of a zip archive with the location of an extracted copy of the target, or else just return the provided path unchanged. |
Function | from_key_val_list |
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., |
Function | get_auth_from_url |
Given a url with authentication components, extract them into a tuple of username,password. |
Function | get_environ_proxies |
Return a dict of environment proxies. |
Function | get_netrc_auth |
Returns the Requests tuple auth for a given url from netrc. |
Function | guess_filename |
Tries to guess the filename of the given object. |
Function | guess_json_utf |
|
Function | is_ipv4_address |
|
Function | is_valid_cidr |
Very simple check of the cidr format in no_proxy variable. |
Function | iter_slices |
Iterate over slices of a string. |
Function | parse_dict_header |
Parse lists of key, value pairs as described by RFC 2068 Section 2 and convert them into a python dict: |
Function | parse_header_links |
Return a list of parsed link headers proxies. |
Function | parse_list_header |
Parse lists as described by RFC 2068 Section 2. |
Function | prepend_scheme_if_needed |
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. |
Function | proxy_bypass |
Return True, if the host should be bypassed. |
Function | proxy_bypass_registry |
Undocumented |
Function | requote_uri |
Re-quote the given URI. |
Function | resolve_proxies |
This method takes proxy information from a request and configuration input to resolve a mapping of target proxies. This will consider settings such a NO_PROXY to strip proxy configurations. |
Function | rewind_body |
Move file pointer back to its recorded starting position so it can be read again on redirect. |
Function | select_proxy |
Select a proxy for the url, if applicable. |
Function | set_environ |
Set the environment variable 'env_name' to 'value' |
Function | should_bypass_proxies |
Returns whether we should bypass proxies or not. |
Function | stream_decode_response_unicode |
Stream decodes a iterator. |
Function | super_len |
Undocumented |
Function | to_key_val_list |
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., |
Function | unquote_header_value |
Unquotes a header value. (Reversal of quote_header_value ). This does not use the real unquoting but what browsers are actually using for quoting. |
Function | unquote_unreserved |
Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded. |
Function | urldefragauth |
Given a url remove the fragment and the authentication part. |
Constant | _CLEAN_HEADER_REGEX_BYTE |
Undocumented |
Constant | _CLEAN_HEADER_REGEX_STR |
Undocumented |
Variable | _null |
Undocumented |
Variable | _null2 |
Undocumented |
Variable | _null3 |
Undocumented |
Parameters | |
cj | CookieJar to insert cookies into. |
cookie_dict | Dict of key/values to insert into CookieJar. |
Returns | |
CookieJar | Undocumented |
Parameters | |
cj | CookieJar object to extract cookies from. |
Returns | |
dict | Undocumented |
Parameters | |
headers | dictionary to extract encoding from. |
Returns | |
str | Undocumented |
Parameters | |
content | bytestring to extract encodings from. |
Returns the requested content back in unicode.
Tried:
Parameters | |
r | Response object to get unicode content from. |
Returns | |
str | Undocumented |
Undocumented
Value |
|
Undocumented
Value |
|
Parameters | |
header | string |
Returns | |
tuple containing content type and dictionary of parameters |
This function allows you to check if an IP belongs to a network subnet
Returns | |
bool | Undocumented |
Parameters | |
header | tuple, in the format (name, value). |
Returns | |
str | Undocumented |
Converts mask from /xx format to xxx.xxx.xxx.xxx
Example: if mask is 24 function returns 255.255.255.0
Returns | |
str | Undocumented |
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') Traceback (most recent call last): ... ValueError: cannot encode objects that are not 2-tuples >>> from_key_val_list({'key': 'val'}) OrderedDict([('key', 'val')])
Returns | |
OrderedDict | Undocumented |
Returns | |
(str,str) | Undocumented |
Returns | |
dict | Undocumented |
Returns | |
bool | Undocumented |
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 | dict |
Return a list of parsed link headers proxies.
i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
Returns | |
list | Undocumented |
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 | list |
Returns | |
str | Undocumented |
Return True, if the host should be bypassed.
Checks proxy settings gathered from the environment, if specified, or the registry.
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.
Returns | |
str | Undocumented |
Parameters | |
request | Request or PreparedRequest |
proxies | A dictionary of schemes or schemes and hosts to proxy URLs |
trust_env | Boolean declaring whether to trust environment configs |
Returns | |
dict | Undocumented |
Parameters | |
url | The url being for the request |
proxies | A dictionary of schemes or schemes and hosts to proxy URLs |
Set the environment variable 'env_name' to 'value'
Save previous value, yield, and then restore the previous value stored in the environment variable 'env_name'.
If 'value' is None, do nothing
Returns | |
bool | Undocumented |
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') Traceback (most recent call last): ... ValueError: cannot encode objects that are not 2-tuples
Returns | |
list | Undocumented |
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. |
is_filename | Undocumented |
Returns | |
str | Undocumented |
Returns | |
str | Undocumented |