Skip to content

Commit e19499e

Browse files
committed
Added decorator to requirements
1 parent d481440 commit e19499e

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run(self):
3636

3737
setup(
3838
name='validators',
39-
version='0.1.0',
39+
version='0.2.0',
4040
url='https://github.com/kvesteri/validators',
4141
license='BSD',
4242
author='Konsta Vesterinen',
@@ -47,7 +47,10 @@ def run(self):
4747
zip_safe=False,
4848
include_package_data=True,
4949
platforms='any',
50-
install_requires=['six>=1.4.0'],
50+
install_requires=[
51+
'six>=1.4.0',
52+
'decorator>=3.4.0'
53+
],
5154
extras_require=extras_require,
5255
cmdclass={'test': PyTest},
5356
classifiers=[

validators/ip_address.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def ipv4(value):
1313
1414
1515
Examples::
16+
17+
1618
>>> import validators
1719
1820
>>> validators.ipv4('123.0.0.7')
@@ -43,6 +45,8 @@ def ipv6(value):
4345
4446
4547
Examples::
48+
49+
4650
>>> import validators
4751
4852
>>> validators.ipv6('abcd:ef::42:1')

validators/url.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
@validator
1515
def url(value, require_tld=True):
1616
"""
17+
url
18+
---
19+
1720
Returns whether or not given value is a valid URL. If the value is
1821
valid URL this function returns True, otherwise `FailedValidation`.
1922

validators/utils.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from collections import OrderedDict
33
except ImportError:
44
from ordereddict import OrderedDict
5+
from decorator import decorator
56
import inspect
67
import itertools
78
import six
8-
from functools import wraps
99

1010

1111
class FailedValidation(object):
@@ -35,13 +35,11 @@ def func_args_as_dict(func, args, kwargs):
3535
)
3636

3737

38-
def validator(func):
39-
@wraps(func)
40-
def wrapper(*args, **kwargs):
41-
value = func(*args, **kwargs)
42-
if not value:
43-
return FailedValidation(
44-
func, func_args_as_dict(func, args, kwargs)
45-
)
46-
return value
47-
return wrapper
38+
@decorator
39+
def validator(func, *args, **kwargs):
40+
value = func(*args, **kwargs)
41+
if not value:
42+
return FailedValidation(
43+
func, func_args_as_dict(func, args, kwargs)
44+
)
45+
return value

0 commit comments

Comments
 (0)