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


Python util.distinct函数代码示例

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


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

示例1: __init__

    def __init__(
        self, id, string=u"", locations=(), flags=(), auto_comments=(), user_comments=(), previous_id=(), lineno=None
    ):
        """Create the message object.

        :param id: the message ID, or a ``(singular, plural)`` tuple for
                   pluralizable messages
        :param string: the translated message string, or a
                       ``(singular, plural)`` tuple for pluralizable messages
        :param locations: a sequence of ``(filenname, lineno)`` tuples
        :param flags: a set or sequence of flags
        :param auto_comments: a sequence of automatic comments for the message
        :param user_comments: a sequence of user comments for the message
        :param previous_id: the previous message ID, or a ``(singular, plural)``
                            tuple for pluralizable messages
        :param lineno: the line number on which the msgid line was found in the
                       PO file, if any
        """
        self.id = id  #: The message ID
        if not string and self.pluralizable:
            string = (u"", u"")
        self.string = string  #: The message translation
        self.locations = list(distinct(locations))
        self.flags = set(flags)
        if id and self.python_format:
            self.flags.add("python-format")
        else:
            self.flags.discard("python-format")
        self.auto_comments = list(distinct(auto_comments))
        self.user_comments = list(distinct(user_comments))
        if isinstance(previous_id, basestring):
            self.previous_id = [previous_id]
        else:
            self.previous_id = list(previous_id)
        self.lineno = lineno
开发者ID:songmm19900210,项目名称:galaxy-tools-prok,代码行数:35,代码来源:catalog.py

示例2: __setitem__

    def __setitem__(self, id, message):
        """Add or update the message with the specified ID.

        >>> catalog = Catalog()
        >>> catalog[u('foo')] = Message(u('foo'))
        >>> catalog[u('foo')]
        <Message foo (flags: [])>

        If a message with that ID is already in the catalog, it is updated
        to include the locations and flags of the new message.

        >>> catalog = Catalog()
        >>> catalog[u('foo')] = Message(u('foo'), locations=[('main.py', 1)])
        >>> catalog[u('foo')].locations
        [('main.py', 1)]
        >>> catalog[u('foo')] = Message(u('foo'), locations=[('utils.py', 5)])
        >>> catalog[u('foo')].locations
        [('main.py', 1), ('utils.py', 5)]

        :param id: the message ID
        :param message: the `Message` object
        """
        assert isinstance(message, Message), 'expected a Message object'
        key = self._key_for(id, message.context)
        current = self._messages.get(key)
        if current:
            if message.pluralizable and not current.pluralizable:
                # The new message adds pluralization
                current.id = message.id
                current.string = message.string
            current.locations = list(distinct(current.locations +
                                              message.locations))
            current.auto_comments = list(distinct(current.auto_comments +
                                                  message.auto_comments))
            current.user_comments = list(distinct(current.user_comments +
                                                  message.user_comments))
            current.flags |= message.flags
            message = current
        elif id == '':
            # special treatment for the header message
            def _parse_header(header_string):
                # message_from_string only works for str, not for unicode
                if not PY3:
                    header_string = header_string.encode('utf8')
                headers = message_from_string(header_string)
                decoded_headers = {}
                for name, value in headers.items():
                    if not PY3:
                        name, value = name.decode('utf8'), value.decode('utf8')
                    decoded_headers[name] = value
                return decoded_headers
            self.mime_headers = list(_parse_header(message.string).items())
            self.header_comment = '\n'.join(['# %s' % comment for comment
                                             in message.user_comments])
            self.fuzzy = message.fuzzy
        else:
            if isinstance(id, (list, tuple)):
                assert isinstance(message.string, (list, tuple)), \
                    'Expected sequence but got %s' % type(message.string)
            self._messages[key] = message
开发者ID:AtomLaw,项目名称:Ally-Py,代码行数:60,代码来源:catalog.py

示例3: __init__

    def __init__(self, id, string=u'', locations=(), flags=(), auto_comments=(),
                 user_comments=(), previous_id=(), lineno=None, context=None):
        """Create the message object.

        :param id: the message ID, or a ``(singular, plural)`` tuple for
                   pluralizable messages
        :param string: the translated message string, or a
                       ``(singular, plural)`` tuple for pluralizable messages
        :param locations: a sequence of ``(filename, lineno)`` tuples
        :param flags: a set or sequence of flags
        :param auto_comments: a sequence of automatic comments for the message
        :param user_comments: a sequence of user comments for the message
        :param previous_id: the previous message ID, or a ``(singular, plural)``
                            tuple for pluralizable messages
        :param lineno: the line number on which the msgid line was found in the
                       PO file, if any
        :param context: the message context
        """
        self.id = id
        if not string and self.pluralizable:
            string = (u'', u'')
        self.string = string
        self.locations = list(distinct(locations))
        self.flags = set(flags)

        self.auto_comments = list(distinct(auto_comments))
        self.user_comments = list(distinct(user_comments))
        if isinstance(previous_id, string_types):
            self.previous_id = [previous_id]
        else:
            self.previous_id = list(previous_id)
        self.lineno = lineno
        self.context = context
开发者ID:JonathanRRogers,项目名称:babel,代码行数:33,代码来源:catalog.py

示例4: __setitem__

    def __setitem__(self, id, message):
        """Add or update the message with the specified ID.

        >>> catalog = Catalog()
        >>> catalog[u'foo'] = Message(u'foo')
        >>> catalog[u'foo']
        <Message u'foo' (flags: [])>

        If a message with that ID is already in the catalog, it is updated
        to include the locations and flags of the new message.

        >>> catalog = Catalog()
        >>> catalog[u'foo'] = Message(u'foo', locations=[('main.py', 1)])
        >>> catalog[u'foo'].locations
        [('main.py', 1)]
        >>> catalog[u'foo'] = Message(u'foo', locations=[('utils.py', 5)])
        >>> catalog[u'foo'].locations
        [('main.py', 1), ('utils.py', 5)]

        :param id: the message ID
        :param message: the `Message` object
        """
        assert isinstance(message, Message), 'expected a Message object'
        key = self._key_for(id, message.context)
        current = self._messages.get(key)
        if current:
            if message.pluralizable and not current.pluralizable:
                # The new message adds pluralization
                current.id = message.id
                current.string = message.string
            current.locations = list(distinct(current.locations +
                                              message.locations))
            current.auto_comments = list(distinct(current.auto_comments +
                                                  message.auto_comments))
            current.user_comments = list(distinct(current.user_comments +
                                                  message.user_comments))
            current.flags |= message.flags
            message = current
        elif id == '':
            # special treatment for the header message
            headers = message_from_string(message.string.encode(self.charset))
            self.mime_headers = headers.items()
            self.header_comment = '\n'.join(['# %s' % comment for comment
                                             in message.user_comments])
            self.fuzzy = message.fuzzy
        else:
            if isinstance(id, (list, tuple)):
                assert isinstance(message.string, (list, tuple)), \
                    'Expected sequence but got %s' % type(message.string)
            self._messages[key] = message
开发者ID:johnmontero,项目名称:pypewe,代码行数:50,代码来源:catalog.py

示例5: _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
     message.user_comments = list(distinct(oldmsg.user_comments))
     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:Mabusto,项目名称:babel,代码行数:31,代码来源:catalog.py

示例6: _get_primary_locales

    def _get_primary_locales():
        preferred = _get_preferred_languages() or ['en']
        primary = []

        for language in preferred:
            if language in available_locales:
                primary.append(available_locales[language])
            elif language[:2] in available_locales:
                primary.append(available_locales[language[:2]])

        return map(None, distinct(primary))
开发者ID:Adrien81,项目名称:skylines,代码行数:11,代码来源:i18n.py

示例7: get_primary_languages

        def get_primary_languages():
            available = [lang['language_code'] for lang in languages()]
            requested = distinct(get_lang() or ['en'])

            # add primary languages
            primary = []
            for language in requested:
                if language in available:
                    primary.append(language)
                else:
                    try:
                        locale = parse_locale(language)
                    except:
                        continue

                    if locale[0] in available:
                        primary.append(locale[0])

            if len(primary) == 0:
                return [language_info('en')]

            return [language_info(lang) for lang in distinct(primary)]
开发者ID:dkm,项目名称:skylines,代码行数:22,代码来源:base.py

示例8: test_distinct

def test_distinct():
    assert list(util.distinct([1, 2, 1, 3, 4, 4])) == [1, 2, 3, 4]
    assert list(util.distinct('foobar')) == ['f', 'o', 'b', 'a', 'r']
开发者ID:Givemore,项目名称:fjord,代码行数:3,代码来源:test_util.py

示例9: __setitem__

    def __setitem__(self, id, message):
        """Add or update the message with the specified ID.

        >>> catalog = Catalog()
        >>> catalog[u'foo'] = Message(u'foo')
        >>> catalog[u'foo']
        <Message u'foo' (flags: [])>

        If a message with that ID is already in the catalog, it is updated
        to include the locations and flags of the new message.

        >>> catalog = Catalog()
        >>> catalog[u'foo'] = Message(u'foo', locations=[('main.py', 1)])
        >>> catalog[u'foo'].locations
        [('main.py', 1)]
        >>> catalog[u'foo'] = Message(u'foo', locations=[('utils.py', 5)])
        >>> catalog[u'foo'].locations
        [('main.py', 1), ('utils.py', 5)]

        :param id: the message ID
        :param message: the `Message` object
        """
        assert isinstance(message, Message), 'expected a Message object'
        key = self._key_for(id, message.context)
        current = self._messages.get(key)
        if current:
            if (message.pluralizable and current.pluralizable and
                message.id != current.id):
                # The messages have conflicting pluralization.
                plural_1 = message.id[1]
                location_1 = ':'.join(map(str, message.locations[0]))
                plural_2 = current.id[1]
                location_2 = ':'.join(map(str, current.locations[0]))
                raise TranslationError(
                    "Found conflicting plurals for '%s': '%s' at %s and "
                    "'%s' at %s. "
                    "(Perhaps solve by replacing '1' with <var> in '%s')"
                    % (key, plural_1, location_1, plural_2, location_2, key))
            if message.pluralizable and not current.pluralizable:
                # The new message adds pluralization
                current.id = message.id
                current.string = message.string
            current.locations = list(distinct(current.locations +
                                              message.locations))
            current.auto_comments = list(distinct(current.auto_comments +
                                                  message.auto_comments))
            current.user_comments = list(distinct(current.user_comments +
                                                  message.user_comments))
            current.flags |= message.flags
            message = current
        elif id == '':
            # special treatment for the header message
            self.mime_headers = _parse_header(message.string).items()
            self.header_comment = '\n'.join([('# %s' % c).rstrip() for c
                                             in message.user_comments])
            self.fuzzy = message.fuzzy
        else:
            if isinstance(id, (list, tuple)):
                assert isinstance(message.string, (list, tuple)), \
                    'Expected sequence but got %s' % type(message.string)
            self._messages[key] = message
开发者ID:Khan,项目名称:babel,代码行数:61,代码来源:catalog.py


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