Skip to content

Commit 6933afe

Browse files
committed
Refactor logging to use % formatting for performance
1 parent 1fed409 commit 6933afe

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

httpx_gssapi/gssapi_.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _wrapper(*args, **kwargs):
8282
return func(*args, **kwargs)
8383
except GSSError as error:
8484
msg = f"{gss_stage} context failed: {error.gen_message()}"
85-
log.exception(f"{func.__name__}(): {msg}")
85+
log.exception("%s(): %s", func.__name__, msg)
8686
if callable(result):
8787
return result(msg, *args, **kwargs)
8888
return result
@@ -164,7 +164,7 @@ def handle_response(self,
164164
num_401s = 0
165165
while response.status_code == 401 and num_401s < 2:
166166
num_401s += 1
167-
log.debug(f"Handling 401 response, total seen: {num_401s}")
167+
log.debug("Handling 401 response, total seen: %d", num_401s)
168168

169169
if _negotiate_value(response) is None:
170170
log.debug("GSSAPI is not supported")
@@ -191,7 +191,7 @@ def handle_mutual_auth(self, response: Response, ctx: SecurityContext):
191191
192192
This is necessary so that we can authenticate responses if requested
193193
"""
194-
log.debug(f"handle_mutual_auth(): Handling {response.status_code}")
194+
log.debug("handle_mutual_auth(): Handling %d", response.status_code)
195195

196196
if self.mutual_authentication == DISABLED:
197197
log.debug("handle_mutual_auth(): Mutual auth disabled, ignoring")
@@ -213,8 +213,9 @@ def handle_mutual_auth(self, response: Response, ctx: SecurityContext):
213213
elif is_http_error or self.mutual_authentication == OPTIONAL:
214214
if response.status_code != httpx.codes.OK:
215215
log.error(
216-
f"handle_mutual_auth(): Mutual authentication unavailable "
217-
f"on {response.status_code} response"
216+
"handle_mutual_auth(): Mutual authentication unavailable"
217+
" on %d response",
218+
response.status_code,
218219
)
219220
if (self.mutual_authentication == REQUIRED
220221
and self.sanitize_mutual_error_response):
@@ -243,9 +244,9 @@ def set_auth_header(self,
243244
gss_resp = ctx.step(token or None)
244245
auth_header = f"Negotiate {b64encode(gss_resp).decode()}"
245246
log.debug(
246-
f"add_request_header(): "
247-
f"{'Preemptive ' if token is None else ''}"
248-
f"Authorization header: {auth_header}"
247+
"add_request_header(): %sAuthorization header: %s",
248+
'Preemptive ' if token is None else '',
249+
auth_header,
249250
)
250251

251252
request.headers['Authorization'] = auth_header
@@ -262,7 +263,7 @@ def authenticate_server(self,
262263
Returns True on success, False on failure.
263264
"""
264265
auth_header = _negotiate_value(response)
265-
log.debug(f"authenticate_server(): Authenticate header: {auth_header}")
266+
log.debug("authenticate_server(): Authenticate header: %s", auth_header)
266267

267268
# If the handshake isn't complete here, nothing we can do
268269
ctx.step(auth_header)

0 commit comments

Comments
 (0)