: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 = [
"""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
import os
import re
import shutil
-from StringIO import StringIO
import sys
import tempfile
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']
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:
'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:
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:
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.
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:
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
...
from datetime import datetime
import time
import unittest
-from StringIO import StringIO
from babel import __version__ as VERSION
from babel.core import Locale, UnknownLocaleError
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):
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
#
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
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])
(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])
import logging
import os
import shutil
-from StringIO import StringIO
import sys
import time
import unittest
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__))
# 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):
# 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):