Skip to content

Commit

Permalink
use of io.open function
Browse files Browse the repository at this point in the history
  • Loading branch information
jmercier-lbi committed Feb 26, 2020
1 parent b2dbdc6 commit 4c49c50
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tools/icu/icutrim.py
Expand Up @@ -13,6 +13,7 @@

from __future__ import print_function

import io
import json
import optparse
import os
Expand Down Expand Up @@ -159,9 +160,8 @@ def runcmd(tool, cmd, doContinue=False):
return rc

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

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

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

0 comments on commit 4c49c50

Please sign in to comment.