Skip to content

Commit afb47e9

Browse files
Hello71Seth Schoen
authored andcommitted
Update makecrx.sh, utils/*.py for Python3 with 2to3
1 parent d569aea commit afb47e9

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

makecrx.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [ -n "$1" ]; then
3232
fi
3333
fi
3434

35-
VERSION=`python -c "import json ; print json.loads(open('chromium/manifest.json').read())['version']"`
35+
VERSION=`python -c "import json ; print(json.loads(open('chromium/manifest.json').read())['version'])"`
3636

3737
echo "Building chrome version" $VERSION
3838

utils/check_certs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
for fname in sys.argv[1:]:
1212
hosts = host_targets.findall(open(fname).read())
1313
if not hosts:
14-
print "Could not find <target hosts> in " + fname
14+
print("Could not find <target hosts> in " + fname)
1515
continue
1616
successes = []
1717
failures = []
@@ -26,15 +26,15 @@
2626
else:
2727
successes.append(h)
2828
if successes and not failures:
29-
print fname + " no cert warnings"
29+
print(fname + " no cert warnings")
3030
elif failures and not successes:
31-
print fname + " categorical failure:"
31+
print(fname + " categorical failure:")
3232
for f in failures:
33-
print " " + f
33+
print(" " + f)
3434
else:
35-
print fname + " mixed results:"
35+
print(fname + " mixed results:")
3636
for s in successes:
37-
print " " + s + " is OK"
37+
print(" " + s + " is OK")
3838
for f in failures:
39-
print " " + f
39+
print(" " + f)
4040

utils/chromium-preloads.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# autogenerate sample versions of rules from Chromium browser's HSTS
44
# preload list (in the from-preloads/ directory)
55

6-
import urllib2, re, glob, os
7-
preloads = urllib2.urlopen("https://src.chromium.org/viewvc/chrome/trunk/src/net/http/transport_security_state_static.h?content-type=text%2Fplain").read()
6+
import urllib.request, urllib.error, urllib.parse, re, glob, os
7+
preloads = urllib.request.urlopen("https://src.chromium.org/viewvc/chrome/trunk/src/net/http/transport_security_state_static.h?content-type=text%2Fplain").read()
88

99
def escape(s):
1010
return re.sub("\.", "\\.", s)
@@ -37,7 +37,7 @@ def make_rule(name, hosts):
3737
open("from-preloads/%s.xml" % name.capitalize(), "w").write(output)
3838

3939
t = re.compile('", true')
40-
preloads = filter(t.search,preloads.split("\n"))
40+
preloads = list(filter(t.search,preloads.split("\n")))
4141

4242
preloads = [x.split('"')[1] for x in preloads]
4343
preloads = [re.sub('\\\\[0-9]*', '.', x) for x in preloads]
@@ -48,7 +48,7 @@ def make_rule(name, hosts):
4848
d = {}
4949
for x in preloads:
5050
if any(map(re.compile(x).search, rules)):
51-
print "Ignored existing domain", x
51+
print("Ignored existing domain", x)
5252
continue
5353
domain = ".".join(x.split(".")[-2:])
5454
d.setdefault(domain, []).append(x)
@@ -59,4 +59,4 @@ def make_rule(name, hosts):
5959
for k in d:
6060
make_rule(k, d[k])
6161

62-
print "Please examine %d new rules in from-preloads/ directory." % len(d)
62+
print("Please examine %d new rules in from-preloads/ directory." % len(d))

utils/merge-rulesets.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
# cleanup after bugs :/
2121
misfile = rulesets_fn + "r"
2222
if os.path.exists(misfile):
23-
print "Cleaning up malformed rulesets file..."
23+
print("Cleaning up malformed rulesets file...")
2424
os.unlink(misfile)
2525

26-
print "Creating ruleset library..."
26+
print("Creating ruleset library...")
2727

2828
# Under git bash, sed -i issues errors and sets the file "read only". Thanks.
2929
if os.path.isfile(rulesets_fn):
@@ -50,7 +50,7 @@
5050
library.write("</rulesetlibrary>\n")
5151
library.close()
5252

53-
print "Removing whitespaces and comments..."
53+
print("Removing whitespaces and comments...")
5454

5555
def rulesize():
5656
return len(open(rulesets_fn).read())
@@ -60,18 +60,18 @@ def rulesize():
6060
call(sedcmd + [r"s/<!--.*?-->//g;/<!--/N;//ba", rulesets_fn])
6161
call(["sed", "-i", r":a;N;$!ba;s/\n//g;s/>[ ]*</></g;s/[ ]*to=/ to=/g;s/[ ]*from=/ from=/g;s/ \/>/\/>/g", rulesets_fn])
6262
call(["sed", "-i", r"s/<\/ruleset>/<\/ruleset>\n/g", rulesets_fn])
63-
print "Crushed", crush, "bytes of rulesets into", rulesize()
63+
print(("Crushed", crush, "bytes of rulesets into", rulesize()))
6464

6565
try:
6666
if 0 == call(["xmllint", "--noout", rulesets_fn]):
67-
print rulesets_fn, "passed XML validity test."
67+
print((rulesets_fn, "passed XML validity test."))
6868
else:
69-
print "ERROR:", rulesets_fn, "failed XML validity test!"
69+
print(("ERROR:", rulesets_fn, "failed XML validity test!"))
7070
sys.exit(1)
71-
except OSError, e:
71+
except OSError as e:
7272
if "No such file or directory" not in traceback.format_exc():
7373
raise
74-
print "WARNING: xmllint not present; validation of", rulesets_fn, " skipped."
74+
print(("WARNING: xmllint not present; validation of", rulesets_fn, " skipped."))
7575

7676
# We make default.rulesets at build time, but it shouldn't have a variable
7777
# timestamp

utils/mk_client_whitelist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
sys.stderr.write("TOP 100:\n")
3434
for n in range(100):
35-
sys.stderr.write(`results[n][1:4]` + '\n')
35+
sys.stderr.write(repr(results[n][1:4]) + '\n')
3636

3737
header = """
3838
// These are SHA256 fingerprints for the most common chains observed by the
@@ -41,11 +41,11 @@
4141
4242
const X509ChainWhitelist = {"""
4343

44-
print header
44+
print(header)
4545
for chain_fp in sorted([row[0] for row in results]):
46-
print " '%s' : true," % chain_fp
46+
print(" '%s' : true," % chain_fp)
4747

4848
footer = "} ;"
49-
print footer
49+
print(footer)
5050

5151

utils/trivial-response.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
if tree.xpath('/ruleset/@default_off'):
4040
default_off += 1
4141
continue
42-
except Exception, e:
42+
except Exception as e:
4343
continue
4444

4545
proc = subprocess.Popen([rule_script, fil, rule_file %
@@ -48,12 +48,12 @@
4848

4949
for (proc, f) in procs:
5050
proc.poll()
51-
print "POLL'D"
51+
print("POLL'D")
5252
if proc.returncode != None:
53-
print "FUCKED"
53+
print("FUCKED")
5454
with open(rule_file % f, 'r') as rule_fd:
5555
with open(report_file, 'a') as report_fd:
56-
print "CONTEXT"
56+
print("CONTEXT")
5757
report_fd.writelines(rule_fd)
5858
os.unlink(rule_file % f)
5959
procs.remove((proc, f))

utils/trivial-validate.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ def test_unencrypted_to(tree):
105105
if to[:6] != "https:" and to[:5] != "http:":
106106
return False
107107
elif to[:5] == "http:" and downgrade:
108-
sys.stdout.write("warning: downgrade rule in %s redirects " % fi)
109-
sys.stdout.write("to http.\n")
108+
sys.stdout.write("warning: downgrade rule in %s redirects " % fi)
109+
sys.stdout.write("to http.\n")
110110
elif to[:5] == "http:":
111-
sys.stdout.write("error: rule in %s redirects to http and " % fi)
112-
sys.stdout.write("downgrade attribute not specified.\n")
111+
sys.stdout.write("error: rule in %s redirects to http and " % fi)
112+
sys.stdout.write("downgrade attribute not specified.\n")
113113
return False
114114
return True
115115

@@ -153,7 +153,7 @@ def test_duplicated_target_host(tree):
153153
targets = tree.xpath("/ruleset/target/@host")
154154
return len(set(targets)) == len(targets)
155155

156-
printable_characters = set(map(chr, xrange(32, 127)))
156+
printable_characters = set(map(chr, list(range(32, 127))))
157157

158158
def test_non_ascii(tree):
159159
# Rules containing non-printable characters.
@@ -199,7 +199,7 @@ def get_all_names_and_targets(d):
199199
else:
200200
continue
201201
seen_file = True
202-
except Exception, oops:
202+
except Exception as oops:
203203
if fi[-4:] != ".xml":
204204
continue
205205
failure = 1
@@ -231,7 +231,7 @@ def get_all_names_and_targets(d):
231231
if tree.xpath("/ruleset"):
232232
sys.stdout.write("warning: ruleset in file without .xml extension: %s\n" % fi)
233233
seen_file = True
234-
except Exception, oops:
234+
except Exception as oops:
235235
failure = 1
236236
sys.stdout.write("%s failed XML validity: %s\n" % (fi, oops))
237237
ruleset_name = tree.xpath("/ruleset/@name")[0]

0 commit comments

Comments
 (0)