projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Get rid of blacklist/whitelist; use blocklist/allowlist instead.
[python_utils.git]
/
argparse_utils.py
diff --git
a/argparse_utils.py
b/argparse_utils.py
index 80046dee7b2c4619406bfec618d131df24d1e5c3..3799a47ccbc1a34a599cdd443eaf5dfa33a64772 100644
(file)
--- a/
argparse_utils.py
+++ b/
argparse_utils.py
@@
-5,7
+5,8
@@
import datetime
import logging
import os
import logging
import os
-import string_utils
+# This module is commonly used by others in here and should avoid
+# taking any unnecessary dependencies back on them.
logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
@@
-58,11
+59,13
@@
class ActionNoYes(argparse.Action):
def valid_bool(v):
if isinstance(v, bool):
return v
def valid_bool(v):
if isinstance(v, bool):
return v
- return string_utils.to_bool(v)
+ from string_utils import to_bool
+ return to_bool(v)
def valid_ip(ip: str) -> str:
def valid_ip(ip: str) -> str:
- s = string_utils.extract_ip_v4(ip.strip())
+ from string_utils import extract_ip_v4
+ s = extract_ip_v4(ip.strip())
if s is not None:
return s
msg = f"{ip} is an invalid IP address"
if s is not None:
return s
msg = f"{ip} is an invalid IP address"
@@
-71,7
+74,8
@@
def valid_ip(ip: str) -> str:
def valid_mac(mac: str) -> str:
def valid_mac(mac: str) -> str:
- s = string_utils.extract_mac_address(mac)
+ from string_utils import extract_mac_address
+ s = extract_mac_address(mac)
if s is not None:
return s
msg = f"{mac} is an invalid MAC address"
if s is not None:
return s
msg = f"{mac} is an invalid MAC address"
@@
-99,7
+103,8
@@
def valid_filename(filename: str) -> str:
def valid_date(txt: str) -> datetime.date:
def valid_date(txt: str) -> datetime.date:
- date = string_utils.to_date(txt)
+ from string_utils import to_date
+ date = to_date(txt)
if date is not None:
return date
msg = f'Cannot parse argument as a date: {txt}'
if date is not None:
return date
msg = f'Cannot parse argument as a date: {txt}'
@@
-108,7
+113,8
@@
def valid_date(txt: str) -> datetime.date:
def valid_datetime(txt: str) -> datetime.datetime:
def valid_datetime(txt: str) -> datetime.datetime:
- dt = string_utils.to_datetime(txt)
+ from string_utils import to_datetime
+ dt = to_datetime(txt)
if dt is not None:
return dt
msg = f'Cannot parse argument as datetime: {txt}'
if dt is not None:
return dt
msg = f'Cannot parse argument as datetime: {txt}'