requests.utils ~~~~~~~~~~~~~~ This module provides utility functions that are used within Requests that are also useful for external consumption.
Function | add |
Returns a CookieJar from a key/value dictionary. |
Function | address |
This function allows you to check if an IP belongs to a network subnet |
Function | atomic |
Write a file to the disk in an atomic fashion |
Function | check |
Verifies that header parts don't contain leading whitespace reserved characters, or return characters. |
Function | default |
:rtype: requests.structures.CaseInsensitiveDict |
Function | default |
Return a string representing the default user agent. |
Function | dict |
Returns a key/value dictionary from a CookieJar. |
Function | dict |
Returns an internal sequence dictionary update. |
Function | dotted |
Converts mask from /xx format to xxx.xxx.xxx.xxx |
Function | extract |
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 |
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 |
Given a url with authentication components, extract them into a tuple of username,password. |
Function | get |
Returns encodings from given HTTP Header Dict. |
Function | get |
Returns encodings from given content string. |
Function | get |
Return a dict of environment proxies. |
Function | get |
Returns the Requests tuple auth for a given url from netrc. |
Function | get |
Returns the requested content back in unicode. |
Function | guess |
Tries to guess the filename of the given object. |
Function | guess |
:rtype: str |
Function | is |
:rtype: bool |
Function | is |
Very simple check of the cidr format in no_proxy variable. |
Function | iter |
Iterate over slices of a string. |
Function | parse |
Parse lists of key, value pairs as described by RFC 2068 Section 2 and convert them into a python dict: |
Function | parse |
Return a list of parsed link headers proxies. |
Function | parse |
Parse lists as described by RFC 2068 Section 2. |
Function | prepend |
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 |
Return True, if the host should be bypassed. |
Function | proxy |
Undocumented |
Function | requote |
Re-quote the given URI. |
Function | resolve |
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 |
Move file pointer back to its recorded starting position so it can be read again on redirect. |
Function | select |
Select a proxy for the url, if applicable. |
Function | set |
Set the environment variable 'env_name' to 'value' |
Function | should |
Returns whether we should bypass proxies or not. |
Function | stream |
Stream decodes an iterator. |
Function | super |
Undocumented |
Function | to |
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 |
Unquotes a header value. (Reversal of :func:`quote_header_value`). This does not use the real unquoting but what browsers are actually using for quoting. |
Function | unquote |
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 | DEFAULT |
Undocumented |
Constant | DEFAULT |
Undocumented |
Constant | DEFAULT |
Undocumented |
Constant | NETRC |
Undocumented |
Constant | UNRESERVED |
Undocumented |
Function | _parse |
Returns content type and parameters from given header |
Function | _validate |
Undocumented |
Variable | _null |
Undocumented |
Variable | _null2 |
Undocumented |
Variable | _null3 |
Undocumented |
Returns a CookieJar from a key/value dictionary. :param cj: CookieJar to insert cookies into. :param cookie_dict: Dict of key/values to insert into CookieJar. :rtype: CookieJar
This function allows you to check if an IP belongs to a network subnet Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24 returns False if ip = 192.168.1.1 and net = 192.168.100.0/24 :rtype: bool
Verifies that header parts don't contain leading whitespace reserved characters, or return characters. :param header: tuple, in the format (name, value).
Returns a key/value dictionary from a CookieJar. :param cj: CookieJar object to extract cookies from. :rtype: dict
Converts mask from /xx format to xxx.xxx.xxx.xxx Example: if mask is 24 function returns 255.255.255.0 :rtype: str
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.
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')]) :rtype: OrderedDict
Given a url with authentication components, extract them into a tuple of username,password. :rtype: (str,str)
Returns encodings from given HTTP Header Dict. :param headers: dictionary to extract encoding from. :rtype: str
Returns the requested content back in unicode. :param r: Response object to get unicode content from. Tried: 1. charset from content-type 2. fall back and replace all unicode characters :rtype: str
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 :class:`dict` again, use the :func:`dump_header` function. :param value: a string with a dict header. :return: :class:`dict` :rtype: 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" :rtype: list
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 :func:`parse_set_header` just that items may appear multiple times and case sensitivity is preserved. The return value is a standard :class:`list`: >>> parse_list_header('token, "quoted value"') ['token', 'quoted value'] To create a header from the :class:`list` again, use the :func:`dump_header` function. :param value: a string with a list header. :return: :class:`list` :rtype: list
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. :rtype: str
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. :rtype: str
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. :param request: Request or PreparedRequest :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs :param trust_env: Boolean declaring whether to trust environment configs :rtype: dict
Select a proxy for the url, if applicable. :param url: The url being for the request :param 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
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 :rtype: list
Unquotes a header value. (Reversal of :func:`quote_header_value`). This does not use the real unquoting but what browsers are actually using for quoting. :param value: the header value to unquote. :rtype: str
Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded. :rtype: str
Undocumented
Value |
|