Minor changes to pass lint check

This commit is contained in:
fakezeta 2017-01-28 01:06:01 +01:00
parent db85e2bc2a
commit 549c3b2c84

View file

@ -46,47 +46,47 @@ def is_validurl(url):
"""Check if the passed url is valid using dperini regex.""" """Check if the passed url is valid using dperini regex."""
import re import re
ip_middle_oct = u"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))" ip_middle_oct = r"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
ip_last_oct = u"(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))" ip_last_oct = r"(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"
regex = re.compile( regex = re.compile(
u"^" r"^"
# protocol identifier # protocol identifier
u"(?:(?:https?|ftp)://)" r"(?:(?:https?|ftp)://)"
# user:pass authentication # user:pass authentication
u"(?:\S+(?::\S*)?@)?" r"(?:\S+(?::\S*)?@)?"
u"(?:" r"(?:"
u"(?P<private_ip>" r"(?P<private_ip>"
# IP address exclusion # IP address exclusion
# private & local networks # private & local networks
u"(?:(?:10|127)" + ip_middle_oct + u"{2}" + ip_last_oct + u")|" r"(?:(?:10|127)" + ip_middle_oct + u"{2}" + ip_last_oct + u")|"
u"(?:(?:169\.254|192\.168)" + ip_middle_oct + ip_last_oct + u")|" r"(?:(?:169\.254|192\.168)" + ip_middle_oct + ip_last_oct + u")|"
u"(?:172\.(?:1[6-9]|2\d|3[0-1])" + ip_middle_oct + ip_last_oct + u"))" r"(?:172\.(?:1[6-9]|2\d|3[0-1])" + ip_middle_oct + ip_last_oct + u"))"
u"|" r"|"
# IP address dotted notation octets # IP address dotted notation octets
# excludes loopback network 0.0.0.0 # excludes loopback network 0.0.0.0
# excludes reserved space >= 224.0.0.0 # excludes reserved space >= 224.0.0.0
# excludes network & broadcast addresses # excludes network & broadcast addresses
# (first & last IP address of each class) # (first & last IP address of each class)
u"(?P<public_ip>" r"(?P<public_ip>"
u"(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])" r"(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])"
u"" + ip_middle_oct + u"{2}" r"" + ip_middle_oct + u"{2}"
u"" + ip_last_oct + u")" r"" + ip_last_oct + u")"
u"|" r"|"
# host name # host name
u"(?:(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)" r"(?:(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)"
# domain name # domain name
u"(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*" r"(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*"
# TLD identifier # TLD identifier
u"(?:\.(?:[a-z\u00a1-\uffff]{2,}))" r"(?:\.(?:[a-z\u00a1-\uffff]{2,}))"
u")" r")"
# port number # port number
u"(?::\d{2,5})?" r"(?::\d{2,5})?"
# resource path # resource path
u"(?:/\S*)?" r"(?:/\S*)?"
# query string # query string
u"(?:\?\S*)?" r"(?:\?\S*)?"
u"$", r"$",
re.UNICODE | re.IGNORECASE re.UNICODE | re.IGNORECASE
) )