Skip to content

Commit

Permalink
release to v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiqul Hasan committed May 22, 2018
1 parent 95bfb40 commit 904880b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

0.3.0 (2018-05-22)
------------------

* isurl function updated and removed support for irc url.

0.2.0 (2017-12-15)
------------------

Expand Down
18 changes: 18 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[packages]



[dev-packages]



[requires]

python_version = "3.6"
20 changes: 20 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name='validus',
version='0.2.0',
version='0.3.0',
description="A dead simple Python string validation library.",
long_description=readme + '\n\n' + history,
author="Rafiqul Hasan",
Expand Down
8 changes: 5 additions & 3 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,14 @@ def test_isurl(self):
self.assertTrue(validus.isurl('http://www.xn--froschgrn-x9a.net/'))
self.assertTrue(validus.isurl('http://foobar.中文网/'))
self.assertTrue(validus.isurl('http://localhost:3000/'))
self.assertTrue(validus.isurl('irc://#channel@network'))
self.assertTrue(validus.isurl('rtmp://foobar.com'))

self.assertFalse(validus.isurl('http://foobar.c_o_m'))
self.assertFalse(validus.isurl('abc'))
self.assertFalse(validus.isurl('abcd'))
self.assertFalse(validus.isurl('abcde'))
self.assertFalse(validus.isurl('abcdef'))
self.assertFalse(validus.isurl('xyz://foobar.com'))
self.assertFalse(validus.isurl('rtmp://foobar.com'))
self.assertFalse(validus.isurl('http://www.foo---bar.com/'))
self.assertFalse(validus.isurl('http://www.foo_bar.com/'))
self.assertFalse(validus.isurl('http://foo bar.org'))
self.assertFalse(validus.isurl('http://.foo.com'))
Expand Down
17 changes: 16 additions & 1 deletion validus/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,22 @@ def isurl(value):
:param value: string to validate URL
"""
url = re.compile(r'^((ftp|tcp|irc|udp|wss?|https?)://)?(\S+(:\S*)?@)?((([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(\[(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9]))\])|(([a-zA-Z0-9]([a-zA-Z0-9-_]+)?[a-zA-Z0-9]([-.][a-zA-Z0-9]+)*)|(((www\.)|([a-zA-Z0-9]([-.][-._a-zA-Z0-9]+)*))?))?(([a-zA-Z\u00a1-\uffff0-9]+-?-?)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.([a-zA-Z\u00a1-\uffff]+))?))\.?(:(\d{1,5}))?((/|\?|#)[^\s]*)?$')
# Regex patterns for validating URL is taken from
# Django's URLValidator class

ul = '\u00a1-\uffff'

# IP patterns
ipv4_re = r'(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}'
ipv6_re = r'\[[0-9a-f:\.]+\]'

# Host patterns
hostname_re = r'[a-z' + ul + r'0-9](?:[a-z' + ul + r'0-9-]{0,61}[a-z' + ul + r'0-9])?'
domain_re = r'(?:\.(?!-)[a-z' + ul + r'0-9-]{1,63}(?<!-))*'
tld_re = r'\.(?!-)(?:[a-z' + ul + '-]{2,63}|xn--[a-z0-9]{1,59})(?<!-)\.?' # may have a trailing dot
host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)'
url = re.compile(r'^(ftp|tcp|rtmp|udp|wss?|https?)://(?:\S+(?::\S*)?@)?(?:' + ipv4_re + '|' + ipv6_re + '|' + host_re + ')(?::\d{2,5})?(?:[/?#][^\s]*)?\Z', re.IGNORECASE)

if value == '' or len(value) >= 2083 or len(value) <= 3:
return False
return bool(url.match(value))
Expand Down

0 comments on commit 904880b

Please sign in to comment.