From: Alex Morega Date: Sun, 7 Jul 2013 08:57:12 +0000 (+0200) Subject: open po files in binary mode X-Git-Tag: 1.0~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bcbab276346d3555ff9917cf25ee6d1ed352967;p=thirdparty%2Fbabel.git open po files in binary mode --- diff --git a/babel/messages/extract.py b/babel/messages/extract.py index c9e01dd9..1e99ce26 100644 --- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -194,7 +194,7 @@ def extract_from_file(method, filename, keywords=DEFAULT_KEYWORDS, :return: the list of extracted messages :rtype: `list` """ - fileobj = open(filename, 'U') + fileobj = open(filename, 'rb') try: return list(extract(method, fileobj, keywords, comment_tags, options, strip_comment_tags)) diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index 59c4b55d..665f3dd6 100755 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -291,7 +291,7 @@ class extract_messages(Command): def run(self): mappings = self._get_mappings() - outfile = open(self.output_file, 'w') + outfile = open(self.output_file, 'wb') try: catalog = Catalog(project=self.distribution.get_name(), version=self.distribution.get_version(), @@ -470,7 +470,7 @@ class init_catalog(Command): catalog.revision_date = datetime.now(LOCALTZ) catalog.fuzzy = False - outfile = open(self.output_file, 'w') + outfile = open(self.output_file, 'wb') try: write_po(outfile, catalog, width=self.width) finally: @@ -944,7 +944,7 @@ class CommandLineInterface(object): if options.output not in (None, '-'): self.log.info('writing PO template file to %s' % options.output) - outfile = open(options.output, 'w') + outfile = open(options.output, 'wb') close_output = True else: outfile = sys.stdout @@ -1028,7 +1028,7 @@ class CommandLineInterface(object): self.log.info('creating catalog %r based on %r', options.output_file, options.input_file) - outfile = open(options.output_file, 'w') + outfile = open(options.output_file, 'wb') try: write_po(outfile, catalog, width=options.width) finally: diff --git a/tests/messages/test_frontend.py b/tests/messages/test_frontend.py index 7f763427..882cb00d 100644 --- a/tests/messages/test_frontend.py +++ b/tests/messages/test_frontend.py @@ -543,11 +543,11 @@ msgstr[0] "" long_message = '"'+ 'xxxxx '*15 + '"' - with open('project/i18n/messages.pot', 'U') as f: - pot_contents = f.read() + with open('project/i18n/messages.pot', 'rb') as f: + pot_contents = f.read().decode('latin-1') pot_with_very_long_line = pot_contents.replace('"bar"', long_message) with open(self.cmd.input_file, 'wb') as f: - f.write(pot_with_very_long_line) + f.write(pot_with_very_long_line.encode('latin-1')) self.cmd.no_wrap = True self.cmd.finalize_options() @@ -602,11 +602,11 @@ msgstr[1] "" long_message = '"'+ 'xxxxx '*15 + '"' - with open('project/i18n/messages.pot', 'U') as f: - pot_contents = f.read() + with open('project/i18n/messages.pot', 'rb') as f: + pot_contents = f.read().decode('latin-1') pot_with_very_long_line = pot_contents.replace('"bar"', long_message) with open(self.cmd.input_file, 'wb') as f: - f.write(pot_with_very_long_line) + f.write(pot_with_very_long_line.encode('latin-1')) self.cmd.width = 120 self.cmd.finalize_options() self.cmd.run()