mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 13:22:58 +00:00
Code refactoring (#889)
* Add __all__ to all module and plugin utils. * Convert quite a few positional args to keyword args. * Avoid Python 3.8+ syntax.
This commit is contained in:
@@ -19,7 +19,7 @@ from ansible_collections.community.crypto.plugins.module_utils._crypto.basic imp
|
||||
UTC = datetime.timezone.utc
|
||||
|
||||
|
||||
def get_now_datetime(with_timezone: bool) -> datetime.datetime:
|
||||
def get_now_datetime(*, with_timezone: bool) -> datetime.datetime:
|
||||
if with_timezone:
|
||||
return datetime.datetime.now(tz=UTC)
|
||||
return datetime.datetime.utcnow()
|
||||
@@ -44,7 +44,7 @@ def remove_timezone(timestamp: datetime.datetime) -> datetime.datetime:
|
||||
|
||||
|
||||
def add_or_remove_timezone(
|
||||
timestamp: datetime.datetime, with_timezone: bool
|
||||
timestamp: datetime.datetime, *, with_timezone: bool
|
||||
) -> datetime.datetime:
|
||||
return (
|
||||
ensure_utc_timezone(timestamp) if with_timezone else remove_timezone(timestamp)
|
||||
@@ -59,7 +59,7 @@ def get_epoch_seconds(timestamp: datetime.datetime) -> float:
|
||||
|
||||
|
||||
def from_epoch_seconds(
|
||||
timestamp: int | float, with_timezone: bool
|
||||
timestamp: int | float, *, with_timezone: bool
|
||||
) -> datetime.datetime:
|
||||
if with_timezone:
|
||||
return datetime.datetime.fromtimestamp(timestamp, UTC)
|
||||
@@ -68,6 +68,7 @@ def from_epoch_seconds(
|
||||
|
||||
def convert_relative_to_datetime(
|
||||
relative_time_string: str,
|
||||
*,
|
||||
with_timezone: bool = False,
|
||||
now: datetime.datetime | None = None,
|
||||
) -> datetime.datetime | None:
|
||||
@@ -107,6 +108,7 @@ def convert_relative_to_datetime(
|
||||
|
||||
def get_relative_time_option(
|
||||
input_string: str,
|
||||
*,
|
||||
input_name: str,
|
||||
with_timezone: bool = False,
|
||||
now: datetime.datetime | None = None,
|
||||
@@ -155,3 +157,15 @@ def get_relative_time_option(
|
||||
raise OpenSSLObjectError(
|
||||
f'The time spec "{input_string}" for {input_name} is invalid'
|
||||
)
|
||||
|
||||
|
||||
__all__ = (
|
||||
"get_now_datetime",
|
||||
"ensure_utc_timezone",
|
||||
"remove_timezone",
|
||||
"add_or_remove_timezone",
|
||||
"get_epoch_seconds",
|
||||
"from_epoch_seconds",
|
||||
"convert_relative_to_datetime",
|
||||
"get_relative_time_option",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user