Home / File/ cookies.py — requests Source File

cookies.py — requests Source File

Architecture documentation for cookies.py, a python file in the requests codebase. 8 imports, 5 dependents.

File python CoreAPI VerbHandlers 8 imports 5 dependents 10 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8["cookies.py"]
  ad9103ba_2c26_1ff0_c67d_e7f70c6f108c["_internal_utils.py"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8 --> ad9103ba_2c26_1ff0_c67d_e7f70c6f108c
  0ab29509_59a1_1f68_fae2_146376240019["to_native_string"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8 --> 0ab29509_59a1_1f68_fae2_146376240019
  655589d9_9504_8132_6277_d047dcd65486["compat.py"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8 --> 655589d9_9504_8132_6277_d047dcd65486
  c03ebeba_c489_0fbe_b92d_230f33c32fc2["calendar"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8 --> c03ebeba_c489_0fbe_b92d_230f33c32fc2
  88441990_55c5_ac59_3cfd_8b5cacc0cb3c["copy"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8 --> 88441990_55c5_ac59_3cfd_8b5cacc0cb3c
  17309818_1833_a3e0_d6fe_f97cb9ad6ed1["time"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8 --> 17309818_1833_a3e0_d6fe_f97cb9ad6ed1
  d04f5b22_a751_5438_e937_aa8b0666d15e["threading"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8 --> d04f5b22_a751_5438_e937_aa8b0666d15e
  1baa2a27_ba7d_1325_c412_51c760ecd121["dummy_threading"]
  270696ff_2a4f_ef5b_92e8_33a79e68a2d8 --> 1baa2a27_ba7d_1325_c412_51c760ecd121
  8cafec3a_816a_3b74_357a_0167321e5d19["adapters.py"]
  8cafec3a_816a_3b74_357a_0167321e5d19 --> 270696ff_2a4f_ef5b_92e8_33a79e68a2d8
  d7a739b0_e73b_9565_f5ed_5e8c24943504["auth.py"]
  d7a739b0_e73b_9565_f5ed_5e8c24943504 --> 270696ff_2a4f_ef5b_92e8_33a79e68a2d8
  461bc6e0_32e7_8eab_ec87_7226e7be0d13["models.py"]
  461bc6e0_32e7_8eab_ec87_7226e7be0d13 --> 270696ff_2a4f_ef5b_92e8_33a79e68a2d8
  ea1101aa_233b_1206_7b38_a38f0fe92a52["sessions.py"]
  ea1101aa_233b_1206_7b38_a38f0fe92a52 --> 270696ff_2a4f_ef5b_92e8_33a79e68a2d8
  2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"]
  2c39b9da_e317_5e6c_bbac_8362bac2110c --> 270696ff_2a4f_ef5b_92e8_33a79e68a2d8
  style 270696ff_2a4f_ef5b_92e8_33a79e68a2d8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""
requests.cookies
~~~~~~~~~~~~~~~~

Compatibility code to be able to use `http.cookiejar.CookieJar` with requests.

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

import calendar
import copy
import time

from ._internal_utils import to_native_string
from .compat import Morsel, MutableMapping, cookielib, urlparse, urlunparse

try:
    import threading
except ImportError:
    import dummy_threading as threading


class MockRequest:
    """Wraps a `requests.Request` to mimic a `urllib2.Request`.

    The code in `http.cookiejar.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.
    """

    def __init__(self, request):
        self._r = request
        self._new_headers = {}
        self.type = urlparse(self._r.url).scheme

    def get_type(self):
        return self.type

    def get_host(self):
        return urlparse(self._r.url).netloc

    def get_origin_req_host(self):
        return self.get_host()

    def get_full_url(self):
        # Only return the response's URL if the user hadn't set the Host
        # header
        if not self._r.headers.get("Host"):
            return self._r.url
        # If they did set it, retrieve it and reconstruct the expected domain
        host = to_native_string(self._r.headers["Host"], encoding="utf-8")
        parsed = urlparse(self._r.url)
        # Reconstruct the URL as we expect it
        return urlunparse(
            [
                parsed.scheme,
// ... (502 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does cookies.py do?
cookies.py is a source file in the requests codebase, written in python. It belongs to the CoreAPI domain, VerbHandlers subdomain.
What functions are defined in cookies.py?
cookies.py defines 10 function(s): _copy_cookie_jar, cookiejar_from_dict, create_cookie, dummy_threading, extract_cookies_to_jar, get_cookie_header, merge_cookies, morsel_to_cookie, remove_cookie_by_name, threading.
What does cookies.py depend on?
cookies.py imports 8 module(s): _internal_utils.py, calendar, compat.py, copy, dummy_threading, threading, time, to_native_string.
What files import cookies.py?
cookies.py is imported by 5 file(s): adapters.py, auth.py, models.py, sessions.py, utils.py.
Where is cookies.py in the architecture?
cookies.py is located at src/requests/cookies.py (domain: CoreAPI, subdomain: VerbHandlers, directory: src/requests).

Analyze Your Own Codebase

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

Try Supermodel Free