| |
@@ -16,8 +16,17 @@
|
| |
import kitchen.text.converters
|
| |
import requests
|
| |
import six
|
| |
-
|
| |
-
|
| |
+ import re
|
| |
+
|
| |
+ #compiling regex for url validation
|
| |
+ url = re.compile(
|
| |
+ r'^(?:http|ftp)s?://|\bwww.\b'
|
| |
+ r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
|
| |
+ r'localhost|'
|
| |
+ r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
|
| |
+ r'(?::\d+)?'
|
| |
+ r'(?:/?|[/?]\S+)$',re.I)
|
| |
+
|
| |
def Required(value):
|
| |
"""Raises an error if the value is ``False``-like."""
|
| |
if not bool(value):
|
| |
@@ -40,8 +49,10 @@
|
| |
|
| |
def Link(value):
|
| |
"""Raises an error if the value doesn't look like a link."""
|
| |
- # TODO -- verify that this is actually a link
|
| |
- return value
|
| |
+ if url.search(value):
|
| |
+ return value
|
| |
+ else:
|
| |
+ raise ValueError('Invalid Url')
|
| |
|
| |
|
| |
def Username(value):
|
| |
LInk validation of url includes https, http,localhost and ip address using regex library of python