|
14 | 14 | # |
15 | 15 | ############################################################################# |
16 | 16 |
|
| 17 | +from __future__ import annotations |
| 18 | + |
17 | 19 | import codecs |
18 | 20 | import glob |
19 | 21 | import json |
@@ -72,13 +74,14 @@ def read_msgfmt_statistics(msg, lgood, lfuzzy, lbad): |
72 | 74 | return langdict, lgood, lfuzzy, lbad |
73 | 75 |
|
74 | 76 |
|
75 | | -def langDefinition(fil): |
76 | | - f = codecs.open(fil, encoding="utf-8", errors="replace", mode="r") |
77 | | - for line in f.readlines(): |
78 | | - if '"Language-Team:' in line: |
79 | | - lang = line.split(" ")[1:-1] |
80 | | - break |
81 | | - f.close() |
| 77 | +def langDefinition(fil: str) -> str: |
| 78 | + lang: str | list[str] = "" |
| 79 | + with codecs.open(fil, encoding="utf-8", errors="replace", mode="r") as f: |
| 80 | + for line in f.readlines(): |
| 81 | + if '"Language-Team:' in line: |
| 82 | + lang = line.split(" ")[1:-1] |
| 83 | + break |
| 84 | + |
82 | 85 | if len(lang) == 2: |
83 | 86 | return " ".join(lang) |
84 | 87 | if len(lang) == 1: |
@@ -139,10 +142,9 @@ def writejson(stats, outfile): |
139 | 142 | # write a string with pretty style |
140 | 143 | outjson = os.linesep.join([line.rstrip() for line in fjson.splitlines()]) |
141 | 144 | # write out file |
142 | | - fout = open(outfile, "w") |
143 | | - fout.write(outjson) |
144 | | - fout.write(os.linesep) |
145 | | - fout.close() |
| 145 | + with open(outfile, "w", encoding="utf-8") as fout: |
| 146 | + fout.write(outjson) |
| 147 | + fout.write(os.linesep) |
146 | 148 | try: |
147 | 149 | os.remove("messages.mo") |
148 | 150 | except OSError: |
|
0 commit comments