Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/bleach/_vendor/django/core/validators.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 from __future__ import unicode_literals | |
2 | |
3 import re | |
4 | |
5 | |
6 class URLValidator(object): | |
7 ul = "\u00a1-\uffff" # unicode letters range (must be a unicode string, not a raw string) | |
8 | |
9 # IP patterns | |
10 ipv4_re = ( | |
11 r"(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}" | |
12 ) | |
13 ipv6_re = r"\[[0-9a-f:\.]+\]" # (simple regex, validated later) | |
14 | |
15 # Host patterns | |
16 hostname_re = ( | |
17 r"[a-z" + ul + r"0-9](?:[a-z" + ul + r"0-9-]{0,61}[a-z" + ul + r"0-9])?" | |
18 ) | |
19 # Max length for domain name labels is 63 characters per RFC 1034 sec. 3.1 | |
20 domain_re = r"(?:\.(?!-)[a-z" + ul + r"0-9-]{1,63}(?<!-))*" | |
21 tld_re = ( | |
22 r"\." # dot | |
23 r"(?!-)" # can't start with a dash | |
24 r"(?:[a-z" + ul + "-]{2,63}" # domain label | |
25 r"|xn--[a-z0-9]{1,59})" # or punycode label | |
26 r"(?<!-)" # can't end with a dash | |
27 r"\.?" # may have a trailing dot | |
28 ) | |
29 host_re = "(" + hostname_re + domain_re + tld_re + "|localhost)" | |
30 | |
31 netloc_re = r"(?:" + ipv4_re + "|" + ipv6_re + "|" + host_re + ")" | |
32 port_re = r"(?::\d{2,5})?" # port | |
33 | |
34 regex = re.compile( | |
35 r"^(?:[a-z0-9\.\-\+]*)://" # scheme is validated separately | |
36 r"(?:\S+(?::\S*)?@)?" # user:pass authentication | |
37 + netloc_re | |
38 + port_re | |
39 + r"(?:[/?#][^\s]*)?" # resource path | |
40 r"\Z", | |
41 re.IGNORECASE, | |
42 ) |