]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Resolved a bunch of syntax errors
authorArmin Ronacher <armin.ronacher@active-4.com>
Sat, 6 Jul 2013 14:57:29 +0000 (16:57 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sat, 6 Jul 2013 14:57:29 +0000 (16:57 +0200)
babel/messages/checkers.py
babel/messages/frontend.py
tests/messages/test_checkers.py
tests/messages/test_extract.py
tests/messages/test_frontend.py
tests/messages/test_mofile.py
tests/messages/test_pofile.py

index 86dc5bb7084bc1cb3c9b334648fc7aa9a4270659..fe8ab3a51e8687edd43e20d79ae6a20cb2a1aca7 100644 (file)
@@ -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 = [
index a0640eba45146e4661e3310b28848814262b5ac9..55acb95b7bbc5f6031ba459806ba9d6da07dec43 100755 (executable)
 
 """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
     ...
index 4eb4cc9d63a19ae1495995adb31a218bb6bc9cde..218b442c919d806f62a245bbae94f2174f5a6f9a 100644 (file)
@@ -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 <EMAIL@ADDRESS>\n"
-"Language-Team: %(locale)s <LL@li.org>\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 <EMAIL@ADDRESS>\\n"
+"Language-Team: %(locale)s <LL@li.org>\\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
index 569b4839daa1af8fce59c11dd2a32d6b61f688d4..7e587f9d7c91e14bec2e9371a3bb4e9f490508a1 100644 (file)
@@ -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])
index 9cce4b72d727f9247a53bc6103080bbea60b310f..7f76342756df501f96b4b7e258709d6ec5249294 100644 (file)
@@ -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__))
index 6d15d0d19d757779e65e74bb5a97a7a41aa6df7a..835891d42e58925bd6c1de28fe349f8591d67406 100644 (file)
 # 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):
index 68e3d22357649e09ca79c3a66e1785ca7d019e07..393785feebe89822ff1d03438c3743564307266f 100644 (file)
 # 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):