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

Method set_ok_domain

Lib/http/cookiejar.py:1016–1074  ·  view source on GitHub ↗
(self, cookie, request)

Source from the content-addressed store, hash-verified

1014 return True
1015
1016 def set_ok_domain(self, cookie, request):
1017 if self.is_blocked(cookie.domain):
1018 _debug(" domain %s is in user block-list", cookie.domain)
1019 return False
1020 if self.is_not_allowed(cookie.domain):
1021 _debug(" domain %s is not in user allow-list", cookie.domain)
1022 return False
1023 if cookie.domain_specified:
1024 req_host, erhn = eff_request_host(request)
1025 domain = cookie.domain
1026 if self.strict_domain and (domain.count(".") >= 2):
1027 # XXX This should probably be compared with the Konqueror
1028 # (kcookiejar.cpp) and Mozilla implementations, but it's a
1029 # losing battle.
1030 i = domain.rfind(".")
1031 j = domain.rfind(".", 0, i)
1032 if j == 0: # domain like .foo.bar
1033 tld = domain[i+1:]
1034 sld = domain[j+1:i]
1035 if sld.lower() in ("co", "ac", "com", "edu", "org", "net",
1036 "gov", "mil", "int", "aero", "biz", "cat", "coop",
1037 "info", "jobs", "mobi", "museum", "name", "pro",
1038 "travel", "eu") and len(tld) == 2:
1039 # domain like .co.uk
1040 _debug(" country-code second level domain %s", domain)
1041 return False
1042 if domain.startswith("."):
1043 undotted_domain = domain[1:]
1044 else:
1045 undotted_domain = domain
1046 embedded_dots = (undotted_domain.find(".") >= 0)
1047 if not embedded_dots and not erhn.endswith(".local"):
1048 _debug(" non-local domain %s contains no embedded dot",
1049 domain)
1050 return False
1051 if cookie.version == 0:
1052 if (not (erhn.endswith(domain) or
1053 erhn.endswith(f"{undotted_domain}.local")) and
1054 (not erhn.startswith(".") and
1055 not ("."+erhn).endswith(domain))):
1056 _debug(" effective request-host %s (even with added "
1057 "initial dot) does not end with %s",
1058 erhn, domain)
1059 return False
1060 if (cookie.version > 0 or
1061 (self.strict_ns_domain & self.DomainRFC2965Match)):
1062 if not domain_match(erhn, domain):
1063 _debug(" effective request-host %s does not domain-match "
1064 "%s", erhn, domain)
1065 return False
1066 if (cookie.version > 0 or
1067 (self.strict_ns_domain & self.DomainStrictNoDots)):
1068 host_prefix = req_host[:-len(domain)]
1069 if (host_prefix.find(".") >= 0 and
1070 not IPV4_RE.search(req_host)):
1071 _debug(" host prefix %s for domain %s contains a dot",
1072 host_prefix, domain)
1073 return False

Callers

nothing calls this directly

Calls 12

is_blockedMethod · 0.95
is_not_allowedMethod · 0.95
_debugFunction · 0.85
eff_request_hostFunction · 0.85
domain_matchFunction · 0.85
countMethod · 0.45
rfindMethod · 0.45
lowerMethod · 0.45
startswithMethod · 0.45
findMethod · 0.45
endswithMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected