Skip to content

Commit fcd5806

Browse files
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 <[email protected]>
1 parent 6ef9f6f commit fcd5806

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

src/python-common/ceph/utils.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def datetime_to_str(dt: datetime.datetime) -> str:
3030
ISO 8601 (timezone=UTC).
3131
"""
3232
return dt.astimezone(tz=datetime.timezone.utc).strftime(
33-
'%Y-%m-%dT%H:%M:%S.%fZ')
33+
'%Y-%m-%dT%H:%M:%S.%fZ'
34+
)
3435

3536

3637
def str_to_datetime(string: str) -> datetime.datetime:
@@ -50,7 +51,7 @@ def str_to_datetime(string: str) -> datetime.datetime:
5051
"""
5152
fmts = [
5253
'%Y-%m-%dT%H:%M:%S.%f',
53-
'%Y-%m-%dT%H:%M:%S.%f%z'
54+
'%Y-%m-%dT%H:%M:%S.%f%z',
5455
]
5556

5657
# In *all* cases, the 9 digit second precision is too much for
@@ -74,8 +75,11 @@ def str_to_datetime(string: str) -> datetime.datetime:
7475
except ValueError:
7576
pass
7677

77-
raise ValueError("Time data {} does not match one of the formats {}".format(
78-
string, str(fmts)))
78+
raise ValueError(
79+
"Time data {} does not match one of the formats {}".format(
80+
string, str(fmts)
81+
)
82+
)
7983

8084

8185
def parse_timedelta(delta: str) -> Optional[datetime.timedelta]:
@@ -101,13 +105,15 @@ def parse_timedelta(delta: str) -> Optional[datetime.timedelta]:
101105
:return: The `datetime.timedelta` object or `None` in case of
102106
a parsing error.
103107
"""
104-
parts = re.match(r'(?P<seconds>-?\d+)s|'
105-
r'(?P<minutes>-?\d+)m|'
106-
r'(?P<hours>-?\d+)h|'
107-
r'(?P<days>-?\d+)d|'
108-
r'(?P<weeks>-?\d+)w$',
109-
delta,
110-
re.IGNORECASE)
108+
parts = re.match(
109+
r'(?P<seconds>-?\d+)s|'
110+
r'(?P<minutes>-?\d+)m|'
111+
r'(?P<hours>-?\d+)h|'
112+
r'(?P<days>-?\d+)d|'
113+
r'(?P<weeks>-?\d+)w$',
114+
delta,
115+
re.IGNORECASE,
116+
)
111117
if not parts:
112118
return None
113119
parts = parts.groupdict()
@@ -130,17 +136,18 @@ def is_hex(s: str, strict: bool = True) -> bool:
130136
return True
131137

132138

133-
def http_req(hostname: str = '',
134-
port: str = '443',
135-
method: Optional[str] = None,
136-
headers: MutableMapping[str, str] = {},
137-
data: Optional[str] = None,
138-
endpoint: str = '/',
139-
scheme: str = 'https',
140-
ssl_verify: bool = False,
141-
timeout: Optional[int] = None,
142-
ssl_ctx: Optional[Any] = None) -> Tuple[Any, Any, Any]:
143-
139+
def http_req(
140+
hostname: str = '',
141+
port: str = '443',
142+
method: Optional[str] = None,
143+
headers: MutableMapping[str, str] = {},
144+
data: Optional[str] = None,
145+
endpoint: str = '/',
146+
scheme: str = 'https',
147+
ssl_verify: bool = False,
148+
timeout: Optional[int] = None,
149+
ssl_ctx: Optional[Any] = None,
150+
) -> Tuple[Any, Any, Any]:
144151
if not ssl_ctx:
145152
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
146153
if not ssl_verify:

0 commit comments

Comments
 (0)