Implements the standard rules for accepting and returning cookies.
| 873 | |
| 874 | |
| 875 | class DefaultCookiePolicy(CookiePolicy): |
| 876 | """Implements the standard rules for accepting and returning cookies.""" |
| 877 | |
| 878 | DomainStrictNoDots = 1 |
| 879 | DomainStrictNonDomain = 2 |
| 880 | DomainRFC2965Match = 4 |
| 881 | |
| 882 | DomainLiberal = 0 |
| 883 | DomainStrict = DomainStrictNoDots|DomainStrictNonDomain |
| 884 | |
| 885 | def __init__(self, |
| 886 | blocked_domains=None, allowed_domains=None, |
| 887 | netscape=True, rfc2965=False, |
| 888 | rfc2109_as_netscape=None, |
| 889 | hide_cookie2=False, |
| 890 | strict_domain=False, |
| 891 | strict_rfc2965_unverifiable=True, |
| 892 | strict_ns_unverifiable=False, |
| 893 | strict_ns_domain=DomainLiberal, |
| 894 | strict_ns_set_initial_dollar=False, |
| 895 | strict_ns_set_path=False, |
| 896 | secure_protocols=("https", "wss") |
| 897 | ): |
| 898 | """Constructor arguments should be passed as keyword arguments only.""" |
| 899 | self.netscape = netscape |
| 900 | self.rfc2965 = rfc2965 |
| 901 | self.rfc2109_as_netscape = rfc2109_as_netscape |
| 902 | self.hide_cookie2 = hide_cookie2 |
| 903 | self.strict_domain = strict_domain |
| 904 | self.strict_rfc2965_unverifiable = strict_rfc2965_unverifiable |
| 905 | self.strict_ns_unverifiable = strict_ns_unverifiable |
| 906 | self.strict_ns_domain = strict_ns_domain |
| 907 | self.strict_ns_set_initial_dollar = strict_ns_set_initial_dollar |
| 908 | self.strict_ns_set_path = strict_ns_set_path |
| 909 | self.secure_protocols = secure_protocols |
| 910 | |
| 911 | if blocked_domains is not None: |
| 912 | self._blocked_domains = tuple(blocked_domains) |
| 913 | else: |
| 914 | self._blocked_domains = () |
| 915 | |
| 916 | if allowed_domains is not None: |
| 917 | allowed_domains = tuple(allowed_domains) |
| 918 | self._allowed_domains = allowed_domains |
| 919 | |
| 920 | def blocked_domains(self): |
| 921 | """Return the sequence of blocked domains (as a tuple).""" |
| 922 | return self._blocked_domains |
| 923 | def set_blocked_domains(self, blocked_domains): |
| 924 | """Set the sequence of blocked domains.""" |
| 925 | self._blocked_domains = tuple(blocked_domains) |
| 926 | |
| 927 | def is_blocked(self, domain): |
| 928 | for blocked_domain in self._blocked_domains: |
| 929 | if user_domain_match(domain, blocked_domain): |
| 930 | return True |
| 931 | return False |
| 932 |
no outgoing calls
searching dependent graphs…