]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
frontend, test_frontend: don't use deprecated U read mode on Py3
authorAarni Koskela <akx@iki.fi>
Mon, 28 May 2018 09:34:31 +0000 (12:34 +0300)
committerAarni Koskela <akx@iki.fi>
Mon, 28 May 2018 10:01:40 +0000 (13:01 +0300)
babel/messages/frontend.py
tests/messages/test_frontend.py

index d848f2dfc1a4394b9d1bd4bcd6bbc340553566b9..31fbaa46b182d7d25e532e1acb69ba9a55457600 100644 (file)
@@ -22,7 +22,7 @@ from locale import getpreferredencoding
 
 from babel import __version__ as VERSION
 from babel import Locale, localedata
-from babel._compat import StringIO, string_types, text_type
+from babel._compat import StringIO, string_types, text_type, PY2
 from babel.core import UnknownLocaleError
 from babel.messages.catalog import Catalog
 from babel.messages.extract import DEFAULT_KEYWORDS, DEFAULT_MAPPING, check_and_call_extract_file, extract_from_dir
@@ -39,6 +39,9 @@ except ImportError:
     from configparser import RawConfigParser
 
 
+po_file_read_mode = ('rU' if PY2 else 'r')
+
+
 def listify_value(arg, split=None):
     """
     Make a list out of an argument.
@@ -485,7 +488,7 @@ class extract_messages(Command):
         mappings = []
 
         if self.mapping_file:
-            with open(self.mapping_file, 'U') as fileobj:
+            with open(self.mapping_file, po_file_read_mode) as fileobj:
                 method_map, options_map = parse_mapping(fileobj)
             for path in self.input_paths:
                 mappings.append((path, method_map, options_map))
index d2e9e35cf484b13845c113021e3223e97bdf18da..3e3cc8bd5f07aaafe5c24a959bb9b0fe4d86082f 100644 (file)
@@ -28,7 +28,7 @@ import pytest
 from babel import __version__ as VERSION
 from babel.dates import format_datetime
 from babel.messages import frontend, Catalog
-from babel.messages.frontend import CommandLineInterface, extract_messages, update_catalog
+from babel.messages.frontend import CommandLineInterface, extract_messages, update_catalog, po_file_read_mode
 from babel.util import LOCALTZ
 from babel.messages.pofile import read_po, write_po
 from babel._compat import StringIO
@@ -124,7 +124,7 @@ class ExtractMessagesTestCase(unittest.TestCase):
         self.cmd.finalize_options()
         self.cmd.run()
 
-        with open(self._pot_file(), 'U') as f:
+        with open(self._pot_file(), po_file_read_mode) as f:
             catalog = read_po(f)
         msg = catalog.get('bar')
         self.assertEqual(1, len(msg.locations))
@@ -204,7 +204,7 @@ msgstr[1] ""
             'year': time.strftime('%Y'),
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(self._pot_file(), 'U') as f:
+        with open(self._pot_file(), po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -257,7 +257,7 @@ msgstr[1] ""
             'year': time.strftime('%Y'),
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(self._pot_file(), 'U') as f:
+        with open(self._pot_file(), po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -315,7 +315,7 @@ msgstr[1] ""
             'year': time.strftime('%Y'),
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(self._pot_file(), 'U') as f:
+        with open(self._pot_file(), po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -346,7 +346,7 @@ msgstr[0] ""
 msgstr[1] ""
 
 """
-        with open(self._pot_file(), 'U') as f:
+        with open(self._pot_file(), po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -440,7 +440,7 @@ msgstr[1] ""
 """ % {'version': VERSION,
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -492,7 +492,7 @@ msgstr[1] ""
 """ % {'version': VERSION,
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -546,7 +546,7 @@ msgstr[2] ""
 """ % {'version': VERSION,
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -597,7 +597,7 @@ msgstr[0] ""
 """ % {'version': VERSION,
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='ja_JP')}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -658,7 +658,7 @@ msgstr[1] ""
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en_US'),
             'long_message': long_message}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -718,7 +718,7 @@ msgstr[1] ""
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en_US'),
             'long_message': long_message}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -879,7 +879,7 @@ msgstr[1] ""
             'year': time.strftime('%Y'),
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(pot_file, 'U') as f:
+        with open(pot_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -930,7 +930,7 @@ msgstr[1] ""
             'year': time.strftime('%Y'),
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(pot_file, 'U') as f:
+        with open(pot_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -979,7 +979,7 @@ msgstr[1] ""
             'year': time.strftime('%Y'),
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(pot_file, 'U') as f:
+        with open(pot_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -1027,7 +1027,7 @@ msgstr[1] ""
 """ % {'version': VERSION,
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -1077,7 +1077,7 @@ msgstr[0] ""
 """ % {'version': VERSION,
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)
 
@@ -1127,7 +1127,7 @@ msgstr[2] ""
 """ % {'version': VERSION,
             'date': format_datetime(datetime(1994, 11, 11, 00, 00), 'yyyy-MM-dd HH:mmZ',
                                     tzinfo=LOCALTZ, locale='en')}
-        with open(po_file, 'U') as f:
+        with open(po_file, po_file_read_mode) as f:
             actual_content = f.read()
         self.assertEqual(expected_content, actual_content)