Home / Class/ RequestsCookieJar Class — requests Architecture

RequestsCookieJar Class — requests Architecture

Architecture documentation for the RequestsCookieJar class in cookies.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  12ccbc5f_4c31_987c_5272_7babba58a1f2["RequestsCookieJar"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8["cookies.py"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|defined in| 270696ff_2a4f_ef5b_92e8_33a79e68a2d8
  b59a42f3_d82f_81a3_c550_b1cea1222004["get()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| b59a42f3_d82f_81a3_c550_b1cea1222004
  fd64c32d_aaa4_5925_c2a7_12f040eb3704["set()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| fd64c32d_aaa4_5925_c2a7_12f040eb3704
  a470e91b_5958_b35b_2e20_0d43c6814aa6["iterkeys()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| a470e91b_5958_b35b_2e20_0d43c6814aa6
  01742ffe_de19_b964_826d_4aae4a4bcfba["keys()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| 01742ffe_de19_b964_826d_4aae4a4bcfba
  a65d7763_96eb_0eb8_7a26_4452b77dab63["itervalues()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| a65d7763_96eb_0eb8_7a26_4452b77dab63
  d8cf25df_d375_8a5a_948e_c64ed910db1c["values()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| d8cf25df_d375_8a5a_948e_c64ed910db1c
  bc544dcb_d89c_998d_c29e_a9005c4a0243["iteritems()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| bc544dcb_d89c_998d_c29e_a9005c4a0243
  342c3122_113c_32a4_2286_94935f7ac0a8["items()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| 342c3122_113c_32a4_2286_94935f7ac0a8
  bb50026d_d1f1_ba5c_1747_2b6f93537724["list_domains()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| bb50026d_d1f1_ba5c_1747_2b6f93537724
  901cc40b_2175_1e4f_0c99_13d7e13784f7["list_paths()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| 901cc40b_2175_1e4f_0c99_13d7e13784f7
  ec393c7b_5fd4_aecc_f97a_373df6c426c4["multiple_domains()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| ec393c7b_5fd4_aecc_f97a_373df6c426c4
  4e263186_5975_87b1_e8e4_1e296957469f["get_dict()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| 4e263186_5975_87b1_e8e4_1e296957469f
  33f4f55a_344c_be2b_20b5_2ad7aa936617["__contains__()"]
  12ccbc5f_4c31_987c_5272_7babba58a1f2 -->|method| 33f4f55a_344c_be2b_20b5_2ad7aa936617

Relationship Graph

Source Code

src/requests/cookies.py lines 176–437

class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
    """Compatibility class; is a http.cookiejar.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).
    """

    def get(self, 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.

        .. warning:: operation is O(n), not O(1).
        """
        try:
            return self._find_no_duplicates(name, domain, path)
        except KeyError:
            return default

    def set(self, 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.
        """
        # support client code that unsets cookies by assignment of a None value:
        if value is None:
            remove_cookie_by_name(
                self, name, domain=kwargs.get("domain"), path=kwargs.get("path")
            )
            return

        if isinstance(value, Morsel):
            c = morsel_to_cookie(value)
        else:
            c = create_cookie(name, value, **kwargs)
        self.set_cookie(c)
        return c

    def iterkeys(self):
        """Dict-like iterkeys() that returns an iterator of names of cookies
        from the jar.

        .. seealso:: itervalues() and iteritems().
        """
        for cookie in iter(self):
            yield cookie.name

    def keys(self):
        """Dict-like keys() that returns a list of names of cookies from the
        jar.

        .. seealso:: values() and items().
        """
        return list(self.iterkeys())

    def itervalues(self):
        """Dict-like itervalues() that returns an iterator of values of cookies
        from the jar.

        .. seealso:: iterkeys() and iteritems().
        """
        for cookie in iter(self):
            yield cookie.value

    def values(self):
        """Dict-like values() that returns a list of values of cookies from the
        jar.

        .. seealso:: keys() and items().
        """

Domain

Frequently Asked Questions

What is the RequestsCookieJar class?
RequestsCookieJar is a class in the requests codebase, defined in src/requests/cookies.py.
Where is RequestsCookieJar defined?
RequestsCookieJar is defined in src/requests/cookies.py at line 176.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free