Skip to content

Commit a5071c6

Browse files
authored
Merge pull request #232 from joe733/workshop
maint: minor improvements
2 parents 8f596c3 + 35e0edd commit a5071c6

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

validators/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Validate Anything!"""
22
# -*- coding: utf-8 -*-
3-
# from ._extremes import AbsMax, AbsMin
43

54
from .between import between
65
from .btc_address import btc_address
@@ -39,9 +38,7 @@
3938
"length",
4039
"mac_address",
4140
"mastercard",
42-
# "AbsMax",
4341
"md5",
44-
# "AbsMax",
4542
"sha1",
4643
"sha224",
4744
"sha256",

validators/btc_address.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
# local
99
from .utils import validator
1010

11-
_segwit_pattern = re.compile(r"^(bc|tc)[0-3][02-9ac-hj-np-z]{14,74}$")
12-
1311

1412
def _decode_base58(addr: str):
1513
"""Decode base58."""
@@ -54,7 +52,8 @@ def btc_address(value: str, /):
5452
"""
5553
if value and type(value) is str:
5654
return (
57-
_segwit_pattern.match(value)
55+
# segwit pattern
56+
re.compile(r"^(bc|tc)[0-3][02-9ac-hj-np-z]{14,74}$").match(value)
5857
if value[:2] in ("bc", "tb")
5958
else _validate_old_btc_address(value)
6059
)

validators/card.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@validator
12-
def card_number(value: str):
12+
def card_number(value: str, /):
1313
"""Return whether or not given value is a valid generic card number.
1414
1515
This validator is based on [Luhn's algorithm][1].
@@ -44,7 +44,7 @@ def card_number(value: str):
4444

4545

4646
@validator
47-
def visa(value: str):
47+
def visa(value: str, /):
4848
"""Return whether or not given value is a valid Visa card number.
4949
5050
Examples:
@@ -70,7 +70,7 @@ def visa(value: str):
7070

7171

7272
@validator
73-
def mastercard(value: str):
73+
def mastercard(value: str, /):
7474
"""Return whether or not given value is a valid Mastercard card number.
7575
7676
Examples:
@@ -96,7 +96,7 @@ def mastercard(value: str):
9696

9797

9898
@validator
99-
def amex(value: str):
99+
def amex(value: str, /):
100100
"""Return whether or not given value is a valid American Express card number.
101101
102102
Examples:
@@ -122,7 +122,7 @@ def amex(value: str):
122122

123123

124124
@validator
125-
def unionpay(value: str):
125+
def unionpay(value: str, /):
126126
"""Return whether or not given value is a valid UnionPay card number.
127127
128128
Examples:
@@ -148,7 +148,7 @@ def unionpay(value: str):
148148

149149

150150
@validator
151-
def diners(value: str):
151+
def diners(value: str, /):
152152
"""Return whether or not given value is a valid Diners Club card number.
153153
154154
Examples:
@@ -174,7 +174,7 @@ def diners(value: str):
174174

175175

176176
@validator
177-
def jcb(value: str):
177+
def jcb(value: str, /):
178178
"""Return whether or not given value is a valid JCB card number.
179179
180180
Examples:
@@ -200,7 +200,7 @@ def jcb(value: str):
200200

201201

202202
@validator
203-
def discover(value: str):
203+
def discover(value: str, /):
204204
"""Return whether or not given value is a valid Discover card number.
205205
206206
Examples:

validators/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# standard
55
from typing import Any, Callable, Dict
66
from inspect import getfullargspec
7+
from functools import wraps
78
from itertools import chain
89

910

@@ -66,6 +67,7 @@ def validator(func: Callable[..., Any]):
6667
> *New in version 2013.10.21*.
6768
"""
6869

70+
@wraps(func)
6971
def wrapper(*args: Any, **kwargs: Any):
7072
return (
7173
True

0 commit comments

Comments
 (0)