From fcd58065fafcdf8a1ddb272cef68c8f1cb08eedb Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 20 Aug 2025 10:30:28 -0400 Subject: [PATCH] python-common: reformat utils.py with black Use the black formatter (with a single manual tweak) to reformat the utils.py file. This formatting will be enforced by a future change. Signed-off-by: John Mulligan --- src/python-common/ceph/utils.py | 51 +++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/python-common/ceph/utils.py b/src/python-common/ceph/utils.py index 0544e9f4173..5419de7da32 100644 --- a/src/python-common/ceph/utils.py +++ b/src/python-common/ceph/utils.py @@ -30,7 +30,8 @@ def datetime_to_str(dt: datetime.datetime) -> str: ISO 8601 (timezone=UTC). """ return dt.astimezone(tz=datetime.timezone.utc).strftime( - '%Y-%m-%dT%H:%M:%S.%fZ') + '%Y-%m-%dT%H:%M:%S.%fZ' + ) def str_to_datetime(string: str) -> datetime.datetime: @@ -50,7 +51,7 @@ def str_to_datetime(string: str) -> datetime.datetime: """ fmts = [ '%Y-%m-%dT%H:%M:%S.%f', - '%Y-%m-%dT%H:%M:%S.%f%z' + '%Y-%m-%dT%H:%M:%S.%f%z', ] # In *all* cases, the 9 digit second precision is too much for @@ -74,8 +75,11 @@ def str_to_datetime(string: str) -> datetime.datetime: except ValueError: pass - raise ValueError("Time data {} does not match one of the formats {}".format( - string, str(fmts))) + raise ValueError( + "Time data {} does not match one of the formats {}".format( + string, str(fmts) + ) + ) def parse_timedelta(delta: str) -> Optional[datetime.timedelta]: @@ -101,13 +105,15 @@ def parse_timedelta(delta: str) -> Optional[datetime.timedelta]: :return: The `datetime.timedelta` object or `None` in case of a parsing error. """ - parts = re.match(r'(?P-?\d+)s|' - r'(?P-?\d+)m|' - r'(?P-?\d+)h|' - r'(?P-?\d+)d|' - r'(?P-?\d+)w$', - delta, - re.IGNORECASE) + parts = re.match( + r'(?P-?\d+)s|' + r'(?P-?\d+)m|' + r'(?P-?\d+)h|' + r'(?P-?\d+)d|' + r'(?P-?\d+)w$', + delta, + re.IGNORECASE, + ) if not parts: return None parts = parts.groupdict() @@ -130,17 +136,18 @@ def is_hex(s: str, strict: bool = True) -> bool: return True -def http_req(hostname: str = '', - port: str = '443', - method: Optional[str] = None, - headers: MutableMapping[str, str] = {}, - data: Optional[str] = None, - endpoint: str = '/', - scheme: str = 'https', - ssl_verify: bool = False, - timeout: Optional[int] = None, - ssl_ctx: Optional[Any] = None) -> Tuple[Any, Any, Any]: - +def http_req( + hostname: str = '', + port: str = '443', + method: Optional[str] = None, + headers: MutableMapping[str, str] = {}, + data: Optional[str] = None, + endpoint: str = '/', + scheme: str = 'https', + ssl_verify: bool = False, + timeout: Optional[int] = None, + ssl_ctx: Optional[Any] = None, +) -> Tuple[Any, Any, Any]: if not ssl_ctx: ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) if not ssl_verify: -- 2.39.5