Skip to content

Commit

Permalink
wpt: Update some security-features scripts to run under Python 3.
Browse files Browse the repository at this point in the history
In Python 3, dict.keys() returns an object which doesn't have
a remove() method. Instead, this is converted to a list so that
this kind of manipulation is possible.

basestring no longer exists in Python 3, so str is used instead.
Technically basestring also includes bytes, but as far as I can
tell it's not reasonable for bytes to end up here.

Finally, message is not guaranteed to exist, so the error object
itself is printed instead.

Change-Id: Iad38779f8cfcfe1f464b73e8cbabef923d90f6ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5090427
Reviewed-by: Hiroshige Hayashizaki <[email protected]>
Commit-Queue: Jeremy Roman <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1234071}
  • Loading branch information
jeremyroman authored and chromium-wpt-export-bot committed Dec 6, 2023
1 parent 7300601 commit 8b2ff8f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion common/security-features/tools/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def generate_test_source_files(spec_directory, test_helper_filenames,
# Choose a debug/release template depending on the target.
html_template = "test.%s.html.template" % target

artifact_order = test_expansion_schema.keys()
artifact_order = list(test_expansion_schema.keys())
artifact_order.remove('expansion')

excluded_selection_pattern = ''
Expand Down
6 changes: 3 additions & 3 deletions common/security-features/tools/spec_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def assert_non_empty_string(obj, field):
assert field in obj, 'Missing field "%s"' % field
assert isinstance(obj[field], basestring), \
assert isinstance(obj[field], str), \
'Field "%s" must be a string' % field
assert len(obj[field]) > 0, 'Field "%s" must not be empty' % field

Expand Down Expand Up @@ -34,7 +34,7 @@ def assert_value_from(obj, field, items):


def assert_atom_or_list_items_from(obj, field, items):
if isinstance(obj[field], basestring) or isinstance(
if isinstance(obj[field], str) or isinstance(
obj[field], int) or obj[field] is None:
assert_value_from(obj, field, items)
return
Expand Down Expand Up @@ -236,7 +236,7 @@ def assert_valid_spec_json(spec_json):
try:
validate(spec_json, error_details)
except AssertionError as err:
print('ERROR:', err.message)
print('ERROR:', err)
print(json.dumps(error_details, indent=4))
sys.exit(1)

Expand Down

0 comments on commit 8b2ff8f

Please sign in to comment.