本文整理汇总了Python中babel._compat.BytesIO类的典型用法代码示例。如果您正苦于以下问题:Python BytesIO类的具体用法?Python BytesIO怎么用?Python BytesIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BytesIO类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_sorted_po_context
def test_sorted_po_context(self):
catalog = Catalog()
catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
locations=[('main.py', 1)],
context='there')
catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
locations=[('main.py', 1)])
catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
locations=[('main.py', 1)],
context='here')
buf = BytesIO()
pofile.write_po(buf, catalog, sort_output=True)
value = buf.getvalue().strip()
# We expect the foo without ctx, followed by "here" foo and "there" foo
assert b'''\
#: main.py:1
msgid "foo"
msgid_plural "foos"
msgstr[0] "Voh"
msgstr[1] "Voeh"
#: main.py:1
msgctxt "here"
msgid "foo"
msgid_plural "foos"
msgstr[0] "Voh"
msgstr[1] "Voeh"
#: main.py:1
msgctxt "there"
msgid "foo"
msgid_plural "foos"
msgstr[0] "Voh"
msgstr[1] "Voeh"''' in value
开发者ID:Changaco,项目名称:babel,代码行数:34,代码来源:test_pofile.py
示例2: test_po_with_multiline_obsolete_message
def test_po_with_multiline_obsolete_message(self):
catalog = Catalog()
catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
msgid = r"""Here's a message that covers
multiple lines, and should still be handled
correctly.
"""
msgstr = r"""Here's a message that covers
multiple lines, and should still be handled
correctly.
"""
catalog.obsolete[msgid] = Message(msgid, msgstr,
locations=[('utils.py', 3)])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True)
self.assertEqual(b'''#: main.py:1
msgid "foo"
msgstr "Voh"
#~ msgid ""
#~ "Here's a message that covers\\n"
#~ "multiple lines, and should still be handled\\n"
#~ "correctly.\\n"
#~ msgstr ""
#~ "Here's a message that covers\\n"
#~ "multiple lines, and should still be handled\\n"
#~ "correctly.\\n"''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:27,代码来源:test_pofile.py
示例3: test_with_context
def test_with_context(self):
buf = BytesIO(b'''# Some string in the menu
#: main.py:1
msgctxt "Menu"
msgid "foo"
msgstr "Voh"
# Another string in the menu
#: main.py:2
msgctxt "Menu"
msgid "bar"
msgstr "Bahr"
''')
catalog = pofile.read_po(buf, ignore_obsolete=True)
self.assertEqual(2, len(catalog))
message = catalog.get('foo', context='Menu')
self.assertEqual('Menu', message.context)
message = catalog.get('bar', context='Menu')
self.assertEqual('Menu', message.context)
# And verify it pass through write_po
out_buf = BytesIO()
pofile.write_po(out_buf, catalog, omit_header=True)
assert out_buf.getvalue().strip() == buf.getvalue().strip(), \
out_buf.getvalue()
开发者ID:Changaco,项目名称:babel,代码行数:25,代码来源:test_pofile.py
示例4: test_sorting
def test_sorting(self):
# Ensure the header is sorted to the first entry so that its charset
# can be applied to all subsequent messages by GNUTranslations
# (ensuring all messages are safely converted to unicode)
catalog = Catalog(locale='en_US')
catalog.add(u'', '''\
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n''')
catalog.add(u'foo', 'Voh')
catalog.add((u'There is', u'There are'), (u'Es gibt', u'Es gibt'))
catalog.add(u'Fizz', '')
catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
buf = BytesIO()
mofile.write_mo(buf, catalog)
buf.seek(0)
translations = Translations(fp=buf)
self.assertEqual(u'Voh', translations.ugettext('foo'))
assert isinstance(translations.ugettext('foo'), text_type)
self.assertEqual(u'Es gibt', translations.ungettext('There is', 'There are', 1))
assert isinstance(translations.ungettext('There is', 'There are', 1), text_type)
self.assertEqual(u'Fizz', translations.ugettext('Fizz'))
assert isinstance(translations.ugettext('Fizz'), text_type)
self.assertEqual(u'Fuzz', translations.ugettext('Fuzz'))
assert isinstance(translations.ugettext('Fuzz'), text_type)
self.assertEqual(u'Fuzzes', translations.ugettext('Fuzzes'))
assert isinstance(translations.ugettext('Fuzzes'), text_type)
开发者ID:python-babel,项目名称:babel,代码行数:26,代码来源:test_mofile.py
示例5: test_no_wrap_and_width_behaviour_on_comments
def test_no_wrap_and_width_behaviour_on_comments(self):
catalog = Catalog()
catalog.add("Pretty dam long message id, which must really be big "
"to test this wrap behaviour, if not it won't work.",
locations=[("fake.py", n) for n in range(1, 30)])
buf = BytesIO()
pofile.write_po(buf, catalog, width=None, omit_header=True)
self.assertEqual(b"""\
#: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7
#: fake.py:8 fake.py:9 fake.py:10 fake.py:11 fake.py:12 fake.py:13 fake.py:14
#: fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19 fake.py:20 fake.py:21
#: fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28
#: fake.py:29
msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work."
msgstr ""
""", buf.getvalue().lower())
buf = BytesIO()
pofile.write_po(buf, catalog, width=100, omit_header=True)
self.assertEqual(b"""\
#: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7 fake.py:8 fake.py:9 fake.py:10
#: fake.py:11 fake.py:12 fake.py:13 fake.py:14 fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19
#: fake.py:20 fake.py:21 fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28
#: fake.py:29
msgid ""
"pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't"
" work."
msgstr ""
""", buf.getvalue().lower())
开发者ID:Changaco,项目名称:babel,代码行数:30,代码来源:test_pofile.py
示例6: test_unknown_language_write
def test_unknown_language_write():
catalog = Catalog(locale='sr_SP')
assert catalog.locale_identifier == 'sr_SP'
assert not catalog.locale
buf = BytesIO()
pofile.write_po(buf, catalog)
assert 'sr_SP' in buf.getvalue().decode()
开发者ID:Changaco,项目名称:babel,代码行数:7,代码来源:test_pofile.py
示例7: test_write_po_file_with_specified_charset
def test_write_po_file_with_specified_charset(self):
catalog = Catalog(charset='iso-8859-1')
catalog.add('foo', u'äöü', locations=[('main.py', 1)])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=False)
po_file = buf.getvalue().strip()
assert b'"Content-Type: text/plain; charset=iso-8859-1\\n"' in po_file
assert u'msgstr "äöü"'.encode('iso-8859-1') in po_file
开发者ID:Changaco,项目名称:babel,代码行数:8,代码来源:test_pofile.py
示例8: test_file_sorted_po
def test_file_sorted_po(self):
catalog = Catalog()
catalog.add(u'bar', locations=[('utils.py', 3)])
catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'), locations=[('main.py', 1)])
buf = BytesIO()
pofile.write_po(buf, catalog, sort_by_file=True)
value = buf.getvalue().strip()
assert value.find(b'main.py') < value.find(b'utils.py')
开发者ID:Changaco,项目名称:babel,代码行数:8,代码来源:test_pofile.py
示例9: test_duplicate_comments
def test_duplicate_comments(self):
catalog = Catalog()
catalog.add(u'foo', auto_comments=['A comment'])
catalog.add(u'foo', auto_comments=['A comment'])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True)
self.assertEqual(b'''#. A comment
msgid "foo"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:9,代码来源:test_pofile.py
示例10: test_join_locations
def test_join_locations(self):
catalog = Catalog()
catalog.add(u'foo', locations=[('main.py', 1)])
catalog.add(u'foo', locations=[('utils.py', 3)])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True)
self.assertEqual(b'''#: main.py:1 utils.py:3
msgid "foo"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:9,代码来源:test_pofile.py
示例11: test_no_include_lineno
def test_no_include_lineno(self):
catalog = Catalog()
catalog.add(u'foo', locations=[('main.py', 1)])
catalog.add(u'foo', locations=[('utils.py', 3)])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True, include_lineno=False)
self.assertEqual(b'''#: main.py utils.py
msgid "foo"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:9,代码来源:test_pofile.py
示例12: test_po_with_previous_msgid
def test_po_with_previous_msgid(self):
catalog = Catalog()
catalog.add(u'foo', u'Voh', locations=[('main.py', 1)],
previous_id=u'fo')
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
self.assertEqual(b'''#: main.py:1
#| msgid "fo"
msgid "foo"
msgstr "Voh"''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:10,代码来源:test_pofile.py
示例13: test_po_with_obsolete_message_ignored
def test_po_with_obsolete_message_ignored(self):
catalog = Catalog()
catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
catalog.obsolete['bar'] = Message(u'bar', u'Bahr',
locations=[('utils.py', 3)],
user_comments=['User comment'])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True, ignore_obsolete=True)
self.assertEqual(b'''#: main.py:1
msgid "foo"
msgstr "Voh"''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:11,代码来源:test_pofile.py
示例14: test_po_with_previous_msgid_plural
def test_po_with_previous_msgid_plural(self):
catalog = Catalog()
catalog.add(('foo', 'foos'), ('Voh', 'Voeh'),
locations=[('main.py', 1)], previous_id=('fo', 'fos'))
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
self.assertEqual(b'''#: main.py:1
#| msgid "fo"
#| msgid_plural "fos"
msgid "foo"
msgid_plural "foos"
msgstr[0] "Voh"
msgstr[1] "Voeh"''', buf.getvalue().strip())
开发者ID:fsys,项目名称:babel,代码行数:13,代码来源:test_pofile.py
示例15: test_wrap_locations_with_hyphens
def test_wrap_locations_with_hyphens(self):
catalog = Catalog()
catalog.add(u'foo', locations=[
('doupy/templates/base/navmenu.inc.html.py', 60)
])
catalog.add(u'foo', locations=[
('doupy/templates/job-offers/helpers.html', 22)
])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True)
self.assertEqual(b'''#: doupy/templates/base/navmenu.inc.html.py:60
#: doupy/templates/job-offers/helpers.html:22
msgid "foo"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:14,代码来源:test_pofile.py
示例16: test_file_with_no_lineno
def test_file_with_no_lineno(self):
catalog = Catalog()
catalog.add(u'bar', locations=[('utils.py', None)],
user_comments=['Comment About `bar` with',
'multiple lines.'])
buf = BytesIO()
pofile.write_po(buf, catalog, sort_output=True)
value = buf.getvalue().strip()
assert b'''\
# Comment About `bar` with
# multiple lines.
#: utils.py
msgid "bar"
msgstr ""''' in value
开发者ID:Changaco,项目名称:babel,代码行数:14,代码来源:test_pofile.py
示例17: test_wrap_long_lines_with_long_word
def test_wrap_long_lines_with_long_word(self):
text = """Here's some text that
includesareallylongwordthatmightbutshouldnt throw us into an infinite loop
"""
catalog = Catalog()
catalog.add(text, locations=[('main.py', 1)])
buf = BytesIO()
pofile.write_po(buf, catalog, no_location=True, omit_header=True,
width=32)
self.assertEqual(b'''msgid ""
"Here's some text that\\n"
"includesareallylongwordthatmightbutshouldnt"
" throw us into an infinite "
"loop\\n"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:15,代码来源:test_pofile.py
示例18: test_wrap_long_lines_in_header
def test_wrap_long_lines_in_header(self):
"""
Verify that long lines in the header comment are wrapped correctly.
"""
catalog = Catalog(project='AReallyReallyLongNameForAProject',
revision_date=datetime(2007, 4, 1))
buf = BytesIO()
pofile.write_po(buf, catalog)
self.assertEqual(b'''\
# Translations template for AReallyReallyLongNameForAProject.
# Copyright (C) 2007 ORGANIZATION
# This file is distributed under the same license as the
# AReallyReallyLongNameForAProject project.
# FIRST AUTHOR <[email protected]>, 2007.
#
#, fuzzy''', b'\n'.join(buf.getvalue().splitlines()[:7]))
开发者ID:Changaco,项目名称:babel,代码行数:16,代码来源:test_pofile.py
示例19: test_pot_with_translator_comments
def test_pot_with_translator_comments(self):
catalog = Catalog()
catalog.add(u'foo', locations=[('main.py', 1)],
auto_comments=['Comment About `foo`'])
catalog.add(u'bar', locations=[('utils.py', 3)],
user_comments=['Comment About `bar` with',
'multiple lines.'])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True)
self.assertEqual(b'''#. Comment About `foo`
#: main.py:1
msgid "foo"
msgstr ""
# Comment About `bar` with
# multiple lines.
#: utils.py:3
msgid "bar"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:19,代码来源:test_pofile.py
示例20: test_wrap_long_lines
def test_wrap_long_lines(self):
text = """Here's some text where
white space and line breaks matter, and should
not be removed
"""
catalog = Catalog()
catalog.add(text, locations=[('main.py', 1)])
buf = BytesIO()
pofile.write_po(buf, catalog, no_location=True, omit_header=True,
width=42)
self.assertEqual(b'''msgid ""
"Here's some text where\\n"
"white space and line breaks matter, and"
" should\\n"
"\\n"
"not be removed\\n"
"\\n"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:20,代码来源:test_pofile.py
注:本文中的babel._compat.BytesIO类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论