Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #31650 right use of string and bytes objects #31659

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 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,10 +285,9 @@ 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, 'rb')
treeitems = fi.readlines()
trees[tree]["locs"] = [treeitems[i].strip() for i in range(len(treeitems))]
fi.close()
with io.open(treelistfile, 'r', encoding='utf-8') as fi:
treeitems = fi.readlines()
trees[tree]["locs"] = [line.strip() for line in treeitems]
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:
Expand Down Expand Up @@ -317,12 +316,12 @@ 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("""^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)
if m:
toDelete = m.group(1)
toDelete = m.group(1).decode("utf-8")
if(options.verbose > 5):
print("<< %s added to delete" % toDelete)
remove.add(toDelete)
Expand Down