]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
open po files in binary mode
authorAlex Morega <alex@grep.ro>
Sun, 7 Jul 2013 08:57:12 +0000 (10:57 +0200)
committerAlex Morega <alex@grep.ro>
Sun, 7 Jul 2013 08:57:12 +0000 (10:57 +0200)
babel/messages/extract.py
babel/messages/frontend.py
tests/messages/test_frontend.py

index c9e01dd93d708a0560eae23062955f43b6afaff1..1e99ce2603c1f821198026d014f876ddaa0a17d9 100644 (file)
@@ -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))
index 59c4b55d97fa8008423a675367aa5cd751124e44..665f3dd601d28164ae0f473779c2c174118b96cc 100755 (executable)
@@ -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:
index 7f76342756df501f96b4b7e258709d6ec5249294..882cb00d3c5b54556fed4fe0167a72b12a3fedb4 100644 (file)
@@ -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()