def currency_formats(self):
"""Locale patterns for currency number formatting.
- >>> print Locale('en', 'US').currency_formats['standard']
+ >>> Locale('en', 'US').currency_formats['standard']
<NumberPattern u'\\xa4#,##0.00'>
- >>> print Locale('en', 'US').currency_formats['accounting']
+ >>> Locale('en', 'US').currency_formats['accounting']
<NumberPattern u'\\xa4#,##0.00'>
"""
return self._data['currency_formats']
def format_date(date=None, format='medium', locale=LC_TIME):
"""Return a date formatted according to the given pattern.
- >>> d = date(2007, 04, 01)
+ >>> d = date(2007, 4, 1)
>>> format_date(d, locale='en_US')
u'Apr 1, 2007'
>>> format_date(d, format='full', locale='de_DE')
locale=LC_TIME):
r"""Return a date formatted according to the given pattern.
- >>> dt = datetime(2007, 04, 01, 15, 30)
+ >>> dt = datetime(2007, 4, 1, 15, 30)
>>> format_datetime(dt, locale='en_US')
u'Apr 1, 2007, 3:30:00 PM'
>>> d = {1: 'foo', 3: 'baz'}
>>> merge(d, {1: 'Foo', 2: 'Bar'})
- >>> items = d.items(); items.sort(); items
+ >>> sorted(d.items())
[(1, 'Foo'), (2, 'Bar'), (3, 'baz')]
:param dict1: the dictionary to merge into
>>> catalog = Catalog(project='Foobar', version='1.0',
... copyright_holder='Foo Company')
- >>> print catalog.header_comment #doctest: +ELLIPSIS
+ >>> print(catalog.header_comment) #doctest: +ELLIPSIS
# Translations template for Foobar.
# Copyright (C) ... Foo Company
# This file is distributed under the same license as the Foobar project.
... # This file is distributed under the same license as the PROJECT
... # project.
... #'''
- >>> print catalog.header_comment
+ >>> print(catalog.header_comment)
# The POT for my really cool Foobar project.
# Copyright (C) 1990-2003 Foo Company
# This file is distributed under the same license as the Foobar
>>> catalog = Catalog(project='Foobar', version='1.0',
... creation_date=created)
>>> for name, value in catalog.mime_headers:
- ... print '%s: %s' % (name, value)
+ ... print('%s: %s' % (name, value))
Project-Id-Version: Foobar 1.0
Report-Msgid-Bugs-To: EMAIL@ADDRESS
POT-Creation-Date: 1990-04-01 15:30+0000
... last_translator='John Doe <jd@example.com>',
... language_team='de_DE <de@example.com>')
>>> for name, value in catalog.mime_headers:
- ... print '%s: %s' % (name, value)
+ ... print('%s: %s' % (name, value))
Project-Id-Version: Foobar 1.0
Report-Msgid-Bugs-To: EMAIL@ADDRESS
POT-Creation-Date: 1990-04-01 15:30+0000
>>> 'head' in catalog
False
- >>> catalog.obsolete.values()
+ >>> list(catalog.obsolete.values())
[<Message 'head' (flags: [])>]
:param template: the reference catalog, usually read from a POT file
The implementation dispatches the actual extraction to plugins, based on the
value of the ``method`` parameter.
- >>> source = '''# foo module
+ >>> source = b'''# foo module
... def run(argv):
- ... print _('Hello, world!')
+ ... print(_('Hello, world!'))
... '''
- >>> from StringIO import StringIO
- >>> for message in extract('python', StringIO(source)):
- ... print message
+ >>> from babel._compat import BytesIO
+ >>> for message in extract('python', BytesIO(source)):
+ ... print(message)
(3, u'Hello, world!', [], None)
:param method: an extraction method (a callable), or
:copyright: (c) 2013 by the Babel Team.
:license: BSD, see LICENSE for more details.
"""
-
+from __future__ import print_function
try:
from ConfigParser import RawConfigParser
except ImportError:
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, BytesIO, PY2
+from babel._compat import string_types, StringIO, PY2
class compile_catalog(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(BytesIO(mapping))
+ method_map, options_map = parse_mapping(StringIO(mapping))
else:
method_map, options_map = [], {}
for pattern, method, options in mapping:
def parse_mapping(fileobj, filename=None):
"""Parse an extraction method mapping from a file-like object.
- >>> buf = BytesIO(b'''
+ >>> buf = StringIO('''
... [extractors]
... custom = mypackage.module:myfunc
...
def parse_keywords(strings=[]):
"""Parse keywords specifications from the given list of strings.
- >>> kw = parse_keywords(['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2']).items()
- >>> kw.sort()
+ >>> kw = sorted(parse_keywords(['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2']).items())
>>> for keyword, indices in kw:
- ... print (keyword, indices)
+ ... print((keyword, indices))
('_', None)
('dgettext', (2,))
('dngettext', (2, 3))
"""Write a catalog to the specified file-like object using the GNU MO file
format.
+ >>> import sys
>>> from babel.messages import Catalog
>>> from gettext import GNUTranslations
- >>> from StringIO import StringIO
+ >>> from babel._compat import BytesIO
>>> catalog = Catalog(locale='en_US')
>>> catalog.add('foo', 'Voh')
<Message ...>
>>> catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
<Message ...>
- >>> buf = StringIO()
+ >>> buf = BytesIO()
>>> write_mo(buf, catalog)
- >>> buf.seek(0)
+ >>> x = buf.seek(0)
>>> translations = GNUTranslations(fp=buf)
+ >>> if sys.version_info[0] >= 3:
+ ... translations.ugettext = translations.gettext
+ ... translations.ungettext = translations.ngettext
>>> translations.ugettext('foo')
u'Voh'
>>> translations.ungettext('bar', 'baz', 1)
:license: BSD, see LICENSE for more details.
"""
+from __future__ import print_function
import os
import re
def unescape(string):
r"""Reverse `escape` the given string.
- >>> print unescape('"Say:\\n \\"hello, world!\\"\\n"')
+ >>> print(unescape('"Say:\\n \\"hello, world!\\"\\n"'))
Say:
"hello, world!"
<BLANKLINE>
def denormalize(string):
r"""Reverse the normalization done by the `normalize` function.
- >>> print denormalize(r'''""
+ >>> print(denormalize(r'''""
... "Say:\n"
- ... " \"hello, world!\"\n"''')
+ ... " \"hello, world!\"\n"'''))
Say:
"hello, world!"
<BLANKLINE>
- >>> print denormalize(r'''""
+ >>> print(denormalize(r'''""
... "Say:\n"
... " \"Lorem ipsum dolor sit "
... "amet, consectetur adipisicing"
- ... " elit, \"\n"''')
+ ... " elit, \"\n"'''))
Say:
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
<BLANKLINE>
file-like object and return a `Catalog`.
>>> from datetime import datetime
- >>> from StringIO import StringIO
+ >>> from babel._compat import StringIO
>>> buf = StringIO('''
... #: main.py:1
... #, fuzzy, python-format
... msgstr[1] "baaz"
... ''')
>>> catalog = read_po(buf)
- >>> catalog.revision_date = datetime(2007, 04, 01)
+ >>> catalog.revision_date = datetime(2007, 4, 1)
>>> for message in catalog:
... if message.id:
- ... print (message.id, message.string)
- ... print ' ', (message.locations, sorted(list(message.flags)))
- ... print ' ', (message.user_comments, message.auto_comments)
+ ... print((message.id, message.string))
+ ... print(' ', (message.locations, sorted(list(message.flags))))
+ ... print(' ', (message.user_comments, message.auto_comments))
(u'foo %(name)s', u'quux %(name)s')
([(u'main.py', 1)], [u'fuzzy', u'python-format'])
([], [])
def normalize(string, prefix='', width=76):
r"""Convert a string into a format that is appropriate for .po files.
- >>> print normalize('''Say:
+ >>> print(normalize('''Say:
... "hello, world!"
- ... ''', width=None)
+ ... ''', width=None))
""
"Say:\n"
" \"hello, world!\"\n"
- >>> print normalize('''Say:
+ >>> print(normalize('''Say:
... "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
- ... ''', width=32)
+ ... ''', width=32))
""
"Say:\n"
" \"Lorem ipsum dolor sit "
<Message...>
>>> catalog.add((u'bar', u'baz'), locations=[('main.py', 3)])
<Message...>
- >>> from io import BytesIO
+ >>> from babel._compat import BytesIO
>>> buf = BytesIO()
>>> write_po(buf, catalog, omit_header=True)
- >>> print buf.getvalue()
+ >>> print(buf.getvalue().decode("utf8"))
#: main.py:1
#, fuzzy, python-format
msgid "foo %(name)s"
>>> def greeting(name='world'):
... return 'Hello, %s!' % name
>>> lazy_greeting = LazyProxy(greeting, name='Joe')
- >>> print lazy_greeting
+ >>> print(lazy_greeting)
Hello, Joe!
>>> u' ' + lazy_greeting
u' Hello, Joe!'
... ]
>>> greetings.sort()
>>> for greeting in greetings:
- ... print greeting
+ ... print(greeting)
Hello, Joe!
Hello, universe!
Hello, world!
Unlike when using sets for a similar effect, the original ordering of the
items in the collection is preserved by this function.
- >>> print list(distinct([1, 2, 1, 3, 4, 4]))
+ >>> print(list(distinct([1, 2, 1, 3, 4, 4])))
[1, 2, 3, 4]
- >>> print list(distinct('foobar'))
+ >>> print(list(distinct('foobar')))
['f', 'o', 'b', 'a', 'r']
:param iterable: the iterable collection providing the data
-import sys
from _pytest.doctest import DoctestModule
from py.path import local
-
-PY2 = sys.version_info[0] < 3
-
-
collect_ignore = ['tests/messages/data', 'setup.py']
+babel_path = local(__file__).dirpath().join('babel')
def pytest_collect_file(path, parent):
- babel_path = local(__file__).dirpath().join('babel')
- config = parent.config
- if PY2:
- if babel_path.common(path) == babel_path:
- if path.ext == ".py":
- return DoctestModule(path, parent)
+ if babel_path.common(path) == babel_path:
+ if path.ext == ".py":
+ return DoctestModule(path, parent)
[pytest]
norecursedirs = venv* .* _* scripts {args}
-doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE ALLOW_UNICODE
+doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE ALLOW_UNICODE IGNORE_EXCEPTION_DETAIL
[bdist_wheel]
universal = 1