Skip to content

Commit 5d0cf27

Browse files
chore/numerous improvements (#9)
* Comparisons to None and other singleton objects should be with "is" and "is not" rather than "==" and "!=" https://www.flake8rules.com/rules/E711.html * removed generic TypeVar T as it currently has no impact and serves only to raise type mismatch warnings. * previously specified the List (uppercase) type, but it is frequently passed "list" types (lowercase). Both are valid, so added a Union to expect both to prevent type mismatch warnings. * should raise ValueError instead of a generic Exception * fixed a typo in the function name * minor: simplifying logic * split requirements.txt so that it only calls for packages required by users of this module, and a new requirements-dev.txt contains all the packages collected for dev, testing, etc. * correcting type definition: "allow_primitives" is a boolean, not a string * Fixed a typo in a variable name * setting "raw" strings for regex patterns to avoid warnings and problems with interpreting escapes * converting to "raw" strings for regex patterns * corrected a typo * should raise appropriate exceptions instead of generic exceptions * fixed typos in variable names * removed arbitrary backslashes: it is not necessary to escape a forward slash in most regex implementations, particularly with the re module * renamed a variable: should not use the name of built-in methods, in this case 'sum' * TypedDict only serves to cause type hint warnings here, so changed to dict * further cleanup: no point in the IsMobileNumberOptions class when dict could be used by itself, and it causes type hint warnings, so just removed it * fixed a typo in a local variable name * fixing more typos * typo in method name "sufix," and it does not appear to be used anywhere, so fixing while it is no impact * it is not safe practice to overwrite a method from a base/inherited class without matching the base method's inputs, so added "args" and "kwargs" inputs. * "search" method is redeclared without being used first, so the first declaration serves no purpose * nit: minor PEP 8 standard that function names should be lowercase, and this is an internal-only method, so renaming to match other multi-word methods (such as "search" and "trim" in the same String class) * Passing input of any type other than str, int, float, dict, or list causes a TypeError exception, because inspect is not directly callable. From context I assume this was meant to be "inspect.ismodule," and doing so resolves the error without breaking any tests. * Missing "staticmethod" decorator, so pattern would instead be treated as a "self" object. * Instead of comparing types to their string names, it is safer and much more flexible to use "isinstance" instead
1 parent d6726ef commit 5d0cf27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+271
-284
lines changed

pyvalidator/alpha.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
'sr-RS@latin': '^[A-ZČĆŽŠĐ]+$',
2424
'sr-RS': '^[А-ЯЂЈЉЊЋЏ]+$',
2525
'sv-SE': '^[A-ZÅÄÖ]+$',
26-
'th-TH': '^[ก-๐\s]+$',
26+
'th-TH': r'^[ก-๐\s]+$',
2727
'tr-TR': '^[A-ZÇĞİıÖŞÜ]+$',
2828
'uk-UA': '^[А-ЩЬЮЯЄIЇҐі]+$',
2929
'vi-VN': '^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$',
3030
'ku-IQ': '^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$',
3131
'ar': '^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+',
3232
'he': '^[א-ת]+',
33-
'fa': '^[\'آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی\']+$',
34-
'hi-IN': '^[\u0900-\u0961]+[\u0972-\u097F]*$',
33+
'fa': r'^[\'آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی\']+$',
34+
'hi-IN': r'^[\u0900-\u0961]+[\u0972-\u097F]*$',
3535
}
3636

3737
alphanumeric = {
@@ -58,15 +58,15 @@
5858
'sr-RS@latin': '^[0-9A-ZČĆŽŠĐ]+$',
5959
'sr-RS': '^[0-9А-ЯЂЈЉЊЋЏ]+$',
6060
'sv-SE': '^[0-9A-ZÅÄÖ]+$',
61-
'th-TH': '^[ก-๙\s]+$',
61+
'th-TH': r'^[ก-๙\s]+$',
6262
'tr-TR': '^[0-9A-ZÇĞİıÖŞÜ]+$',
6363
'uk-UA': '^[0-9А-ЩЬЮЯЄIЇҐі]+$',
6464
'ku-IQ': '^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$',
6565
'vi-VN': '^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$',
6666
'ar': '^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+',
6767
'he': '^[0-9א-ת]+',
68-
'fa': '^[\'0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰\']+$',
69-
'hi-IN': '^[\u0900-\u0963]+[\u0966-\u097F]*$',
68+
'fa': r'^[\'0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰\']+$',
69+
'hi-IN': r'^[\u0900-\u0963]+[\u0966-\u097F]*$',
7070
}
7171

7272
decimal = {

pyvalidator/is_alpha.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def is_alpha(input, locale='en-US', options={}):
77
input = assert_string(input)
88

9-
if locale == None:
9+
if locale is None:
1010
locale = 'en-US'
1111

1212
if 'ignore' in options and options['ignore']:
@@ -16,13 +16,13 @@ def is_alpha(input, locale='en-US', options={}):
1616

1717
input = input.sub(pattern, '')
1818
else:
19-
raise Exception('ignore should be instance of a String or RegExp')
19+
raise TypeError('ignore should be instance of a String or RegExp')
2020

2121
if locale in alpha:
2222
pattern = RegEx(alpha[locale], 'i')
2323
return pattern.match(input)
2424

25-
raise Exception("Invalid locale {}".format(locale))
25+
raise ValueError("Invalid locale {}".format(locale))
2626

2727

2828
locales = list(alpha.keys())

pyvalidator/is_ascii.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44

55
def is_ascii(input: str) -> bool:
6-
pattern = RegEx("^[\x00-\x7F]+$")
6+
pattern = RegEx(r"^[\x00-\x7F]+$")
77
input = assert_string(input)
88
return pattern.match(input)

pyvalidator/is_base64.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
def is_base64(input: str, options={}) -> bool:
1212
assert_string(input)
1313

14-
not_base64 = RegEx("[^A-Z0-9+\/=]", "i")
15-
url_safe_base64 = RegEx("^[A-Z0-9_\-]*$", "i")
14+
not_base64 = RegEx(r"[^A-Z0-9+/=]", "i")
15+
url_safe_base64 = RegEx(r"^[A-Z0-9_\-]*$", "i")
1616

1717
options = merge(options, default_base64_options)
1818
input_length = len(input)

pyvalidator/is_byte_length.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ def is_byte_length(input: str, options={}) -> bool:
2222
input_length = len(split_input) - 1
2323

2424
return input_length >= options["min"] and (
25-
options["max"] == None or input_length <= options["max"]
25+
options["max"] is None or input_length <= options["max"]
2626
)

pyvalidator/is_credit_card.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
def is_credit_card(input: str) -> bool:
77
input = assert_string(input)
88

9-
credit_card = RegEx("^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$")
10-
sanetization_pattern = RegEx("[- ]+", 'g')
9+
credit_card = RegEx(r"^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$")
10+
sanitization_pattern = RegEx("[- ]+", 'g')
1111

12-
sanitized = input.sub(sanetization_pattern, '')
12+
sanitized = input.sub(sanitization_pattern, '')
1313

1414
if not credit_card.match(sanitized):
1515
return False
1616

17-
sum = 0
17+
_sum = 0
1818
should_double = False
19-
reversed_sanetized_input = sanitized[::-1]
19+
reversed_sanitized_input = sanitized[::-1]
2020

21-
for digit in reversed_sanetized_input:
21+
for digit in reversed_sanitized_input:
2222
if not is_number(digit):
2323
return False
2424

@@ -27,11 +27,11 @@ def is_credit_card(input: str) -> bool:
2727
if should_double:
2828
tmp_num = tmp_num * 2
2929
if tmp_num >= 10:
30-
sum += ((tmp_num % 10) + 1)
30+
_sum += ((tmp_num % 10) + 1)
3131
else:
32-
sum += tmp_num
32+
_sum += tmp_num
3333
else:
34-
sum += tmp_num
34+
_sum += tmp_num
3535
should_double = not should_double
3636

37-
return bool(sanitized if (sum % 10) == 0 else False)
37+
return bool(sanitized if (_sum % 10) == 0 else False)

pyvalidator/is_currency.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55

66

77
def currency_regex(options):
8-
decimal_digits = "\d{" + str(options["digits_after_decimal"][0]) + "}"
8+
decimal_digits = r"\d{" + str(options["digits_after_decimal"][0]) + "}"
99
for index, digit in enumerate(options["digits_after_decimal"]):
1010
if index != 0:
11-
decimal_digits = "{}|\d{}{}{}".format(decimal_digits, '{', digit, '}')
11+
decimal_digits = r"{}|\d{}{}{}".format(decimal_digits, '{', digit, '}')
1212

1313
def __match(x):
1414
return "\\{}".format(x.group(0))
1515

16-
symbol = "({}){}".format(RegEx.sub("\W", __match, options["symbol"]), '' if options["require_symbol"] else '?')
16+
symbol = "({}){}".format(RegEx.sub(r"\W", __match, options["symbol"]), '' if options["require_symbol"] else '?')
1717
negative = '-?'
18-
whole_dollar_amount_without_sep = '[1-9]\d*'
19-
whole_dollar_amount_with_sep = "[1-9]\d{{0,2}}({}\d{{3}})*".format(options["thousands_separator"])
18+
whole_dollar_amount_without_sep = r'[1-9]\d*'
19+
whole_dollar_amount_with_sep = r"[1-9]\d{{0,2}}({}\d{{3}})*".format(options["thousands_separator"])
2020
valid_whole_dollar_amounts = [
2121
'0',
2222
whole_dollar_amount_without_sep,
2323
whole_dollar_amount_with_sep
2424
]
2525
whole_dollar_amount = "({})?".format(join(valid_whole_dollar_amounts, '|'))
26-
decimal_amount = "(\{}({})){}".format(options["decimal_separator"], decimal_digits, '' if options["require_decimal"] else '?')
26+
decimal_amount = r"(\{}({})){}".format(options["decimal_separator"], decimal_digits, '' if options["require_decimal"] else '?')
2727
pattern = "{}{}".format(
2828
whole_dollar_amount,
2929
decimal_amount if (options["allow_decimal"] or options["require_decimal"]) else ''
@@ -36,7 +36,7 @@ def __match(x):
3636
pattern = negative + pattern
3737

3838
if options["allow_negative_sign_placeholder"]:
39-
pattern = "( (?!\-))?" + pattern
39+
pattern = r"( (?!\-))?" + pattern
4040
elif options["allow_space_after_symbol"]:
4141
pattern = " ?" + pattern
4242
elif options["allow_space_after_digits"]:
@@ -53,7 +53,7 @@ def __match(x):
5353
elif not (options["negative_sign_before_digits"] and options["negative_sign_after_digits"]):
5454
pattern = negative + pattern
5555

56-
return RegEx("^(?!-? )(?=.*\d){}$".format(pattern))
56+
return RegEx(r"^(?!-? )(?=.*\d){}$".format(pattern))
5757

5858

5959
default_currency_options = {

pyvalidator/is_data_uri.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
def is_data_uri(input: str) -> bool:
66
assert_string(input)
77

8-
valid_media_type = RegEx("^[a-z]+\/[a-z0-9\-\+]+$", 'i')
9-
valid_attribute = RegEx("^[a-z\-]+=[a-z0-9\-]+$", 'i')
10-
valid_data = RegEx("^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$", 'i')
8+
valid_media_type = RegEx(r"^[a-z]+/[a-z0-9\-\+]+$", 'i')
9+
valid_attribute = RegEx(r"^[a-z\-]+=[a-z0-9\-]+$", 'i')
10+
valid_data = RegEx(r"^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@/\?%\s]*$", 'i')
1111

1212
data = input.split(',')
1313

pyvalidator/is_date.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ def zip(date_list: ListT[str], format_list: ListT[str]) -> ListT[Tuple[str, str]
6060
def is_date(input: str, options: IsDateOptions = {}) -> bool:
6161
input = assert_string(input)
6262

63-
date_format_pattern = RegEx(r"(^(y{4}|y{2})[|:;,.\/-](m{1,2})[|:;,.\/-](d{1,2})$)|(^(m{1,2})[|:;,.\/-](d{1,2})[|:;,.\/-]((y{4}|y{2})$))|(^(d{1,2})[|:;,.\/-](m{1,2})[|:;,.\/-]((y{4}|y{2})$))", 'i')
63+
date_format_pattern = RegEx(r"(^(y{4}|y{2})[|:;,./-](m{1,2})[|:;,./-](d{1,2})$)|(^(m{1,2})[|:;,./-](d{1,2})[|:;,./-]((y{4}|y{2})$))|(^(d{1,2})[|:;,./-](m{1,2})[|:;,./-]((y{4}|y{2})$))", 'i')
6464

6565
options = merge(options, __default_options)
6666

6767
format = String(options['format'])
6868

6969
if not date_format_pattern.match(format):
70-
raise Exception('Not supported format provided: ', format)
70+
raise ValueError('Not supported format provided: ', format)
7171

7272
format_delimiter: Union[str, None] = List(options['delimiters']).find(lambda delimiter, _: delimiter in format)
7373

@@ -80,20 +80,20 @@ def is_date(input: str, options: IsDateOptions = {}) -> bool:
8080
if not input_delimiter:
8181
return False
8282

83-
format = format if options['strict_mode'] else format.sub("\{}".format(input_delimiter), '/')
84-
input = input if options['strict_mode'] else input.sub("\{}".format(input_delimiter), '/')
83+
format = format if options['strict_mode'] else format.sub(r"\{}".format(input_delimiter), '/')
84+
input = input if options['strict_mode'] else input.sub(r"\{}".format(input_delimiter), '/')
8585

86-
format_tupples = zip(
86+
format_tuples = zip(
8787
input.split(date_delimiter),
8888
format.lower().split(date_delimiter)
8989
)
9090

9191
date_dict = {}
9292

93-
for format_tupple in format_tupples:
94-
if len(format_tupple[0]) != len(format_tupple[1]):
93+
for format_tuple in format_tuples:
94+
if len(format_tuple[0]) != len(format_tuple[1]):
9595
return False
96-
format_char = format_tupple[1][0]
97-
date_dict[format_char] = format_tupple[0]
96+
format_char = format_tuple[1][0]
97+
date_dict[format_char] = format_tuple[0]
9898

9999
return bool(to_date("{}/{}/{}".format(date_dict['m'], date_dict['d'], date_dict['y'])))

pyvalidator/is_decimal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def decimal_regexp(options):
1010
local_decimal = decimal[local]
1111
decimal_digits = options["decimal_digits"]
1212
require_decimal = '' if options["force_decimal"] else '?'
13-
regex = "^[-+]?([0-9]+)?(\{}[0-9]{{".format(local_decimal) + "{}}}){}$".format(decimal_digits, require_decimal)
13+
regex = r"^[-+]?([0-9]+)?(\{}[0-9]{{".format(local_decimal) + "{}}}){}$".format(decimal_digits, require_decimal)
1414
return RegEx(regex)
1515

1616

@@ -31,7 +31,7 @@ def is_decimal(input: str, options={}) -> bool:
3131
options = merge(options, default_decimal_options)
3232

3333
if options["locale"] not in decimal:
34-
raise Exception("Invalid locale '{}'".format(options["locale"]))
34+
raise ValueError("Invalid locale '{}'".format(options["locale"]))
3535

3636
without_white_space = input.sub(" ", '')
3737
return includesNot(blacklist, without_white_space) and bool(decimal_regexp(options).match(input))

pyvalidator/is_divisible_by.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
def is_divisible_by(input: str, num: Union[int, float, str]) -> bool:
99
assert_string(input)
10-
if to_float(input) != None and to_int(num) != None:
10+
if to_float(input) is not None and to_int(num) is not None:
1111
return (to_float(input) % to_int(num)) == 0
1212
return False

pyvalidator/is_ean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def reducer(acc, partial_sum):
3232
def is_ean(input: str) -> bool:
3333
input = assert_string(input)
3434

35-
valid_ean_regex = RegEx("^(\d{8}|\d{13}|\d{14})$")
35+
valid_ean_regex = RegEx(r"^(\d{8}|\d{13}|\d{14})$")
3636

3737
actual_check_digit = input.slice(-1)
3838
if not is_number(actual_check_digit):

pyvalidator/is_email.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import TypedDict, Union
22

33
from .is_byte_length import is_byte_length
44
from .is_fqdn import is_fqdn
@@ -20,7 +20,7 @@ class IsEmailOptions(TypedDict):
2020
domain_specific_validation: bool
2121
allow_ip_domain: bool
2222
blacklisted_chars: str
23-
host_blacklist: List
23+
host_blacklist: Union[List, list]
2424

2525

2626
default_email_options: IsEmailOptions = {
@@ -67,15 +67,15 @@ def is_email(input: str, options: IsEmailOptions = {}) -> bool:
6767
options = merge(options, default_email_options)
6868

6969
split_name_address = r"^([^\x00-\x1F\x7F-\x9F]+)<"
70-
email_user_part = r"^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$"
70+
email_user_part = r"^[a-z\d!#\$%&'\*\+\-/=\?\^_`{\|}~]+$"
7171
gmail_user_part = r"^[a-z\d]+$"
7272
quoted_email_user = r"^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$"
73-
email_user_utf8_part = r"^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$"
73+
email_user_utf8_part = r"^[a-z\d!#\$%&'\*\+\-/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$"
7474
quoted_email_user_utf8 = r"^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$"
7575
default_max_email_length = 254
7676

7777
if options["require_display_name"] or options["allow_display_name"]:
78-
display_email = input.findMatches(split_name_address, 'i')
78+
display_email = input.find_matches(split_name_address, 'i')
7979
if display_email:
8080
display_name = String(display_email[0])
8181

@@ -105,7 +105,7 @@ def is_email(input: str, options: IsEmailOptions = {}) -> bool:
105105
user = user.lower()
106106
username = String(user.split('+')[0])
107107

108-
if not is_byte_length(username.sub(RegEx('\.', 'g'), ''), {"min": 6, "max": 30}):
108+
if not is_byte_length(username.sub(RegEx(r'\.', 'g'), ''), {"min": 6, "max": 30}):
109109
return False
110110

111111
user_parts = username.split('.')
@@ -149,7 +149,7 @@ def is_email(input: str, options: IsEmailOptions = {}) -> bool:
149149
return False
150150

151151
if options["blacklisted_chars"]:
152-
if user.findMatches(RegEx("[" + options["blacklisted_chars"] + "]+", 'g')):
152+
if user.find_matches(RegEx("[" + options["blacklisted_chars"] + "]+", 'g')):
153153
return False
154154

155155
return True

pyvalidator/is_emoji.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
from .utils.assert_string import assert_string
55
from .utils.merge import merge
66

7-
empji_patterns = (
7+
emoji_patterns = (
88
"^["
9-
"\U0001F1E0-\U0001F1FF" # flags (iOS)
10-
"\U0001F300-\U0001F5FF" # symbols & pictographs
11-
"\U0001F600-\U0001F64F" # emoticons
12-
"\U0001F680-\U0001F6FF" # transport & map symbols
13-
"\U0001F700-\U0001F77F" # alchemical symbols
14-
"\U0001F780-\U0001F7FF" # Geometric Shapes Extended
15-
"\U0001F800-\U0001F8FF" # Supplemental Arrows-C
16-
"\U0001F900-\U0001F9FF" # Supplemental Symbols and Pictographs
17-
"\U0001FA00-\U0001FA6F" # Chess Symbols
18-
"\U0001FA70-\U0001FAFF" # Symbols and Pictographs Extended-A
19-
"\U00002702-\U000027B0" # Dingbats
9+
r"\U0001F1E0-\U0001F1FF" # flags (iOS)
10+
r"\U0001F300-\U0001F5FF" # symbols & pictographs
11+
r"\U0001F600-\U0001F64F" # emoticons
12+
r"\U0001F680-\U0001F6FF" # transport & map symbols
13+
r"\U0001F700-\U0001F77F" # alchemical symbols
14+
r"\U0001F780-\U0001F7FF" # Geometric Shapes Extended
15+
r"\U0001F800-\U0001F8FF" # Supplemental Arrows-C
16+
r"\U0001F900-\U0001F9FF" # Supplemental Symbols and Pictographs
17+
r"\U0001FA00-\U0001FA6F" # Chess Symbols
18+
r"\U0001FA70-\U0001FAFF" # Symbols and Pictographs Extended-A
19+
r"\U00002702-\U000027B0" # Dingbats
2020
"]$"
2121
)
2222

@@ -37,25 +37,25 @@ def is_emoji(input: str, options: IsEmojiOptions = {}) -> bool:
3737

3838
def is_flag_emoji(c):
3939
return (
40-
"\U0001F1E6\U0001F1E8" <= c <= "\U0001F1FF\U0001F1FC"
40+
r"\U0001F1E6\U0001F1E8" <= c <= r"\U0001F1FF\U0001F1FC"
4141
or (
4242
c in [
43-
"\U0001F3F4\U000e0067\U000e0062\U000e0065\U000e006e\U000e0067\U000e007f",
44-
"\U0001F3F4\U000e0067\U000e0062\U000e0073\U000e0063\U000e0074\U000e007f",
45-
"\U0001F3F4\U000e0067\U000e0062\U000e0077\U000e006c\U000e0073\U000e007f"
43+
r"\U0001F3F4\U000e0067\U000e0062\U000e0065\U000e006e\U000e0067\U000e007f",
44+
r"\U0001F3F4\U000e0067\U000e0062\U000e0073\U000e0063\U000e0074\U000e007f",
45+
r"\U0001F3F4\U000e0067\U000e0062\U000e0077\U000e006c\U000e0073\U000e007f"
4646
]
4747
)
4848
)
4949

50-
if options["omit_rule"] != None:
50+
if options["omit_rule"] is not None:
5151
input = input.sub(options["omit_rule"], '')
5252

5353
if not input.length:
5454
return False
5555

5656
for char in input:
5757
char = String(char)
58-
if not (char.match(empji_patterns) or is_flag_emoji(char)):
58+
if not (char.match(emoji_patterns) or is_flag_emoji(char)):
5959
return False
6060

6161
return True

pyvalidator/is_even.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def is_even(input: Union[int, str]) -> bool:
77
input = to_int(input)
88

9-
if input == None:
9+
if input is None:
1010
return False
1111

1212
return not bool(input % 2)

0 commit comments

Comments
 (0)