class documentation

class RequestsCookieJar(cookielib.CookieJar, MutableMapping): (source)

View In Hierarchy

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. Requests does not use the dict interface internally; it's just for compatibility with external client code. All requests code should work out of the box with externally provided instances of ``CookieJar``, e.g. ``LWPCookieJar`` and ``FileCookieJar``. Unlike a regular CookieJar, this class is pickleable. .. warning:: dictionary operations that are normally O(1) may be O(n).

Method __contains__ Undocumented
Method __delitem__ Deletes a cookie given a name. Wraps ``cookielib.CookieJar``'s ``remove_cookie_by_name()``.
Method __getitem__ Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead.
Method __getstate__ Unlike a normal CookieJar, this class is pickleable.
Method __setitem__ Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead.
Method __setstate__ Unlike a normal CookieJar, this class is pickleable.
Method copy Return a copy of this RequestsCookieJar.
Method get 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.
Method get_dict 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.
Method get_policy Return the CookiePolicy instance used.
Method items Dict-like items() that returns a list of name-value tuples from the jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a vanilla python dict of key value pairs.
Method iteritems Dict-like iteritems() that returns an iterator of name-value tuples from the jar.
Method iterkeys Dict-like iterkeys() that returns an iterator of names of cookies from the jar.
Method itervalues Dict-like itervalues() that returns an iterator of values of cookies from the jar.
Method keys Dict-like keys() that returns a list of names of cookies from the jar.
Method list_domains Utility method to list all the domains in the jar.
Method list_paths Utility method to list all the paths in the jar.
Method multiple_domains Returns True if there are multiple domains in the jar. Returns False otherwise.
Method set 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.
Method set_cookie Undocumented
Method update Updates this jar with cookies from another CookieJar or dict-like
Method values Dict-like values() that returns a list of values of cookies from the jar.
Method _find Requests uses this method internally to get cookie values.
Method _find_no_duplicates Both ``__get_item__`` and ``get`` call this function: it's never used elsewhere in Requests.
Instance Variable _cookies_lock Undocumented
def __contains__(self, name): (source)

Undocumented

def __delitem__(self, name): (source)

Deletes a cookie given a name. Wraps ``cookielib.CookieJar``'s ``remove_cookie_by_name()``.

def __getitem__(self, name): (source)

Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. .. warning:: operation is O(n), not O(1).

def __getstate__(self): (source)

Unlike a normal CookieJar, this class is pickleable.

def __setitem__(self, name, value): (source)

Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead.

def __setstate__(self, state): (source)

Unlike a normal CookieJar, this class is pickleable.

def copy(self): (source)

Return a copy of this RequestsCookieJar.

def get(self, name, default=None, domain=None, path=None): (source)

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. .. warning:: operation is O(n), not O(1).

def get_dict(self, domain=None, path=None): (source)

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. :rtype: dict

def get_policy(self): (source)

Return the CookiePolicy instance used.

def items(self): (source)

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

def iteritems(self): (source)

Dict-like iteritems() that returns an iterator of name-value tuples from the jar. .. seealso:: iterkeys() and itervalues().

def iterkeys(self): (source)

Dict-like iterkeys() that returns an iterator of names of cookies from the jar. .. seealso:: itervalues() and iteritems().

def itervalues(self): (source)

Dict-like itervalues() that returns an iterator of values of cookies from the jar. .. seealso:: iterkeys() and iteritems().

def keys(self): (source)

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

def list_domains(self): (source)

Utility method to list all the domains in the jar.

def list_paths(self): (source)

Utility method to list all the paths in the jar.

def multiple_domains(self): (source)

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

def set(self, name, value, **kwargs): (source)

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.

def set_cookie(self, cookie, *args, **kwargs): (source)

Undocumented

def update(self, other): (source)

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

def values(self): (source)

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

def _find(self, name, domain=None, path=None): (source)

Requests uses this method internally to get cookie values. If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :return: cookie.value

def _find_no_duplicates(self, name, domain=None, path=None): (source)

Both ``__get_item__`` and ``get`` call this function: it's never used elsewhere in Requests. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :raises KeyError: if cookie is not found :raises CookieConflictError: if there are multiple cookies that match name and optionally domain and path :return: cookie.value

_cookies_lock = (source)

Undocumented