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


Python locale.strxfrm方法代码示例

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


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

示例1: sort_key

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def sort_key(self, string):
        """
        Return a value suitable to pass to the "key" parameter of sorted()
        """

        if HAVE_ICU and self.collator:
            #ICU can digest strings and unicode
            return self.collator.getCollationKey(string).getByteArray()
        else:
            if isinstance(string, bytes):
                string = string.decode("utf-8", "replace")
            try:
                key = locale.strxfrm(string)
            except Exception as err:
                LOG.warning("Failed to obtain key for %s because %s",
                         self.collation, str(err))
                return string
            return key 
开发者ID:GenealogyCollective,项目名称:gprime,代码行数:20,代码来源:locale.py

示例2: get_sortable

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def get_sortable(self, key):
        '''Get sortable of the key.'''
        if key in ["album", "genre", "artist", "title"]:
            value = self.get("sort_%s" % key)
        elif key == "date":    
            value = self.get("#date")
            if not value: value = None
        elif key == "file":    
            try:
                value = locale.strxfrm(self.get_filename())
            except Exception:
                value = self.get_filename()
        else:    
            value = self.get(key, None)
            
        if not value and key[0] == "#": value = 0    
        return value 
开发者ID:dragondjf,项目名称:QMusic,代码行数:19,代码来源:song.py

示例3: get_country_names

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def get_country_names():
    """
    Returns a list of (English) country names from the OKFN/Core Datasets "List of all countries with their
    2 digit codes" list, which has to be available as a file called "countries.csv" in the same directory as
    this source file.
    """

    csv_file_name = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'countries.csv')

    with open(csv_file_name, encoding='utf8') as csv_file:
        csv_reader = csv.reader(csv_file)
        # Skip header line
        next(csv_reader)

        countries = [row[0] for row in csv_reader]
        # Some teams have members in multiple countries
        countries.append('International')

    return sorted(countries, key=locale.strxfrm) 
开发者ID:fausecteam,项目名称:ctf-gameserver,代码行数:21,代码来源:util.py

示例4: select_most_frequent_words

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def select_most_frequent_words(words_and_frequencies, count):
        if count == 0:
            return []

        def get_collated_word(word_and_freq):
            word, freq = word_and_freq
            return locale.strxfrm(word)

        def get_frequency(word_and_freq):
            word, freq = word_and_freq
            return freq

        words_and_frequencies.sort(key=get_frequency, reverse=True)
        words_and_frequencies = words_and_frequencies[:count]
        words_and_frequencies.sort(key=get_collated_word)
        return words_and_frequencies 
开发者ID:jendrikseipp,项目名称:rednotebook,代码行数:18,代码来源:clouds.py

示例5: test_cp34188

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def test_cp34188(self):
        import locale
        locale.setlocale(locale.LC_COLLATE,"de_CH")
        self.assertTrue(sorted([u'a', u'z', u'�'], cmp=locale.strcoll) == sorted([u'a', u'z', u'�'], key=locale.strxfrm)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_stdmodules.py

示例6: sort_by

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def sort_by(paths, iterable):
    """
    Sorts by a translatable name, using system locale for a better result.
    """
    locale.setlocale(locale.LC_ALL, settings.SYSTEM_LOCALE)
    for path in paths:
        iterable = sorted(iterable, key=lambda obj: locale.strxfrm(str(getattr_(obj, path))))
    return iterable 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:10,代码来源:utils.py

示例7: tag_sorting

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def tag_sorting(self, t1, t2, order):
        t1_sp = t1.get_attribute("special")
        t2_sp = t2.get_attribute("special")
        t1_name = locale.strxfrm(t1.get_name())
        t2_name = locale.strxfrm(t2.get_name())
        if not t1_sp and not t2_sp:
            return (t1_name > t2_name) - (t1_name < t2_name)
        elif not t1_sp and t2_sp:
            return 1
        elif t1_sp and not t2_sp:
            return -1
        else:
            t1_order = t1.get_attribute("order")
            t2_order = t2.get_attribute("order")
            return (t1_order > t2_order) - (t1_order < t2_order) 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:17,代码来源:treeview_factory.py

示例8: test_strxfrm

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def test_strxfrm(self):
        self.assertLess(locale.strxfrm('a'), locale.strxfrm('b')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_locale.py

示例9: test_strxfrm_with_diacritic

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def test_strxfrm_with_diacritic(self):
        self.assertLess(locale.strxfrm('à'), locale.strxfrm('b')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_locale.py

示例10: cached_dict

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def cached_dict(self, locale_code="en-us", show_all=False):
        """Retrieves a sorted list of live language codes and names.

        By default only returns live languages for enabled projects, but it can
        also return live languages for disabled projects if specified.

        :param locale_code: the UI locale for which language full names need to
            be localized.
        :param show_all: tells whether to return all live languages (both for
            disabled and enabled projects) or only live languages for enabled
            projects.
        :return: an `OrderedDict`
        """
        key_prefix = "all_cached_dict" if show_all else "cached_dict"
        key = make_method_key(self, key_prefix, locale_code)
        languages = cache.get(key, None)
        if languages is None:
            qs = self.get_all_queryset() if show_all else self.get_queryset()
            languages = OrderedDict(
                sorted(
                    [
                        (locale.strxfrm(lang[0]), tr_lang(lang[1]))
                        for lang in qs.values_list("code", "fullname")
                    ],
                    key=itemgetter(0),
                )
            )
            cache.set(key, languages, CACHE_TIMEOUT)

        return languages 
开发者ID:evernote,项目名称:zing,代码行数:32,代码来源:models.py

示例11: key_name_sort

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def key_name_sort(value):
        # folders are always "in front" of apps and the "up" folder is
        # always first
        if "exec" in value:
            c = "E"
        elif not "up_folder" in value:
            c = "D"
        else:
            c = "C"
        return c + locale.strxfrm(value["name"]) 
开发者ID:ftCommunity,项目名称:ftcommunity-TXT,代码行数:12,代码来源:launcher.py

示例12: sorted_langs

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def sorted_langs(langs):
    return sorted(
        set(langs),
        key=lambda code: locale.strxfrm(
            get_english_language_name(code).encode("UTF-8")
        ),
    ) 
开发者ID:googlefonts,项目名称:nototools,代码行数:9,代码来源:generate_website_data.py

示例13: dumb_sort

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def dumb_sort():
        return strxfrm("A") < strxfrm("a") 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:4,代码来源:locale.py

示例14: test_strxfrm

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def test_strxfrm(self):
        self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
        # embedded null character
        self.assertRaises(ValueError, locale.strxfrm, 'a\0') 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:6,代码来源:test_locale.py

示例15: changedlocale

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strxfrm [as 别名]
def changedlocale(new_locale=None):
    """ Change locale for collation temporarily within a context (with-statement) """
    # The newone locale parameter should be a tuple: ('is_IS', 'UTF-8')
    old_locale = locale.getlocale(locale.LC_COLLATE)
    try:
        locale.setlocale(locale.LC_COLLATE, new_locale or _DEFAULT_SORT_LOCALE)
        yield locale.strxfrm  # Function to transform string for sorting
    finally:
        locale.setlocale(locale.LC_COLLATE, old_locale) 
开发者ID:mideind,项目名称:ReynirPackage,代码行数:11,代码来源:settings.py


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