Skip to content

Commit

Permalink
Use f-string instead of format call
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Jul 9, 2024
1 parent 9b6d6b2 commit 1efd9eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion fileviewer/fileviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions research/research.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1efd9eb

Please sign in to comment.