Skip to content

Commit 91a96e4

Browse files
cclaussBethGriggs
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 34212b5 commit 91a96e4

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

‎tools/icu/icutrim.py‎

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

1414
from __future__ importprint_function
15-
importsys
16-
importshutil
17-
# for utf-8
18-
reload(sys)
19-
sys.setdefaultencoding("utf-8")
2015

16+
importjson
2117
importoptparse
2218
importos
23-
importjson
2419
importre
20+
importshutil
21+
importsys
22+
23+
try:
24+
# for utf-8 on Python 2
25+
reload(sys)
26+
sys.setdefaultencoding("utf-8")
27+
exceptNameError:
28+
pass# Python 3 already defaults to utf-8
29+
30+
try:
31+
basestring# Python 2
32+
exceptNameError:
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-
iftype(config["trees"][tree]) ==strortype(config["trees"][tree]) ==unicode:
226+
ifisinstance(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)