From: Armin Ronacher Date: Sat, 6 Jul 2013 14:57:29 +0000 (+0200) Subject: Resolved a bunch of syntax errors X-Git-Tag: 1.0~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ec1963d292bdbcc3c43e2684134ae4670833e61;p=thirdparty%2Fbabel.git Resolved a bunch of syntax errors --- diff --git a/babel/messages/checkers.py b/babel/messages/checkers.py index 86dc5bb7..fe8ab3a5 100644 --- a/babel/messages/checkers.py +++ b/babel/messages/checkers.py @@ -16,9 +16,8 @@ :since: version 0.9 """ -from itertools import izip from babel.messages.catalog import TranslationError, PYTHON_FORMAT -from babel._compat import string_types +from babel._compat import string_types, izip #: list of format chars that are compatible to each other _string_format_compatibilities = [ diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index a0640eba..55acb95b 100755 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -14,7 +14,10 @@ """Frontends for the message extraction functionality.""" -from ConfigParser import RawConfigParser +try: + from ConfigParser import RawConfigParser +except ImportError: + from configparser import RawConfigParser from datetime import datetime from distutils import log from distutils.cmd import Command @@ -25,7 +28,6 @@ from optparse import OptionParser import os import re import shutil -from StringIO import StringIO import sys import tempfile @@ -38,7 +40,7 @@ from babel.messages.extract import extract_from_dir, DEFAULT_KEYWORDS, \ from babel.messages.mofile import write_mo from babel.messages.pofile import read_po, write_po from babel.util import odict, LOCALTZ -from babel._compat import string_types +from babel._compat import string_types, BytesIO __all__ = ['CommandLineInterface', 'compile_catalog', 'extract_messages', 'init_catalog', 'check_message_extractors', 'update_catalog'] @@ -344,7 +346,7 @@ class extract_messages(Command): message_extractors = self.distribution.message_extractors for dirname, mapping in message_extractors.items(): if isinstance(mapping, string_types): - method_map, options_map = parse_mapping(StringIO(mapping)) + method_map, options_map = parse_mapping(BytesIO(mapping)) else: method_map, options_map = [], {} for pattern, method, options in mapping: @@ -433,7 +435,7 @@ class init_catalog(Command): 'new catalog') try: self._locale = Locale.parse(self.locale) - except UnknownLocaleError, e: + except UnknownLocaleError as e: raise DistutilsOptionError(e) if not self.output_file and not self.output_dir: @@ -668,9 +670,9 @@ class CommandLineInterface(object): for identifier in identifiers: locale = Locale.parse(identifier) output = format % (identifier, locale.english_name) - print output.encode(sys.stdout.encoding or + print(output.encode(sys.stdout.encoding or getpreferredencoding() or - 'ascii', 'replace') + 'ascii', 'replace')) return 0 if not args: @@ -699,14 +701,14 @@ class CommandLineInterface(object): handler.setFormatter(formatter) def _help(self): - print self.parser.format_help() - print "commands:" + print(self.parser.format_help()) + print("commands:") longest = max([len(command) for command in self.commands]) format = " %%-%ds %%s" % max(8, longest + 1) commands = self.commands.items() commands.sort() for name, description in commands: - print format % (name, description) + print(format % (name, description)) def compile(self, argv): """Subcommand for compiling a message catalog to a MO file. @@ -992,7 +994,7 @@ class CommandLineInterface(object): parser.error('you must provide a locale for the new catalog') try: locale = Locale.parse(options.locale) - except UnknownLocaleError, e: + except UnknownLocaleError as e: parser.error(e) if not options.input_file: @@ -1162,7 +1164,7 @@ def main(): def parse_mapping(fileobj, filename=None): """Parse an extraction method mapping from a file-like object. - >>> buf = StringIO(''' + >>> buf = BytesIO(b''' ... [extractors] ... custom = mypackage.module:myfunc ... diff --git a/tests/messages/test_checkers.py b/tests/messages/test_checkers.py index 4eb4cc9d..218b442c 100644 --- a/tests/messages/test_checkers.py +++ b/tests/messages/test_checkers.py @@ -14,7 +14,6 @@ from datetime import datetime import time import unittest -from StringIO import StringIO from babel import __version__ as VERSION from babel.core import Locale, UnknownLocaleError @@ -23,6 +22,7 @@ from babel.messages import checkers from babel.messages.plurals import PLURALS from babel.messages.pofile import read_po from babel.util import LOCALTZ +from babel._compat import StringIO class CheckersTestCase(unittest.TestCase): @@ -102,7 +102,7 @@ msgstr[0] "" except UnknownLocaleError: # Just an alias? Not what we're testing here, let's continue continue - po_file = (ur"""\ + po_file = (u"""\ # %(english_name)s translations for TestProject. # Copyright (C) 2007 FooBar, Inc. # This file is distributed under the same license as the TestProject @@ -111,17 +111,17 @@ msgstr[0] "" # msgid "" msgstr "" -"Project-Id-Version: TestProject 0.1\n" -"Report-Msgid-Bugs-To: bugs.address@email.tld\n" -"POT-Creation-Date: 2007-04-01 15:30+0200\n" -"PO-Revision-Date: %(date)s\n" -"Last-Translator: FULL NAME \n" -"Language-Team: %(locale)s \n" -"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel %(version)s\n" +"Project-Id-Version: TestProject 0.1\\n" +"Report-Msgid-Bugs-To: bugs.address@email.tld\\n" +"POT-Creation-Date: 2007-04-01 15:30+0200\\n" +"PO-Revision-Date: %(date)s\\n" +"Last-Translator: FULL NAME \\n" +"Language-Team: %(locale)s \\n" +"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s\\n" +"MIME-Version: 1.0\\n" +"Content-Type: text/plain; charset=utf-8\\n" +"Content-Transfer-Encoding: 8bit\\n" +"Generated-By: Babel %(version)s\\n" #. This will be a translator comment, #. that will include several lines diff --git a/tests/messages/test_extract.py b/tests/messages/test_extract.py index 569b4839..7e587f9d 100644 --- a/tests/messages/test_extract.py +++ b/tests/messages/test_extract.py @@ -316,38 +316,38 @@ n = ngettext('foo') self.assertEqual(('foo'), messages[5][2]) def test_utf8_message(self): - buf = BytesIO(b""" + buf = BytesIO(u""" # NOTE: hello msg = _('Bonjour à tous') -""") +""".encode('utf-8')) messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {'encoding': 'utf-8'})) self.assertEqual(u'Bonjour à tous', messages[0][2]) self.assertEqual([u'NOTE: hello'], messages[0][3]) def test_utf8_message_with_magic_comment(self): - buf = BytesIO(b"""# -*- coding: utf-8 -*- + buf = BytesIO(u"""# -*- coding: utf-8 -*- # NOTE: hello msg = _('Bonjour à tous') -""") +""".encode('utf-8')) messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) self.assertEqual(u'Bonjour à tous', messages[0][2]) self.assertEqual([u'NOTE: hello'], messages[0][3]) def test_utf8_message_with_utf8_bom(self): - buf = StringIO(codecs.BOM_UTF8 + """ + buf = StringIO(codecs.BOM_UTF8 + u""" # NOTE: hello msg = _('Bonjour à tous') -""") +""".encode('utf-8')) messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) self.assertEqual(u'Bonjour à tous', messages[0][2]) self.assertEqual([u'NOTE: hello'], messages[0][3]) def test_utf8_raw_strings_match_unicode_strings(self): - buf = StringIO(codecs.BOM_UTF8 + """ + buf = StringIO(codecs.BOM_UTF8 + u""" msg = _('Bonjour à tous') msgu = _(u'Bonjour à tous') -""") +""".encode('utf-8')) messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) self.assertEqual(u'Bonjour à tous', messages[0][2]) self.assertEqual(messages[0][2], messages[1][2]) @@ -408,21 +408,21 @@ msg10 = dngettext(domain, 'Page', 'Pages', 3) (10, (u'Page', u'Pages'), [], None)], messages) def test_message_with_line_comment(self): - buf = BytesIO(b"""\ + buf = BytesIO(u"""\ // NOTE: hello msg = _('Bonjour à tous') -""") +""".encode('utf-8')) messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {})) self.assertEqual(u'Bonjour à tous', messages[0][2]) self.assertEqual([u'NOTE: hello'], messages[0][3]) def test_message_with_multiline_comment(self): - buf = BytesIO(b"""\ + buf = BytesIO(u"""\ /* NOTE: hello and bonjour and servus */ msg = _('Bonjour à tous') -""") +""".encode('utf-8')) messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {})) self.assertEqual(u'Bonjour à tous', messages[0][2]) self.assertEqual([u'NOTE: hello', 'and bonjour', ' and servus'], messages[0][3]) diff --git a/tests/messages/test_frontend.py b/tests/messages/test_frontend.py index 9cce4b72..7f763427 100644 --- a/tests/messages/test_frontend.py +++ b/tests/messages/test_frontend.py @@ -18,7 +18,6 @@ from distutils.log import _global_log import logging import os import shutil -from StringIO import StringIO import sys import time import unittest @@ -28,6 +27,7 @@ from babel.dates import format_datetime from babel.messages import frontend from babel.util import LOCALTZ from babel.messages.pofile import read_po +from babel._compat import StringIO this_dir = os.path.abspath(os.path.dirname(__file__)) diff --git a/tests/messages/test_mofile.py b/tests/messages/test_mofile.py index 6d15d0d1..835891d4 100644 --- a/tests/messages/test_mofile.py +++ b/tests/messages/test_mofile.py @@ -11,13 +11,12 @@ # individuals. For the exact contribution history, see the revision # history and logs, available at http://babel.edgewall.org/log/. -import doctest import gettext import os import unittest -from StringIO import StringIO from babel.messages import mofile, Catalog +from babel._compat import StringIO class ReadMoTestCase(unittest.TestCase): diff --git a/tests/messages/test_pofile.py b/tests/messages/test_pofile.py index 68e3d223..393785fe 100644 --- a/tests/messages/test_pofile.py +++ b/tests/messages/test_pofile.py @@ -12,14 +12,13 @@ # history and logs, available at http://babel.edgewall.org/log/. from datetime import datetime -import doctest -from StringIO import StringIO import unittest from babel.core import Locale from babel.messages.catalog import Catalog, Message from babel.messages import pofile from babel.util import FixedOffsetTimezone +from babel._compat import StringIO class ReadPoTestCase(unittest.TestCase):