Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dedd219

Browse filesBrowse files
jmercier-lbiMylesBorins
authored andcommitted
tools: fixup icutrim.py use of string and bytes objects
PR-URL: #31659 Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent d2ce8e9 commit dedd219
Copy full SHA for dedd219

File tree

Expand file treeCollapse file tree

1 file changed

+8
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-9
lines changed
Open diff view settings
Collapse file

‎tools/icu/icutrim.py‎

Copy file name to clipboardExpand all lines: tools/icu/icutrim.py
+8-9Lines changed: 8 additions & 9 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,10 +285,9 @@ 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, 'rb')
289-
treeitems = fi.readlines()
290-
trees[tree]["locs"] = [treeitems[i].strip() for i in range(len(treeitems))]
291-
fi.close()
288+
with io.open(treelistfile, 'r', encoding='utf-8') as fi:
289+
treeitems = fi.readlines()
290+
trees[tree]["locs"] = [line.strip() for line in treeitems]
292291
if tree not in config.get("trees", {}):
293292
print(" Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options.filterfile, tree))
294293
else:
@@ -317,12 +316,12 @@ def removeList(count=0):
317316
erritems = fi.readlines()
318317
fi.close()
319318
#Item zone/zh_Hant_TW.res depends on missing item zone/zh_Hant.res
320-
pat = re.compile("""^Item ([^ ]+) depends on missing item ([^ ]+).*""")
319+
pat = re.compile(bytes(r"^Item ([^ ]+) depends on missing item ([^ ]+).*", 'utf-8'))
321320
for i in range(len(erritems)):
322321
line = erritems[i].strip()
323322
m = pat.match(line)
324323
if m:
325-
toDelete = m.group(1)
324+
toDelete = m.group(1).decode("utf-8")
326325
if(options.verbose > 5):
327326
print("<< %s added to delete" % toDelete)
328327
remove.add(toDelete)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.