What do you think about this?
#utils.py
def is_http_url(s):
"""
Returns true if s is valid http url, else false
Arguments:
- `s`:
"""
if re.match('https?://(?:www)?(?:[\w-]{2,255}(?:\.\w{2,6}){1,2})(?:/[\w&%?#-]{1,300})?',s):
return True
else:
return False
#utils_test.py
import utils
class TestHttpUrlValidating(unittest.TestCase):
"""
"""
def test_validating(self):
"""
"""
self.assertEqual(utils.is_http_url('https://google.com'),True)
self.assertEqual(utils.is_http_url('http://www.google.com/r-o_ute?key=value'),True)
self.assertEqual(utils.is_http_url('aaaaaa'),False)
Is this enough? I'm going to insert URLs into database. Are there other ways to validate it?
rfc3987.match('http://http://codereview.stackexchange.com/', rule='URI')
\$\endgroup\$