1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-08 22:07:55 +00:00

web/lib/validation.py: add validate_i2purl()

We need it for URL validation when adding external hosts sources.
This commit is contained in:
Hidden Z 2010-10-31 12:24:28 +00:00
parent 9f3773cebf
commit d9eb21932e

View File

@ -109,3 +109,12 @@ def validate_b64hash(data, check_uniq=True):
if qs.exists():
raise ValidationError('Base64 hash must be unique')
return data
def validate_i2purl(data):
""" Basic I2P URL validator """
# convert to lowercase and strip leading and trailing whitespaces
data = data.lower().strip()
# check for http://, .i2p in domain and GET validity
if re.match(r'^http://(?:.+?\.i2p)(?:/?|[/?]\S+)$', data) == None:
raise ValidationError('Bad I2P url')