From 8e3d9c4d89c4b65825f6fe4b04e63ebd92a455e7 Mon Sep 17 00:00:00 2001 From: Flynn Date: Fri, 16 Aug 2024 15:46:35 -0400 Subject: [PATCH] Formatting. Signed-off-by: Flynn --- kubernetes/utils/duration.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kubernetes/utils/duration.py b/kubernetes/utils/duration.py index eb85abc9d..3f434d081 100644 --- a/kubernetes/utils/duration.py +++ b/kubernetes/utils/duration.py @@ -21,9 +21,11 @@ import durationpy # really be a big deal. reDuration = re.compile(r'^([0-9]{1,5}(h|m|s|ms)){1,4}$') -# maxDuration_ms is the maximum duration that GEP-2257 can support, in milliseconds. +# maxDuration_ms is the maximum duration that GEP-2257 can support, in +# milliseconds. maxDuration_ms = (((99999 * 3600) + (59 * 60) + 59) * 1_000) + 999 + def parse_duration(duration) -> datetime.timedelta: """ Parse GEP-2257 Duration format to a datetime.timedelta object. @@ -75,6 +77,7 @@ def parse_duration(duration) -> datetime.timedelta: return durationpy.from_str(duration) + def format_duration(delta: datetime.timedelta) -> str: """ Format a datetime.timedelta object to GEP-2257 Duration format. @@ -130,7 +133,8 @@ def format_duration(delta: datetime.timedelta) -> str: raise ValueError("Cannot express negative durations in GEP-2257: {}".format(delta)) if delta > datetime.timedelta(milliseconds=maxDuration_ms): - raise ValueError("Cannot express durations longer than 99999h59m59s999ms in GEP-2257: {}".format(delta)) + raise ValueError( + "Cannot express durations longer than 99999h59m59s999ms in GEP-2257: {}".format(delta)) # durationpy.to_str() is happy to use floating-point seconds, which # GEP-2257 is _not_ happy with. So start by peeling off any microseconds @@ -158,4 +162,3 @@ def format_duration(delta: datetime.timedelta) -> str: delta_str += f"{delta_ms}ms" return delta_str -