当前位置: 首页>>代码示例>>Python>>正文


Python compat.u函数代码示例

本文整理汇总了Python中babel.compat.u函数的典型用法代码示例。如果您正苦于以下问题:Python u函数的具体用法?Python u怎么用?Python u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了u函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_header_entry

    def test_header_entry(self):
        buf = StringIO(r'''\
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2007 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <[email protected]>, 2007.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version:  3.15\n"
"Report-Msgid-Bugs-To: Fliegender Zirkus <[email protected]>\n"
"POT-Creation-Date: 2007-09-27 11:19+0700\n"
"PO-Revision-Date: 2007-09-27 21:42-0700\n"
"Last-Translator: John <[email protected]>\n"
"Language-Team: German Lang <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=iso-8859-2\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 1.0dev-r313\n"
''')
        catalog = pofile.read_po(buf)
        self.assertEqual(1, len(list(catalog)))
        self.assertEqual(u('3.15'), catalog.version)
        self.assertEqual(u('Fliegender Zirkus <[email protected]>'),
                         catalog.msgid_bugs_address)
        self.assertEqual(datetime(2007, 9, 27, 11, 19,
                                  tzinfo=FixedOffsetTimezone(7 * 60)),
                         catalog.creation_date)
        self.assertEqual(u('John <[email protected]>'), catalog.last_translator)
        self.assertEqual(u('German Lang <[email protected]>'), catalog.language_team)
        self.assertEqual(u('iso-8859-2'), catalog.charset)
        self.assertEqual(True, list(catalog)[0].fuzzy)
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:34,代码来源: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(r'''#: 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:Lukas-Stuehrk,项目名称:Babel3,代码行数:27,代码来源:pofile.py

示例3: _merge

 def _merge(message, oldkey, newkey):
     message = message.clone()
     fuzzy = False
     if oldkey != newkey:
         fuzzy = True
         fuzzy_matches.add(oldkey)
         oldmsg = messages.get(oldkey)
         if isinstance(oldmsg.id, string_types):
             message.previous_id = [oldmsg.id]
         else:
             message.previous_id = list(oldmsg.id)
     else:
         oldmsg = remaining.pop(oldkey, None)
     message.string = oldmsg.string
     if isinstance(message.id, (list, tuple)):
         if not isinstance(message.string, (list, tuple)):
             fuzzy = True
             message.string = tuple(
                 [message.string] + ([u('')] * (len(message.id) - 1))
             )
         elif len(message.string) != self.num_plurals:
             fuzzy = True
             message.string = tuple(message.string[:len(oldmsg.string)])
     elif isinstance(message.string, (list, tuple)):
         fuzzy = True
         message.string = message.string[0]
     message.flags |= oldmsg.flags
     if fuzzy:
         message.flags |= set([u('fuzzy')])
     self[message.id] = message
开发者ID:AtomLaw,项目名称:Ally-Py,代码行数:30,代码来源:catalog.py

示例4: _process_message_line

 def _process_message_line(lineno, line):
     if line.startswith('msgid_plural'):
         in_msgid[0] = True
         msg = line[12:].lstrip()
         messages.append(msg)
     elif line.startswith('msgid'):
         in_msgid[0] = True
         offset[0] = lineno
         txt = line[5:].lstrip()
         if messages:
             _add_message()
         messages.append(txt)
     elif line.startswith('msgstr'):
         in_msgid[0] = False
         in_msgstr[0] = True
         msg = line[6:].lstrip()
         if msg.startswith('['):
             idx, msg = msg[1:].split(']', 1)
             translations.append([int(idx), msg.lstrip()])
         else:
             translations.append([0, msg])
     elif line.startswith('msgctxt'):
         if messages:
             _add_message()
         in_msgid[0] = in_msgstr[0] = False
         context.append(line[7:].lstrip())
     elif line.startswith('"'):
         if in_msgid[0]:
             messages[-1] += u('\n') + line.rstrip()
         elif in_msgstr[0]:
             translations[-1][1] += u('\n') + line.rstrip()
         elif in_msgctxt[0]:
             context.append(line.rstrip())
开发者ID:xpoft,项目名称:babel,代码行数:33,代码来源:pofile.py

示例5: apply

 def apply(self, value, locale, currency=None):
     value *= self.scale
     is_negative = int(value < 0)
     if self.exp_prec: # Scientific notation
         value = abs(value)
         if value:
             exp = int(math.floor(math.log(value, 10)))
         else:
             exp = 0
         # Minimum number of integer digits
         if self.int_prec[0] == self.int_prec[1]:
             exp -= self.int_prec[0] - 1
         # Exponent grouping
         elif self.int_prec[1]:
             exp = int(exp) // self.int_prec[1] * self.int_prec[1]
         if not have_decimal or not isinstance(value, Decimal):
             value = float(value)
         if exp < 0:
             value = value * 10**(-exp)
         else:
             value = value / 10**exp
         exp_sign = ''
         if exp < 0:
             exp_sign = get_minus_sign_symbol(locale)
         elif self.exp_plus:
             exp_sign = get_plus_sign_symbol(locale)
         exp = abs(exp)
         number = u('%s%s%s%s') % \
              (self._format_sigdig(value, self.frac_prec[0], 
                                  self.frac_prec[1]), 
               get_exponential_symbol(locale),  exp_sign,
               self._format_int(str(exp), self.exp_prec[0],
                                self.exp_prec[1], locale))
     elif '@' in self.pattern: # Is it a siginificant digits pattern?
         text = self._format_sigdig(abs(value),
                                   self.int_prec[0],
                                   self.int_prec[1])
         if '.' in text:
             a, b = text.split('.')
             a = self._format_int(a, 0, 1000, locale)
             if b:
                 b = get_decimal_symbol(locale) + b
             number = a + b
         else:
             number = self._format_int(text, 0, 1000, locale)
     else: # A normal number pattern
         a, b = split_number(bankersround(abs(value), 
                                          self.frac_prec[1]))
         b = b or '0'
         a = self._format_int(a, self.int_prec[0],
                              self.int_prec[1], locale)
         b = self._format_frac(b, locale)
         number = a + b
     retval = u('%s%s%s') % (self.prefix[is_negative], number,
                             self.suffix[is_negative])
     if u('\xa4') in retval:
         retval = retval.replace(u('\xa4\xa4'), currency.upper())
         retval = retval.replace(u('\xa4'), get_currency_symbol(currency, locale))
     return retval
开发者ID:AtomLaw,项目名称:Ally-Py,代码行数:59,代码来源:numbers.py

示例6: test_comment_tag

    def test_comment_tag(self):
        buf = StringIO("""
# NOTE: A translation comment
msg = _(u'Foo Bar')
""")
        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u('Foo Bar'), messages[0][2])
        self.assertEqual([u('NOTE: A translation comment')], messages[0][3])
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:8,代码来源:extract.py

示例7: test_utf8_raw_strings_match_unicode_strings

    def test_utf8_raw_strings_match_unicode_strings(self):
        buf = BytesIO(codecs.BOM_UTF8 + u("""
msg = _('Bonjour \xe0 tous')
msgu = _(u'Bonjour \xe0 tous')
""").encode('utf-8'))
        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u('Bonjour \xe0 tous'), messages[0][2])
        self.assertEqual(messages[0][2], messages[1][2])
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:8,代码来源:extract.py

示例8: 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('\xe4\xf6\xfc'), locations=[('main.py', 1)])
     buf = BytesIO()
     pofile.write_po(buf, catalog, omit_header=False)
     po_file = buf.getvalue().strip()
     assert b(r'"Content-Type: text/plain; charset=iso-8859-1\n"') in po_file
     assert u('msgstr "\xe4\xf6\xfc"').encode('iso-8859-1') in po_file
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:8,代码来源:pofile.py

示例9: test_message_with_line_comment

    def test_message_with_line_comment(self):
        buf = StringIO("""\
// NOTE: hello
msg = _('Bonjour à tous')
""")
        messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u('Bonjour \xe0 tous'), messages[0][2])
        self.assertEqual([u('NOTE: hello')], messages[0][3])
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:8,代码来源:extract.py

示例10: test_update_message_changed_to_plural

 def test_update_message_changed_to_plural(self):
     cat = catalog.Catalog()
     cat.add(u('foo'), u('Voh'))
     tmpl = catalog.Catalog()
     tmpl.add((u('foo'), u('foos')))
     cat.update(tmpl)
     self.assertEqual((u('Voh'), ''), cat['foo'].string)
     assert cat['foo'].fuzzy
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:8,代码来源:catalog.py

示例11: test_utf8_message_with_utf8_bom

    def test_utf8_message_with_utf8_bom(self):
        buf = BytesIO(codecs.BOM_UTF8 + u("""
# NOTE: hello
msg = _('Bonjour \xe0 tous')
""").encode('utf-8'))
        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u('Bonjour \xe0 tous'), messages[0][2])
        self.assertEqual([u('NOTE: hello')], messages[0][3])
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:8,代码来源:extract.py

示例12: test_utf8_message_with_magic_comment

    def test_utf8_message_with_magic_comment(self):
        buf = StringIO("""# -*- coding: utf-8 -*-
# NOTE: hello
msg = _('Bonjour à tous')
""")
        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u('Bonjour \xe0 tous'), messages[0][2])
        self.assertEqual([u('NOTE: hello')], messages[0][3])
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:8,代码来源:extract.py

示例13: 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:Lukas-Stuehrk,项目名称:Babel3,代码行数:9,代码来源:pofile.py

示例14: 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:Lukas-Stuehrk,项目名称:Babel3,代码行数:9,代码来源:pofile.py

示例15: test_two_succeeding_comments

    def test_two_succeeding_comments(self):
        buf = StringIO("""
# NOTE: one
# NOTE: two
msg = _(u'Foo Bar')
""")
        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u('Foo Bar'), messages[0][2])
        self.assertEqual([u('NOTE: one'), u('NOTE: two')], messages[0][3])
开发者ID:Lukas-Stuehrk,项目名称:Babel3,代码行数:9,代码来源:extract.py


注:本文中的babel.compat.u函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。