MCPcopy Index your code
hub / github.com/python/cpython / make_cookies

Method make_cookies

Lib/http/cookiejar.py:1600–1653  ·  view source on GitHub ↗

Return sequence of Cookie objects extracted from response object.

(self, response, request)

Source from the content-addressed store, hash-verified

1598 cookie.version = 0
1599
1600 def make_cookies(self, response, request):
1601 """Return sequence of Cookie objects extracted from response object."""
1602 # get cookie-attributes for RFC 2965 and Netscape protocols
1603 headers = response.info()
1604 rfc2965_hdrs = headers.get_all("Set-Cookie2", [])
1605 ns_hdrs = headers.get_all("Set-Cookie", [])
1606 self._policy._now = self._now = int(time.time())
1607
1608 rfc2965 = self._policy.rfc2965
1609 netscape = self._policy.netscape
1610
1611 if ((not rfc2965_hdrs and not ns_hdrs) or
1612 (not ns_hdrs and not rfc2965) or
1613 (not rfc2965_hdrs and not netscape) or
1614 (not netscape and not rfc2965)):
1615 return [] # no relevant cookie headers: quick exit
1616
1617 try:
1618 cookies = self._cookies_from_attrs_set(
1619 split_header_words(rfc2965_hdrs), request)
1620 except Exception:
1621 _warn_unhandled_exception()
1622 cookies = []
1623
1624 if ns_hdrs and netscape:
1625 try:
1626 # RFC 2109 and Netscape cookies
1627 ns_cookies = self._cookies_from_attrs_set(
1628 parse_ns_headers(ns_hdrs), request)
1629 except Exception:
1630 _warn_unhandled_exception()
1631 ns_cookies = []
1632 self._process_rfc2109_cookies(ns_cookies)
1633
1634 # Look for Netscape cookies (from Set-Cookie headers) that match
1635 # corresponding RFC 2965 cookies (from Set-Cookie2 headers).
1636 # For each match, keep the RFC 2965 cookie and ignore the Netscape
1637 # cookie (RFC 2965 section 9.1). Actually, RFC 2109 cookies are
1638 # bundled in with the Netscape cookies for this purpose, which is
1639 # reasonable behaviour.
1640 if rfc2965:
1641 lookup = {}
1642 for cookie in cookies:
1643 lookup[(cookie.domain, cookie.path, cookie.name)] = None
1644
1645 def no_matching_rfc2965(ns_cookie, lookup=lookup):
1646 key = ns_cookie.domain, ns_cookie.path, ns_cookie.name
1647 return key not in lookup
1648 ns_cookies = filter(no_matching_rfc2965, ns_cookies)
1649
1650 if ns_cookies:
1651 cookies.extend(ns_cookies)
1652
1653 return cookies
1654
1655 def set_cookie_if_ok(self, cookie, request):
1656 """Set a cookie if policy says it's OK to do so."""

Callers 4

extract_cookiesMethod · 0.95
test_expiresMethod · 0.95
test_domain_allowMethod · 0.95
test_domain_blockMethod · 0.95

Calls 10

split_header_wordsFunction · 0.85
parse_ns_headersFunction · 0.85
filterFunction · 0.50
infoMethod · 0.45
get_allMethod · 0.45
timeMethod · 0.45
extendMethod · 0.45

Tested by 3

test_expiresMethod · 0.76
test_domain_allowMethod · 0.76
test_domain_blockMethod · 0.76