X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/d8c7acf5c1153bb75c51b632ee6bf2d913448a3a..7515976d9cc927f6f72a191442c5788856f610fd:/validators.py?ds=inline diff --git a/validators.py b/validators.py index 68ba293..1e73c0b 100644 --- a/validators.py +++ b/validators.py @@ -1,6 +1,6 @@ from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ -from django.core.validators import URLValidator +from django.core.validators import RegexValidator import re @@ -80,23 +80,28 @@ class TreePositionValidator(object): message = property(get_message) -class URLRedirectValidator(URLValidator): +class RedirectValidator(RegexValidator): + """Based loosely on the URLValidator, but no option to verify_exists""" regex = re.compile( - r'^(?:https?://' # http:// or https:// - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' #domain... - r'localhost|' #localhost... - r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip - r'(?::\d+)?' # optional port - r'|)' # also allow internal redirects - r'(?:/?|[/?]?\S+)$', re.IGNORECASE) + r'^(?:https?://' # http:// or https:// + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' #domain... + r'localhost|' #localhost... + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip + r'(?::\d+)?' # optional port + r'(?:/?|[/?#]?\S+)|' + r'[^?#\s]\S*)$', + re.IGNORECASE) + message = _(u'Enter a valid absolute or relative redirect target') -class URLLinkValidator(URLValidator): +class URLLinkValidator(RegexValidator): + """Based loosely on the URLValidator, but no option to verify_exists""" regex = re.compile( - r'^(?:https?://' # http:// or https:// - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' #domain... - r'localhost|' #localhost... - r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip - r'(?::\d+)?' # optional port - r'|)' # also allow internal links - r'(?:/?|[/?#]?\S+)$', re.IGNORECASE) + r'^(?:https?://' # http:// or https:// + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' #domain... + r'localhost|' #localhost... + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip + r'(?::\d+)?' # optional port + r'|)' # also allow internal links + r'(?:/?|[/?#]?\S+)$', re.IGNORECASE) + message = _(u'Enter a valid absolute or relative redirect target')