summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan MERCIER <jmercier@cng.fr>2020-02-06 11:47:08 +0100
committerJames M Snell <jasnell@gmail.com>2020-03-18 16:18:27 -0700
commit5f0af2af2a67216e00fe07ccda11e889d14abfcd (patch)
tree7206b60f90045e50781815fdf0593897c0a31085
parent509a184820ca91d6935213cb3008cb881d8a3a5d (diff)
downloadnode-new-5f0af2af2a67216e00fe07ccda11e889d14abfcd.tar.gz
tools: fixup icutrim.py use of string and bytes objects
PR-URL: https://github.com/nodejs/node/pull/31659 Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
-rwxr-xr-xtools/icu/icutrim.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/tools/icu/icutrim.py b/tools/icu/icutrim.py
index 25bd99d9cb..f857e73bbc 100755
--- a/tools/icu/icutrim.py
+++ b/tools/icu/icutrim.py
@@ -13,6 +13,7 @@
from __future__ import print_function
+import io
import json
import optparse
import os
@@ -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", {})
@@ -285,10 +285,9 @@ for i in range(len(items)):
# 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:
@@ -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)