Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: LayoutTests/imported/web-platform-tests/subresource-integrity/support/generate_javascript.py

Issue 816533002: Import CSSWG Shapes tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: One more test expectations update Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/imported/web-platform-tests/subresource-integrity/subresource-integrity.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 from os import path, listdir
2 from hashlib import sha256, md5
3 from base64 import urlsafe_b64encode
4 import re
5
6 JS_DIR = path.normpath(path.join(__file__, "..", ".."))
7
8
9 def js_files():
10 '''
11 Yield each file in the javascript directory
12 '''
13 for f in listdir(JS_DIR):
14 if path.isfile(f) and f.endswith(".js"):
15 yield f
16
17
18 def format_digest(digest):
19 '''
20 URL-safe base64 encode a binary digest and strip any padding.
21 '''
22 return urlsafe_b64encode(digest).rstrip("=")
23
24
25 def sha256_uri(content):
26 '''
27 Generate an encoded sha256 URI.
28 '''
29 return "ni:///sha-256;%s" % format_digest(sha256(content).digest())
30
31
32 def md5_uri(content):
33 '''
34 Generate an encoded md5 digest URI.
35 '''
36 return "ni:///md5;%s" % format_digest(md5(content).digest())
37
38
39 def main():
40 for file in js_files():
41 base = path.splitext(path.basename(file))[0]
42 var_name = re.sub(r"[^a-z]", "_", base)
43 content = "%s=true;" % var_name
44 with open(file, "w") as f:
45 f.write(content)
46
47
48 if __name__ == "__main__":
49 main()
OLDNEW
« no previous file with comments | « LayoutTests/imported/web-platform-tests/subresource-integrity/subresource-integrity.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698