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


Python Alphabet.tolower方法代码示例

本文整理汇总了Python中languages.Alphabet.tolower方法的典型用法代码示例。如果您正苦于以下问题:Python Alphabet.tolower方法的具体用法?Python Alphabet.tolower怎么用?Python Alphabet.tolower使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在languages.Alphabet的用法示例。


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

示例1: list

# 需要导入模块: from languages import Alphabet [as 别名]
# 或者: from languages.Alphabet import tolower [as 别名]
    def list(cls, nick_from, nick_to, max_len = 100):
        """ Query for a list of users within a nickname range """

        nick_from = u"a" if nick_from is None else Alphabet.tolower(nick_from)
        nick_to = u"ö" if nick_to is None else Alphabet.tolower(nick_to)
        counter = 0

        try:
            o_from = Alphabet.full_order.index(nick_from[0])
        except:
            o_from = 0
        try:
            o_to = Alphabet.full_order.index(nick_to[0])
        except:
            o_to = len(Alphabet.full_order) - 1

        # We do this by issuing a series of queries, each returning
        # nicknames beginning with a particular letter.
        # These shenanigans are necessary because NDB maintains its string
        # indexes by Unicode ordinal index, which is quite different from
        # the actual sort collation order we need. Additionally, the
        # indexes are case-sensitive while our query boundaries are not.

        # Prepare the list of query letters
        q_letters = []

        for i in range(o_from, o_to + 1):
            # Append the lower case letter
            q_letters.append(Alphabet.full_order[i])
            # Append the upper case letter
            q_letters.append(Alphabet.full_upper[i])

        # For aesthetic cleanliness, sort the query letters (in Unicode order)
        q_letters.sort()

        count = 0
        for q_from in q_letters:

            q_to = unichr(ord(q_from) + 1)

            # logging.info(u"Issuing user query from '{0}' to '{1}'".format(q_from, q_to).encode('latin-1'))
            q = cls.query(ndb.AND(UserModel.nickname >= q_from, UserModel.nickname < q_to))

            CHUNK_SIZE = 1000 # Individual letters contain >600 users as of 2015-02-12
            # logging.info(u"Fetching chunk of {0} users".format(CHUNK_SIZE).encode('latin-1'))
            for um in iter_q(q, chunk_size = CHUNK_SIZE):
                if not um.inactive:
                    # This entity matches: return a dict describing it
                    yield dict(
                        id = um.key.id(),
                        nickname = um.nickname,
                        prefs = um.prefs,
                        timestamp = um.timestamp,
                        ready = um.ready,
                        ready_timed = um.ready_timed,
                        human_elo = um.human_elo
                    )
                    count += 1
                    if max_len and count >= max_len:
                        # Reached limit: done
                        return
开发者ID:vthorsteinsson,项目名称:Netskrafl,代码行数:63,代码来源:skrafldb.py


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