summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@frugalware.org>2011-10-03 23:16:59 +0200
committerMiklos Vajna <vmiklos@frugalware.org>2011-10-03 23:17:17 +0200
commitd92a87f19534105ee9c29ba5e509fd99c31c3611 (patch)
tree88cf568c15e777bc0205a3c849bb602966b4bd5e
parent8f8e9a4a4ccd01ce6c73588748861199d79adde9 (diff)
fdo#41380: fix po2lo to support python3 as well
-rwxr-xr-xl10ntools/scripts/po2lo15
1 files changed, 11 insertions, 4 deletions
diff --git a/l10ntools/scripts/po2lo b/l10ntools/scripts/po2lo
index 0f81ebc203e3..969f3eae0e95 100755
--- a/l10ntools/scripts/po2lo
+++ b/l10ntools/scripts/po2lo
@@ -78,7 +78,7 @@ class Template:
"""Represents a reference template in SDF format."""
def __init__(self, path):
- sock = open(path)
+ sock = xopen(path, "r", encoding='utf-8')
self.lines = []
for line in sock:
entry = Entry(line.split('\t'))
@@ -88,7 +88,7 @@ class Template:
def translate(self, translations):
"""Translates entires in the template based on translations."""
- sock = open(options.output, "w")
+ sock = xopen(options.output, "w", encoding='utf-8')
for line in self.lines:
line.translate(translations)
sock.write("\t".join(line.items)+"\r\n")
@@ -103,7 +103,7 @@ class Translations:
for root, dirs, files in os.walk(options.input):
for file in files:
path = "%s/%s" % (root, file)
- sock = open(path)
+ sock = xopen(path, "r", encoding='utf-8')
buf = []
multiline = False
fuzzy = False
@@ -166,6 +166,13 @@ class Translations:
text = text.replace(tag, escaped_tag)
return text
+def xopen(path, mode, encoding):
+ """Wrapper around open() to support both python2 and python3."""
+ if sys.version_info >= (3,):
+ return open(path, mode, encoding=encoding)
+ else:
+ return open(path, mode)
+
def main():
"""Main function of this script."""
@@ -193,7 +200,7 @@ options = Options()
# used by sdf2po()
normalfilenamechars = "/#.0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
normalizetable = ""
-for i in map(chr, range(256)):
+for i in map(chr, list(range(256))):
if i in normalfilenamechars:
normalizetable += i
else: