Skip to content

Commit c36228f

Browse files
Rollup merge of rust-lang#46044 - collinanderson:py3, r=kennytm
fix some python3 incompatibilities
2 parents cdadb6c + 261d4d8 commit c36228f

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

src/etc/indenter

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ while True:
1313
if more_re.match(line):
1414
indent += 1
1515

16-
print "%03d %s%s" % (indent, " " * indent, line.strip())
16+
print("%03d %s%s" % (indent, " " * indent, line.strip()))
1717

1818
if less_re.match(line):
1919
indent -= 1

src/etc/sugarise-doc-comments.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def block_trim(s):
5050
lns = lns[:-1]
5151

5252
# remove leading horizontal whitespace
53-
n = sys.maxint
53+
n = sys.maxsize
5454
for ln in lns:
5555
if ln.strip():
5656
n = min(n, len(re.search('^\s*', ln).group()))
57-
if n != sys.maxint:
57+
if n != sys.maxsize:
5858
lns = [ln[n:] for ln in lns]
5959

6060
# strip trailing whitespace

src/etc/test-float-parse/runtests.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,15 @@
9797
from subprocess import Popen, check_call, PIPE
9898
from glob import glob
9999
import multiprocessing
100-
import Queue
101100
import threading
102101
import ctypes
103102
import binascii
104103

104+
try: # Python 3
105+
import queue as Queue
106+
except ImportError: # Python 2
107+
import Queue
108+
105109
NUM_WORKERS = 2
106110
UPDATE_EVERY_N = 50000
107111
INF = namedtuple('INF', '')()

src/libstd_unicode/unicode.py

+17-20
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def load_unicode_data(f):
8989
if is_surrogate(cp):
9090
continue
9191
if range_start >= 0:
92-
for i in xrange(range_start, cp):
92+
for i in range(range_start, cp):
9393
udict[i] = data
9494
range_start = -1
9595
if data[1].endswith(", First>"):
@@ -382,7 +382,7 @@ def compute_trie(rawdata, chunksize):
382382
root = []
383383
childmap = {}
384384
child_data = []
385-
for i in range(len(rawdata) / chunksize):
385+
for i in range(len(rawdata) // chunksize):
386386
data = rawdata[i * chunksize: (i + 1) * chunksize]
387387
child = '|'.join(map(str, data))
388388
if child not in childmap:
@@ -400,7 +400,7 @@ def emit_bool_trie(f, name, t_data, is_pub=True):
400400

401401
# convert to bitmap chunks of 64 bits each
402402
chunks = []
403-
for i in range(0x110000 / CHUNK):
403+
for i in range(0x110000 // CHUNK):
404404
chunk = 0
405405
for j in range(64):
406406
if rawdata[i * 64 + j]:
@@ -412,12 +412,12 @@ def emit_bool_trie(f, name, t_data, is_pub=True):
412412
pub_string = "pub "
413413
f.write(" %sconst %s: &'static super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name))
414414
f.write(" r1: [\n")
415-
data = ','.join('0x%016x' % chunk for chunk in chunks[0:0x800 / CHUNK])
415+
data = ','.join('0x%016x' % chunk for chunk in chunks[0:0x800 // CHUNK])
416416
format_table_content(f, data, 12)
417417
f.write("\n ],\n")
418418

419419
# 0x800..0x10000 trie
420-
(r2, r3) = compute_trie(chunks[0x800 / CHUNK : 0x10000 / CHUNK], 64 / CHUNK)
420+
(r2, r3) = compute_trie(chunks[0x800 // CHUNK : 0x10000 // CHUNK], 64 // CHUNK)
421421
f.write(" r2: [\n")
422422
data = ','.join(str(node) for node in r2)
423423
format_table_content(f, data, 12)
@@ -428,7 +428,7 @@ def emit_bool_trie(f, name, t_data, is_pub=True):
428428
f.write("\n ],\n")
429429

430430
# 0x10000..0x110000 trie
431-
(mid, r6) = compute_trie(chunks[0x10000 / CHUNK : 0x110000 / CHUNK], 64 / CHUNK)
431+
(mid, r6) = compute_trie(chunks[0x10000 // CHUNK : 0x110000 // CHUNK], 64 // CHUNK)
432432
(r4, r5) = compute_trie(mid, 64)
433433
f.write(" r4: [\n")
434434
data = ','.join(str(node) for node in r4)
@@ -446,14 +446,14 @@ def emit_bool_trie(f, name, t_data, is_pub=True):
446446
f.write(" };\n\n")
447447

448448
def emit_small_bool_trie(f, name, t_data, is_pub=True):
449-
last_chunk = max(int(hi / 64) for (lo, hi) in t_data)
449+
last_chunk = max(hi // 64 for (lo, hi) in t_data)
450450
n_chunks = last_chunk + 1
451451
chunks = [0] * n_chunks
452452
for (lo, hi) in t_data:
453453
for cp in range(lo, hi + 1):
454-
if int(cp / 64) >= len(chunks):
455-
print(cp, int(cp / 64), len(chunks), lo, hi)
456-
chunks[int(cp / 64)] |= 1 << (cp & 63)
454+
if cp // 64 >= len(chunks):
455+
print(cp, cp // 64, len(chunks), lo, hi)
456+
chunks[cp // 64] |= 1 << (cp & 63)
457457

458458
pub_string = ""
459459
if is_pub:
@@ -519,32 +519,29 @@ def emit_conversions_module(f, to_upper, to_lower, to_title):
519519
pfun = lambda x: "(%s,[%s,%s,%s])" % (
520520
escape_char(x[0]), escape_char(x[1][0]), escape_char(x[1][1]), escape_char(x[1][2]))
521521
emit_table(f, "to_lowercase_table",
522-
sorted(to_lower.iteritems(), key=operator.itemgetter(0)),
522+
sorted(to_lower.items(), key=operator.itemgetter(0)),
523523
is_pub=False, t_type = t_type, pfun=pfun)
524524
emit_table(f, "to_uppercase_table",
525-
sorted(to_upper.iteritems(), key=operator.itemgetter(0)),
525+
sorted(to_upper.items(), key=operator.itemgetter(0)),
526526
is_pub=False, t_type = t_type, pfun=pfun)
527527
f.write("}\n\n")
528528

529529
def emit_norm_module(f, canon, compat, combine, norm_props):
530-
canon_keys = canon.keys()
531-
canon_keys.sort()
530+
canon_keys = sorted(canon.keys())
532531

533-
compat_keys = compat.keys()
534-
compat_keys.sort()
532+
compat_keys = sorted(compat.keys())
535533

536534
canon_comp = {}
537535
comp_exclusions = norm_props["Full_Composition_Exclusion"]
538536
for char in canon_keys:
539-
if True in map(lambda (lo, hi): lo <= char <= hi, comp_exclusions):
537+
if any(lo <= char <= hi for lo, hi in comp_exclusions):
540538
continue
541539
decomp = canon[char]
542540
if len(decomp) == 2:
543-
if not canon_comp.has_key(decomp[0]):
541+
if decomp[0] not in canon_comp:
544542
canon_comp[decomp[0]] = []
545543
canon_comp[decomp[0]].append( (decomp[1], char) )
546-
canon_comp_keys = canon_comp.keys()
547-
canon_comp_keys.sort()
544+
canon_comp_keys = sorted(canon_comp.keys())
548545

549546
if __name__ == "__main__":
550547
r = "tables.rs"

0 commit comments

Comments
 (0)