Skip to content

Commit 4c49c50

Browse files
committed
use of io.open function
1 parent b2dbdc6 commit 4c49c50

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tools/icu/icutrim.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from __future__ import print_function
1515

16+
import io
1617
import json
1718
import optparse
1819
import os
@@ -159,9 +160,8 @@ def runcmd(tool, cmd, doContinue=False):
159160
return rc
160161

161162
## STEP 0 - read in json config
162-
fi= open(options.filterfile, "rb")
163-
config=json.load(fi)
164-
fi.close()
163+
with io.open(options.filterfile, encoding='utf-8') as fi:
164+
config=json.load(fi)
165165

166166
if options.locales:
167167
config["variables"] = config.get("variables", {})
@@ -285,14 +285,14 @@ def addTreeByType(tree, mytree):
285285
# read in the resource list for the tree
286286
treelistfile = os.path.join(options.tmpdir,"%s.lst" % tree)
287287
runcmd("iculslocs", "-i %s -N %s -T %s -l > %s" % (outfile, dataname, tree, treelistfile))
288-
fi = open(treelistfile, 'r')
289-
treeitems = fi.readlines()
290-
trees[tree]["locs"] = [treeitems[i].strip() for i in range(len(treeitems))]
291-
fi.close()
292-
if tree not in config.get("trees", {}):
293-
print(" Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options.filterfile, tree))
294-
else:
295-
queueForRemoval(tree)
288+
with io.open(treelistfile, 'r', encoding='utf-8') as fi:
289+
treeitems = fi.readlines()
290+
trees[tree]["locs"] = [treeitems[i].strip() for i in range(len(treeitems))]
291+
fi.close()
292+
if tree not in config.get("trees", {}):
293+
print(" Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options.filterfile, tree))
294+
else:
295+
queueForRemoval(tree)
296296

297297
def removeList(count=0):
298298
# don't allow "keep" items to creep in here.
@@ -317,7 +317,7 @@ def removeList(count=0):
317317
erritems = fi.readlines()
318318
fi.close()
319319
#Item zone/zh_Hant_TW.res depends on missing item zone/zh_Hant.res
320-
pat = re.compile(rb"^Item ([^ ]+) depends on missing item ([^ ]+).*")
320+
pat = re.compile(bytes(r"^Item ([^ ]+) depends on missing item ([^ ]+).*", 'utf-8'))
321321
for i in range(len(erritems)):
322322
line = erritems[i].strip()
323323
m = pat.match(line)

0 commit comments

Comments
 (0)