Skip to content

Commit 453b92e

Browse files
authored
Update cookiejar.py
1 parent b102f09 commit 453b92e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Lib/http/cookiejar.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,8 @@ def __init__(self,
893893
strict_ns_domain=DomainLiberal,
894894
strict_ns_set_initial_dollar=False,
895895
strict_ns_set_path=False,
896-
secure_protocols=("https", "wss")
896+
secure_protocols=("https", "wss"),
897+
additional_country_code_slds=None,
897898
):
898899
"""Constructor arguments should be passed as keyword arguments only."""
899900
self.netscape = netscape
@@ -907,6 +908,14 @@ def __init__(self,
907908
self.strict_ns_set_initial_dollar = strict_ns_set_initial_dollar
908909
self.strict_ns_set_path = strict_ns_set_path
909910
self.secure_protocols = secure_protocols
911+
912+
# source: https://en.wikipedia.org/wiki/Second-level_domain
913+
well_known_slds = {"co", "ac", "com", "edu", "org", "net",
914+
"gov", "mil", "int", "aero", "biz", "cat", "coop",
915+
"info", "jobs", "mobi", "museum", "name", "pro",
916+
"travel", "eu", "tv", "or", "nom", "sch", "web"}
917+
if isinstance(additional_country_code_slds, set):
918+
self.slds = well_known_slds.union(additional_country_code_slds)
910919

911920
if blocked_domains is not None:
912921
self._blocked_domains = tuple(blocked_domains)
@@ -1032,10 +1041,7 @@ def set_ok_domain(self, cookie, request):
10321041
if j == 0: # domain like .foo.bar
10331042
tld = domain[i+1:]
10341043
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:
1044+
if sld.lower() in self.slds and len(tld) == 2:
10391045
# domain like .co.uk
10401046
_debug(" country-code second level domain %s", domain)
10411047
return False

0 commit comments

Comments
 (0)