summaryrefslogtreecommitdiff
path: root/string_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'string_utils.py')
-rw-r--r--string_utils.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/string_utils.py b/string_utils.py
index 5eb03d2..0829846 100644
--- a/string_utils.py
+++ b/string_utils.py
@@ -28,7 +28,7 @@ URLS_RAW_STRING = (
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
@@ -150,7 +150,7 @@ def is_none_or_empty(in_str: Optional[str]) -> bool:
True
>>> is_none_or_empty(None)
True
- >>> is_none_or_empty(" ")
+ >>> is_none_or_empty(" \t ")
True
>>> is_none_or_empty('Test')
False
@@ -175,18 +175,22 @@ def is_string(obj: Any) -> bool:
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() == ""
@@ -733,8 +737,6 @@ def is_ip(in_str: Any) -> bool:
"""
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')