From 1efd9eb7ac2b088c39f8047ef0d7bafea054c787 Mon Sep 17 00:00:00 2001 From: Lazlo Westerhof Date: Tue, 9 Jul 2024 14:59:14 +0200 Subject: [PATCH] Use f-string instead of format call --- api.py | 10 +++++----- fileviewer/fileviewer.py | 2 +- research/research.py | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api.py b/api.py index 2bcbd535..226d20c2 100644 --- a/api.py +++ b/api.py @@ -58,7 +58,7 @@ def break_strings(N: int, m: int) -> int: return (N - 1) // m + 1 def nrep_string_expr(s: str, m: int = 64) -> str: - return '++\n'.join('"{}"'.format(escape_quotes(s[i * m:i * m + m])) for i in range(break_strings(len(s), m) + 1)) + return '++\n'.join(f'"{escape_quotes(s[i * m:i * m + m])}"' for i in range(break_strings(len(s), m) + 1)) if app.config.get('LOG_API_CALL_DURATION', False): begintime = timer() @@ -74,9 +74,9 @@ def nrep_string_expr(s: str, m: int = 64) -> str: arg_str_expr = nrep_string_expr(base64_encoded_params.decode('utf-8')) # Set parameters as variable instead of parameter input to circumvent iRODS string limits. - rule_body = ''' *x={} - api_{}(*x) - '''.format(arg_str_expr, fn) + rule_body = f''' *x={arg_str_expr} + api_{fn}(*x) + ''' x = rule.Rule( g.irods, @@ -97,7 +97,7 @@ def nrep_string_expr(s: str, m: int = 64) -> str: if app.config.get('LOG_API_CALL_DURATION', False): endtime = timer() callduration = round((endtime - begintime) * 1000) - print("DEBUG: {:4d}ms api_{} {}".format(callduration, fn, params), file=sys.stderr) + print(f"DEBUG: {callduration:4d}ms api_{fn} {params}", file=sys.stderr) return json.loads(result) diff --git a/fileviewer/fileviewer.py b/fileviewer/fileviewer.py index ecb46db6..fe1f9294 100644 --- a/fileviewer/fileviewer.py +++ b/fileviewer/fileviewer.py @@ -51,7 +51,7 @@ def irods_writer() -> None: obj_desc.write(chunk.data) except Exception: failure = True - log_error("Chunk upload failed for {}".format(chunk.path)) + log_error(f"Chunk upload failed for {chunk.path}") finally: try: obj_desc.close() diff --git a/research/research.py b/research/research.py index f4fd95a6..d1c94539 100644 --- a/research/research.py +++ b/research/research.py @@ -54,7 +54,7 @@ def irods_writer() -> None: obj_desc.write(chunk.data) except Exception: failure = True - log_error("Chunk upload failed for {}".format(chunk.path)) + log_error(f"Chunk upload failed for {chunk.path}") finally: try: obj_desc.close() @@ -226,8 +226,7 @@ def upload_post() -> Response: # No file was present, which is okay. pass except Exception as e: - log_error("Error occurred when truncating existing object on upload at {} ({}:{})".format( - object_path, str(type(e)), str(e))) + log_error(f"Error occurred when truncating existing object on upload at {object_path} ({str(type(e))}:{str(e)})") response = make_response(jsonify({"message": "Upload failed when truncating existing data object."}), 500) response.headers["Content-Type"] = "application/json" return response @@ -271,8 +270,9 @@ def upload_post() -> Response: # No file was present, which is okay. pass except Exception as e: - log_error("Error occurred on upload when unlinking existing object at {} ({}:{})".format( - final_object_path, str(type(e)), str(e))) + log_error( + f"Error occurred on upload when unlinking existing object at {final_object_path} ({str(type(e))}:{str(e)})" + ) response = make_response(jsonify({"message": "Upload failed when removing existing data object."}), 500) response.headers["Content-Type"] = "application/json" return response