r"([a-z-]+://)" # scheme
r"([a-z_\d-]+:[a-z_\d-]+@)?" # user:password
r"(www\.)?" # www.
- r"((?<!\.)[a-z\d]+[a-z\d.-]+\.[a-z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|localhost)" # domain
+ r"((?<!\.)[a-z\d]+[a-z\d.-]+\.[a-z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|localhost)" # domain
r"(:\d{2,})?" # port number
r"(/[a-z\d_%+-]*)*" # folders
r"(\.[a-z\d_%+-]+)*" # file extension
True
>>> is_none_or_empty(None)
True
- >>> is_none_or_empty(" ")
+ >>> is_none_or_empty(" \t ")
True
>>> is_none_or_empty('Test')
False
def is_empty_string(in_str: Any) -> bool:
+ return is_empty(in_str)
+
+
+def is_empty(in_str: Any) -> bool:
"""
Checks if input is a string and empty or only whitespace.
- >>> is_empty_string('')
+ >>> is_empty('')
True
- >>> is_empty_string(' \t\t ')
+ >>> is_empty(' \t\t ')
True
- >>> is_empty_string('test')
+ >>> is_empty('test')
False
- >>> is_empty_string(100.88)
+ >>> is_empty(100.88)
False
- >>> is_empty_string([1, 2, 3])
+ >>> is_empty([1, 2, 3])
False
"""
return is_string(in_str) and in_str.strip() == ""
"""
Checks if a string is a valid ip (either v4 or v6).
- *Examples:*
-
>>> is_ip('255.200.100.75')
True
>>> is_ip('2001:db8:85a3:0000:0000:8a2e:370:7334')
>>> to_bool('True')
True
+
>>> to_bool('1')
True
+
>>> to_bool('yes')
True
+
>>> to_bool('no')
False
+
>>> to_bool('huh?')
False
+
+ >>> to_bool('on')
+ True
+
"""
if not is_string(in_str):
raise ValueError(in_str)
- return in_str.lower() in ("true", "1", "yes", "y", "t")
+ return in_str.lower() in ("true", "1", "yes", "y", "t", "on")
def to_date(in_str: str) -> Optional[datetime.date]: