Skip to content

Commit b86a01a

Browse files
authored
Ruff: Add and fix PLW15 (#10706)
1 parent a714e51 commit b86a01a

File tree

197 files changed

+969
-968
lines changed

Some content is hidden

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

197 files changed

+969
-968
lines changed

docker/install_chrome_dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def find_packages(library_name):
1818

1919

2020
def run_command(cmd, cwd=None, env=None):
21-
result = subprocess.run(cmd, cwd=cwd, env=env, capture_output=True, text=True)
21+
result = subprocess.run(cmd, cwd=cwd, env=env, capture_output=True, text=True, check=False)
2222
return result.stdout
2323

2424

@@ -27,7 +27,7 @@ def ldd(file_path):
2727
# For simplicity, I'm assuming if we get an error, the code is non-zero.
2828
try:
2929
result = subprocess.run(
30-
["ldd", file_path], capture_output=True, text=True,
30+
["ldd", file_path], capture_output=True, text=True, check=False,
3131
)
3232
stdout = result.stdout
3333
code = result.returncode

dojo/management/commands/csv_findings_export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def handle(self, *args, **options):
2626
findings = Finding.objects.filter(verified=True,
2727
active=True).select_related(
2828
"test__engagement__product")
29-
writer = csv.writer(open(file_path, "w"))
29+
writer = csv.writer(open(file_path, "w", encoding="utf-8"))
3030

3131
headers = [
3232
"product_name",

dojo/management/commands/import_surveys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def handle(self, *args, **options):
2929
# Find the current id in the surveys file
3030
path = os.path.dirname(os.path.abspath(__file__))
3131
path = path[:-19] + "fixtures/initial_surveys.json"
32-
contents = open(path).readlines()
32+
contents = open(path, encoding="utf-8").readlines()
3333
for line in contents:
3434
if '"polymorphic_ctype": ' in line:
3535
matchedLine = line
@@ -38,7 +38,7 @@ def handle(self, *args, **options):
3838
old_id = "".join(c for c in matchedLine if c.isdigit())
3939
new_line = matchedLine.replace(old_id, str(ctype_id))
4040
# Replace the all lines in the file
41-
with open(path, "w") as fout:
41+
with open(path, "w", encoding="utf-8") as fout:
4242
for line in contents:
4343
fout.write(line.replace(matchedLine, new_line))
4444
# Delete the temp question

dojo/tools/blackduck/importer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _process_csvfile(self, report):
3333
No file information then.
3434
"""
3535
security_issues = {}
36-
with open(str(report)) as f:
36+
with open(str(report), encoding="utf-8") as f:
3737
security_issues = self.__partition_by_key(f)
3838

3939
project_ids = set(security_issues.keys())
@@ -55,10 +55,10 @@ def _process_zipfile(self, report):
5555
# Backwards compatibility, newer versions of Blackduck have a source file rather
5656
# than a "files" file.
5757
if "source" in file_name or "files" in file_name:
58-
with io.TextIOWrapper(zip.open(full_file_name)) as f:
58+
with io.TextIOWrapper(zip.open(full_file_name), encoding="utf-8") as f:
5959
files = self.__partition_by_key(f)
6060
elif "security" in file_name:
61-
with io.TextIOWrapper(zip.open(full_file_name)) as f:
61+
with io.TextIOWrapper(zip.open(full_file_name), encoding="utf-8") as f:
6262
security_issues = self.__partition_by_key(f)
6363

6464
project_ids = set(files.keys()) & set(security_issues.keys())

dojo/tools/blackduck_binary_analysis/importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _process_csvfile(self, report, orig_report_name):
2727
If passed a CSV file, process.
2828
"""
2929
vulnerabilities = {}
30-
with open(str(report)) as f:
30+
with open(str(report), encoding="utf-8") as f:
3131
vulnerabilities = self.__partition_by_key(f)
3232

3333
sha1_hash_keys = set(vulnerabilities.keys())

dojo/tools/blackduck_component_risk/importer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ def _process_zipfile(self, report: Path) -> (dict, dict, dict):
5252
file_name = full_file_name.split("/")[-1]
5353
# Look for the component and security CSVs.
5454
if "component" in file_name:
55-
with io.TextIOWrapper(zip.open(full_file_name)) as f:
55+
with io.TextIOWrapper(zip.open(full_file_name), encoding="utf-8") as f:
5656
components = self.__get_components(f)
5757
c_file = True
5858
elif "security" in file_name:
59-
with io.TextIOWrapper(zip.open(full_file_name)) as f:
59+
with io.TextIOWrapper(zip.open(full_file_name), encoding="utf-8") as f:
6060
security_issues = self.__get_security_risks(f)
6161
s_file = True
6262
elif "source" in file_name:
63-
with io.TextIOWrapper(zip.open(full_file_name)) as f:
63+
with io.TextIOWrapper(zip.open(full_file_name), encoding="utf-8") as f:
6464
source = self.__get_source(f)
6565
# Raise exception to error-out if the zip is missing either of
6666
# these files.

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ select = [
6565
"PD",
6666
"PGH",
6767
"PLE",
68+
"PLW15",
6869
"TRY003",
6970
"TRY004",
7071
"TRY2",

tests/Import_scanner_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_check_test_file(self):
5858

5959
def test_check_for_forms(self):
6060
forms_path = dir_path[:-5] + "dojo/forms.py"
61-
file = open(forms_path, "r+")
61+
file = open(forms_path, "r+", encoding="utf-8")
6262
forms = file.readlines()
6363
file.close()
6464

@@ -96,7 +96,7 @@ def test_check_for_forms(self):
9696
@unittest.skip("Deprecated since Dynamic Parser infrastructure")
9797
def test_check_for_options(self):
9898
template_path = dir_path[:-5] + "dojo/templates/dojo/import_scan_results.html"
99-
file = open(template_path, "r+")
99+
file = open(template_path, "r+", encoding="utf-8")
100100
templates = file.readlines()
101101
file.close()
102102

unittests/dojo_test_case.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def import_scan_with_params(self, filename, scan_type="ZAP Scan", engagement=1,
481481
product_name=None, product_type_name=None, auto_create_context=None, expected_http_status_code=201, test_title=None,
482482
scan_date=None, service=None, forceActive=True, forceVerified=True):
483483

484-
with open(get_unit_tests_path() + "/" + filename) as testfile:
484+
with open(get_unit_tests_path() + "/" + filename, encoding="utf-8") as testfile:
485485
payload = {
486486
"minimum_severity": minimum_severity,
487487
"active": active,
@@ -533,7 +533,7 @@ def import_scan_with_params(self, filename, scan_type="ZAP Scan", engagement=1,
533533
def reimport_scan_with_params(self, test_id, filename, scan_type="ZAP Scan", engagement=1, minimum_severity="Low", active=True, verified=False, push_to_jira=None,
534534
tags=None, close_old_findings=True, group_by=None, engagement_name=None, scan_date=None,
535535
product_name=None, product_type_name=None, auto_create_context=None, expected_http_status_code=201, test_title=None):
536-
with open(get_unit_tests_path() + "/" + filename) as testfile:
536+
with open(get_unit_tests_path() + "/" + filename, encoding="utf-8") as testfile:
537537
payload = {
538538
"minimum_severity": minimum_severity,
539539
"active": active,
@@ -582,7 +582,7 @@ def reimport_scan_with_params(self, test_id, filename, scan_type="ZAP Scan", eng
582582
def endpoint_meta_import_scan_with_params(self, filename, product=1, product_name=None,
583583
create_endpoints=True, create_tags=True, create_dojo_meta=True,
584584
expected_http_status_code=201):
585-
with open(get_unit_tests_path() + "/" + filename) as testfile:
585+
with open(get_unit_tests_path() + "/" + filename, encoding="utf-8") as testfile:
586586
payload = {
587587
"create_endpoints": create_endpoints,
588588
"create_tags": create_tags,

unittests/test_apiv2_scan_import_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def setUp(self):
3030
test.save()
3131

3232
def import_zap_scan(self, upload_empty_scan=False):
33-
with open("tests/zap_sample.xml") as file:
33+
with open("tests/zap_sample.xml", encoding="utf-8") as file:
3434
if upload_empty_scan:
3535
file = SimpleUploadedFile("zap_sample.xml", self.EMPTY_ZAP_SCAN.encode("utf-8"))
3636

0 commit comments

Comments
 (0)