Skip to content

Commit 7dbfe7f

Browse files
authored
Merge pull request #756 from cisagov/CRASM_1073_fstrings_to_format
Replace all f-strings to use .format
2 parents 2c136b2 + 67e1269 commit 7dbfe7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+696
-548
lines changed

backend/scripts/populateCountiesCities/cities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def pull_cities():
117117
)
118118
time.sleep(1)
119119
except Exception as e:
120-
print(f"Error: {e}")
120+
print("Error: {}".format(e))
121121
pass
122122

123123
df = pd.DataFrame(holding_pen, columns=["State", "County", "City", "URL"])

backend/scripts/populateCountiesCities/counties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def pull_counties():
6262
}
6363
)
6464
except Exception as e:
65-
print(f"Error: {e}")
65+
print("Error: {}".format(e))
6666
pass
6767

6868
time.sleep(1)

backend/src/xfd_django/xfd_api/api_methods/auth.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88

99
async def handle_okta_callback(request):
1010
"""POST API LOGIC."""
11-
print(f"Request from /auth/okta-callback: {str(request)}")
11+
print("Request from /auth/okta-callback: {}".format(str(request)))
1212
body = await request.json()
13-
print(f"Request json from callback: {str(request)}")
14-
print(f"Request json from callback: {body}")
15-
print(f"Body type: {type(body)}")
13+
print("Request json from callback: {}".format(str(request)))
14+
print("Request json from callback: {}".format(body))
15+
print("Body type: {}".format(type(body)))
1616
code = body.get("code")
17-
print(f"Code: {code}")
17+
print("Code: {}".format(code))
1818
if not code:
1919
return HTTPException(
2020
status_code=status.HTTP_400_BAD_REQUEST,
2121
detail="Code not found in request body",
2222
)
2323
jwt_data = await get_jwt_from_code(code)
24-
print(f"JWT Data: {jwt_data}")
24+
print("JWT Data: {}".format(jwt_data))
2525
if jwt_data is None:
2626
raise HTTPException(
2727
status_code=status.HTTP_400_BAD_REQUEST,

backend/src/xfd_django/xfd_api/api_methods/domain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def export_domains(domain_search: DomainSearch, current_user):
167167
for product in service.products.all():
168168
if product.name:
169169
product_entry = (
170-
f"{product.name} {product.version}"
170+
"{} {}".format(product.name, product.version)
171171
if product.version
172172
else product.name
173173
)
@@ -221,5 +221,5 @@ def export_domains(domain_search: DomainSearch, current_user):
221221

222222
except Exception as e:
223223
# Log the exception for debugging (optional)
224-
print(f"Error exporting domains: {e}")
224+
print("Error exporting domains: {}".format(e))
225225
raise HTTPException(status_code=500, detail=str(e))

backend/src/xfd_django/xfd_api/api_methods/organization.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def get_organization(organization_id, current_user):
250250
raise http_exc
251251

252252
except Exception as e:
253-
print(f"An error occurred: {e}")
253+
print("An error occurred: {}".format(e))
254254
raise HTTPException(status_code=500, detail=str(e))
255255

256256

@@ -715,7 +715,7 @@ def delete_organization(org_id: str, current_user):
715715
# Return success response
716716
return {
717717
"status": "success",
718-
"message": f"Organization {org_id} has been deleted successfully.",
718+
"message": "Organization {} has been deleted successfully.".format(org_id),
719719
}
720720

721721
except HTTPException as http_exc:
@@ -1064,7 +1064,7 @@ def search_organizations_task(search_body, current_user: User):
10641064
# Use match_all if searchTerm is empty
10651065
if search_body.searchTerm.strip():
10661066
query_body["query"]["bool"]["must"].append(
1067-
{"wildcard": {"name": f"*{search_body.searchTerm}*"}}
1067+
{"wildcard": {"name": "*{}*".format(search_body.searchTerm)}}
10681068
)
10691069
else:
10701070
query_body["query"]["bool"]["must"].append({"match_all": {}})
@@ -1076,7 +1076,7 @@ def search_organizations_task(search_body, current_user: User):
10761076
)
10771077

10781078
# Log the query for debugging
1079-
print(f"Query body: {query_body}")
1079+
print("Query body: {}".format(query_body))
10801080

10811081
# Execute the search
10821082
search_results = client.search_organizations(query_body)

backend/src/xfd_django/xfd_api/api_methods/proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ async def proxy_request(
3232
if cookie_name:
3333
cookies = manipulate_cookie(request, cookie_name)
3434
if cookies:
35-
headers["Cookie"] = f"{cookie_name}={cookies[cookie_name]}"
35+
headers["Cookie"] = "{}={}".format(cookie_name, cookies[cookie_name])
3636

3737
# Make the request to the target URL
3838
async with httpx.AsyncClient() as client:
3939
proxy_response = await client.request(
4040
method=request.method,
41-
url=f"{target_url}/{path}",
41+
url="{}/{}".format(target_url, path),
4242
headers=headers,
4343
params=request.query_params,
4444
content=await request.body(),

backend/src/xfd_django/xfd_api/api_methods/saved_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def delete_saved_search(saved_search_id, user):
235235
return JsonResponse(
236236
{
237237
"status": "success",
238-
"message": f"Saved search id:{saved_search_id} deleted.",
238+
"message": "Saved search id:{} deleted.".format(saved_search_id),
239239
}
240240
)
241241
except User.DoesNotExist:

backend/src/xfd_django/xfd_api/api_methods/scan.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ def delete_scan(scan_id: str, current_user):
270270

271271
scan.delete()
272272

273-
return {"status": "success", "message": f"Scan {scan_id} deleted successfully."}
273+
return {
274+
"status": "success",
275+
"message": "Scan {} deleted successfully.".format(scan_id),
276+
}
274277

275278
except HTTPException as http_exc:
276279
raise http_exc
@@ -297,7 +300,7 @@ def run_scan(scan_id: str, current_user):
297300
scan.save()
298301
return {
299302
"status": "success",
300-
"message": f"Scan {scan_id} set to manualRunPending.",
303+
"message": "Scan {} set to manualRunPending.".format(scan_id),
301304
}
302305

303306
except HTTPException as http_exc:
@@ -320,7 +323,7 @@ async def invoke_scheduler(current_user):
320323
lambda_client = LambdaClient()
321324

322325
# Form the lambda function name using environment variable
323-
lambda_function_name = f"{os.getenv('SLS_LAMBDA_PREFIX')}-scheduler"
326+
lambda_function_name = "{}-scheduler".format(os.getenv("SLS_LAMBDA_PREFIX"))
324327
print(lambda_function_name)
325328

326329
# Run the Lambda command

backend/src/xfd_django/xfd_api/api_methods/scan_tasks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def list_scan_tasks(search_data: Optional[ScanTaskSearch], current_user):
3737

3838
# Determine the correct ordering based on the 'order' field
3939
ordering_field = (
40-
f"-{search_data.sort}"
40+
"-{}".format(search_data.sort)
4141
if search_data.order and search_data.order.upper() == "DESC"
42-
else search_data.sort
42+
else "{}".format(search_data.sort)
4343
)
4444

4545
# Construct query based on filters
@@ -71,7 +71,7 @@ def list_scan_tasks(search_data: Optional[ScanTaskSearch], current_user):
7171
for task in qs:
7272
# Ensure scan is not None before accessing its properties
7373
if task.scan is None:
74-
print(f"Warning: ScanTask {task.id} has no scan associated.")
74+
print("Warning: ScanTask {} has no scan associated.".format(task.id))
7575
scan_data = None
7676
else:
7777
scan_data = {
@@ -177,7 +177,7 @@ def kill_scan_task(scan_task_id, current_user):
177177
utc_now = datetime.now(timezone.utc)
178178
scan_task.status = "failed"
179179
scan_task.finishedAt = utc_now
180-
scan_task.output = f"Manually stopped at {utc_now.isoformat()}"
180+
scan_task.output = "Manually stopped at {}".format(utc_now.isoformat())
181181
scan_task.save()
182182

183183
return {"statusCode": 200, "message": "ScanTask successfully marked as failed."}

backend/src/xfd_django/xfd_api/api_methods/search.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def fetch_all_results(
6767
try:
6868
response = client.search_domains(request)
6969
except Exception as e:
70-
print(f"Elasticsearch error: {e}")
70+
print("Elasticsearch error: {}".format(e))
7171
raise HTTPException(status_code=500, detail="Error querying Elasticsearch.")
7272

7373
hits = response.get("hits", {}).get("hits", [])
@@ -97,9 +97,9 @@ def process_results(results: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
9797
if "name" in product:
9898
product_name = product["name"].lower()
9999
product_version = product.get("version", "")
100-
products[
101-
product_name
102-
] = f"{product['name']} {product_version}".strip()
100+
products[product_name] = "{} {}".format(
101+
product["name"], product_version
102+
).strip()
103103

104104
res["products"] = ", ".join(products.values())
105105
processed_results.append(res)
@@ -204,7 +204,7 @@ async def search_export(search_body: DomainSearchBody, current_user) -> Dict[str
204204
try:
205205
csv_url = s3_client.save_csv(csv_content, "domains")
206206
except Exception as e:
207-
print(f"S3 upload error: {e}")
207+
print("S3 upload error: {}".format(e))
208208
raise HTTPException(status_code=500, detail="Error uploading CSV to S3.")
209209

210210
return {"url": csv_url}

0 commit comments

Comments
 (0)