Commit b99dd264 authored by Michal Čihař's avatar Michal Čihař

Open all files in binary mode

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 58ff601c
...@@ -727,7 +727,7 @@ class FileFormat(object): ...@@ -727,7 +727,7 @@ class FileFormat(object):
if cls.new_translation is None: if cls.new_translation is None:
raise ValueError('Not supported') raise ValueError('Not supported')
with open(filename, 'w') as output: with open(filename, 'wb') as output:
output.write(cls.new_translation) output.write(cls.new_translation)
def iterate_merge(self, fuzzy): def iterate_merge(self, fuzzy):
...@@ -1106,12 +1106,12 @@ class PhpFormat(FileFormat): ...@@ -1106,12 +1106,12 @@ class PhpFormat(FileFormat):
This is workaround for .save() not working as intended in This is workaround for .save() not working as intended in
translate-toolkit. translate-toolkit.
''' '''
with open(self.store.filename, 'r') as handle: with open(self.store.filename, 'rb') as handle:
convertor = po2php.rephp(handle, self.store) convertor = po2php.rephp(handle, self.store)
outputphplines = convertor.convertstore(False) outputphplines = convertor.convertstore(False)
with open(self.store.filename, 'w') as handle: with open(self.store.filename, 'wb') as handle:
handle.writelines(outputphplines) handle.writelines(outputphplines)
...@@ -1177,9 +1177,9 @@ class JSONFormat(FileFormat): ...@@ -1177,9 +1177,9 @@ class JSONFormat(FileFormat):
"""Handles creation of new translation file.""" """Handles creation of new translation file."""
content = '{}\n' content = '{}\n'
if base: if base:
with open(base, 'r') as handle: with open(base, 'rb') as handle:
content = handle.read() content = handle.read()
with open(filename, 'w') as output: with open(filename, 'wb') as output:
output.write(content) output.write(content)
@property @property
...@@ -1228,7 +1228,7 @@ class CSVFormat(FileFormat): ...@@ -1228,7 +1228,7 @@ class CSVFormat(FileFormat):
# Did we get file or filename? # Did we get file or filename?
if not hasattr(storefile, 'read'): if not hasattr(storefile, 'read'):
storefile = open(storefile, 'r') storefile = open(storefile, 'rb')
# Read content for fixups # Read content for fixups
content = storefile.read() content = storefile.read()
...@@ -1283,7 +1283,7 @@ class CSVSimpleFormat(CSVFormat): ...@@ -1283,7 +1283,7 @@ class CSVSimpleFormat(CSVFormat):
# Did we get file or filename? # Did we get file or filename?
if not hasattr(storefile, 'read'): if not hasattr(storefile, 'read'):
storefile = open(storefile, 'r') storefile = open(storefile, 'rb')
result = storeclass( result = storeclass(
fieldnames=['source', 'target'], fieldnames=['source', 'target'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment