Skip to content

Commit 1f61c89

Browse files
cclaussBethGriggs
cclauss
authored andcommitted
tools: prepare tools/icu/icutrim.py for Python 3
PR-URL: #24888 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent e140d41 commit 1f61c89

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tools/icu/icutrim.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@
1212
# Use "-h" to get help options.
1313

1414
from __future__ import print_function
15-
import sys
16-
import shutil
17-
# for utf-8
18-
reload(sys)
19-
sys.setdefaultencoding("utf-8")
2015

16+
import json
2117
import optparse
2218
import os
23-
import json
2419
import re
20+
import shutil
21+
import sys
22+
23+
try:
24+
# for utf-8 on Python 2
25+
reload(sys)
26+
sys.setdefaultencoding("utf-8")
27+
except NameError:
28+
pass # Python 3 already defaults to utf-8
29+
30+
try:
31+
basestring # Python 2
32+
except NameError:
33+
basestring = str # Python 3
2534

2635
endian=sys.byteorder
2736

@@ -214,7 +223,7 @@ def queueForRemoval(tree):
214223
if(options.verbose>0):
215224
print("* %s: %d items" % (tree, len(mytree["locs"])))
216225
# do varible substitution for this tree here
217-
if type(config["trees"][tree]) == str or type(config["trees"][tree]) == unicode:
226+
if isinstance(config["trees"][tree], basestring):
218227
treeStr = config["trees"][tree]
219228
if(options.verbose>5):
220229
print(" Substituting $%s for tree %s" % (treeStr, tree))

0 commit comments

Comments
 (0)