From: Aarni Koskela Date: Mon, 28 May 2018 09:34:31 +0000 (+0300) Subject: frontend, test_frontend: don't use deprecated U read mode on Py3 X-Git-Tag: v2.6.0~2^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3471306e9cd08214d12e6e4af81d8b9dbcd70874;p=thirdparty%2Fbabel.git frontend, test_frontend: don't use deprecated U read mode on Py3 --- diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index d848f2df..31fbaa46 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -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)) diff --git a/tests/messages/test_frontend.py b/tests/messages/test_frontend.py index d2e9e35c..3e3cc8bd 100644 --- a/tests/messages/test_frontend.py +++ b/tests/messages/test_frontend.py @@ -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)