Return ``True`` if the host is either an exact match or a match to the wildcard pattern. Any pattern beginning with a period matches a domain and all of its subdomains. (e.g. ``.example.com`` matches ``example.com`` and ``foo.example.com``). Anything else is an exact string mat
(host, pattern)
| 223 | |
| 224 | |
| 225 | def is_same_domain(host, pattern): |
| 226 | """ |
| 227 | Return ``True`` if the host is either an exact match or a match |
| 228 | to the wildcard pattern. |
| 229 | |
| 230 | Any pattern beginning with a period matches a domain and all of its |
| 231 | subdomains. (e.g. ``.example.com`` matches ``example.com`` and |
| 232 | ``foo.example.com``). Anything else is an exact string match. |
| 233 | """ |
| 234 | if not pattern: |
| 235 | return False |
| 236 | |
| 237 | pattern = pattern.lower() |
| 238 | return ( |
| 239 | pattern[0] == "." |
| 240 | and (host.endswith(pattern) or host == pattern[1:]) |
| 241 | or pattern == host |
| 242 | ) |
| 243 | |
| 244 | |
| 245 | def url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False): |
no outgoing calls