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


Python locale.strcoll方法代码示例

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


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

示例1: __ColumnSorter

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def __ColumnSorter(self, key1, key2):
        col = self._col
        ascending = self._colSortFlag[col]
        item1 = self.itemDataMap[key1][col]
        item2 = self.itemDataMap[key2][col]

        #--- Internationalization of string sorting with locale module
        if type(item1) == unicode and type(item2) == unicode:
            cmpVal = locale.strcoll(item1, item2)
        elif type(item1) == str or type(item2) == str:
            cmpVal = locale.strcoll(str(item1), str(item2))
        else:
            cmpVal = cmp(item1, item2)
        #---

        # If the items are equal then pick something else to make the sort value unique
        if cmpVal == 0:
            cmpVal = apply(cmp, self.GetSecondarySortValues(col, key1, key2))

        if ascending:
            return cmpVal
        else:
            return -cmpVal 
开发者ID:bluenote10,项目名称:PandasDataFrameGUI,代码行数:25,代码来源:listmixin.py

示例2: _SortItemsNow

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def _SortItemsNow(self):
        """
        Sort the actual items in the list now, according to the current column and order
        """
        sortColumn = self.GetSortColumn()
        if not sortColumn:
            return

        secondarySortColumn = None # self.GetSecondarySortColumn()

        def _singleObjectComparer(col, object1, object2):
            value1 = col.GetValue(object1)
            value2 = col.GetValue(object2)
            try:
                return locale.strcoll(value1.lower(), value2.lower())
            except:
                return cmp(value1, value2)

        def _objectComparer(object1, object2):
            result = _singleObjectComparer(sortColumn, object1, object2)
            if secondarySortColumn and result == 0:
                result = _singleObjectComparer(secondarySortColumn, object1, object2)
            return result

        self.SortListItemsBy(_objectComparer) 
开发者ID:JackonYang,项目名称:bookhub,代码行数:27,代码来源:ObjectListView.py

示例3: test_strcoll_3303

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def test_strcoll_3303(self):
            # test crasher from bug #3303
            self.assertRaises(TypeError, locale.strcoll, u"a", None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_locale.py

示例4: test_cp34188

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [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

示例5: FilterTopCities

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def FilterTopCities(self):
    """Applies the boost to US cities, sorts by population and outputs the
    list of files to output directory.
    """
    filtered_cities = []
    for city in self._data:
      filtered_cities.append(city)
    cities_sorted = sorted(filtered_cities, key=attrgetter('name'), cmp=locale.strcoll)
    with codecs.open(os.path.join(options.options.output_dir, 'top_cities.txt'), 'w', 'utf-8') as f:
      for c in cities_sorted:
        f.write('%s,%s,%s,%f,%f\n' % (c.name, c.state or '', c.cc, c.lat, c.lon)) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:13,代码来源:geoprocessor.py

示例6: _ParseUSPostal

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def _ParseUSPostal(self, datafile):
    """Loads and parses the provided datafile into an array of placename
    information.
    """
    self._us_postal = []
    with open(datafile, 'r') as f:
      for line in f.readlines():
        fields = line.split('\t')
        datum = GeoDatum(None, self._CleanName(fields[2].decode('utf-8')),
                         float(fields[9]), float(fields[10]), fields[0], fields[4], fields[5], None)
        self._us_postal.append(datum)
    self._us_postal = sorted(self._us_postal, key=attrgetter('name'), cmp=locale.strcoll)
    logging.info('parsed %d places from US postal database' % len(self._us_postal)) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:15,代码来源:geoprocessor.py

示例7: test_strcoll

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

示例8: test_strcoll_with_diacritic

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

示例9: test_strcoll_3303

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def test_strcoll_3303(self):
        # test crasher from bug #3303
        self.assertRaises(TypeError, locale.strcoll, "a", None)
        self.assertRaises(TypeError, locale.strcoll, b"a", None) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_locale.py

示例10: sort_for_script

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def sort_for_script(cp_list, script):
    lang = lang_for_script(script)
    if not lang:
        print("cannot sort for script, no lang for %s" % script)
        return cp_list
    if _HAVE_ICU:
        from icu import Locale, Collator

        loc = Locale(lang + "_" + script)
        col = Collator.createInstance(loc)
        return sorted(cp_list, cmp=col.compare)
    else:
        import locale

        return sorted(cp_list, cmp=locale.strcoll) 
开发者ID:googlefonts,项目名称:nototools,代码行数:17,代码来源:generate_sample_from_exemplar.py

示例11: custom_strcoll

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def custom_strcoll(a, b, last=sentinel):
            """strcoll that can handle a sentinel that is always last."""
            if a is last:
                return 0 if a is b else 1
            elif b is last:  # a cannot also be sentinel b/c above logic
                return -1
            else:  # neither are sentinel
                return strcoll(a, b) 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:10,代码来源:locale.py

示例12: test_strcoll

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

示例13: __ColumnSorter

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def __ColumnSorter(self, itemData1, itemData2):
        """Allows custom compare functions, in self.colcmps."""
        col = self._col
        ascending = self._colSortFlag[col]

        if col < len(self.enabled_columns):
            name = self.enabled_columns[col]
        else:
            name = self.column_order[0]

        itemData1 = self.TranslateItemData(itemData1)
        itemData2 = self.TranslateItemData(itemData2)
        item1 = self.itemData_to_row[itemData1][name]
        item2 = self.itemData_to_row[itemData2][name]

        column = self.columns[name]

        if column.comparator != None:
            # use custom cmp method
            cmpVal = column.comparator(item1, item2)
        elif isinstance(item1, str) or isinstance(item2, str):
            # Internationalization of string sorting with locale module
            cmpVal = locale.strcoll(unicode(item1), unicode(item2))
        else:
            cmpVal = cmp(item1, item2)

        # If the items are equal then pick something else to make the sort value unique
        if cmpVal == 0:
            cmpVal = apply(cmp, self.GetSecondarySortValues(col, itemData1, itemData2))

        if ascending:
            return cmpVal
        else:
            return -cmpVal 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:36,代码来源:ListCtrl.py

示例14: view_logs

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def view_logs():
    available_logs = current_service.get_logs()
    available_logs.sort(cmp=lambda x1, x2: locale.strcoll(x1['path'], x2['path']))

    return render_template(
        'logs.html',
        page='logs',
        logs=available_logs,
        is_xhr=request.is_xhr
    ) 
开发者ID:Jahaja,项目名称:psdash,代码行数:12,代码来源:web.py

示例15: archive_deterministically

# 需要导入模块: import locale [as 别名]
# 或者: from locale import strcoll [as 别名]
def archive_deterministically(dir_to_archive, dest_archive, prepend_path=None):
    """Create a .tar.gz archive in a deterministic (reproducible) manner.

    See https://reproducible-builds.org/docs/archives/ for more details."""

    def reset(tarinfo):
        """Helper to reset owner/group and modification time for tar entries"""
        tarinfo.uid = tarinfo.gid = 0
        tarinfo.uname = tarinfo.gname = "root"
        tarinfo.mtime = 0
        return tarinfo

    dest_archive = os.path.abspath(dest_archive)
    with cd(dir_to_archive):
        current_dir = "."
        file_list = [current_dir]
        for root, dirs, files in os.walk(current_dir):
            for name in itertools.chain(dirs, files):
                file_list.append(os.path.join(root, name))

        # Sort file entries with the fixed locale
        with setlocale('C'):
            file_list.sort(cmp=locale.strcoll)

        # Use a temporary file and atomic rename to avoid partially-formed
        # packaging (in case of exceptional situations like running out of disk space).
        # TODO do this in a temporary folder after #11983 is fixed
        temp_file = '{}.temp~'.format(dest_archive)
        with os.fdopen(os.open(temp_file, os.O_WRONLY | os.O_CREAT, 0644), 'w') as out_file:
            with gzip.GzipFile('wb', fileobj=out_file, mtime=0) as gzip_file:
                with tarfile.open(fileobj=gzip_file, mode='w:') as tar_file:
                    for entry in file_list:
                        arcname = entry
                        if prepend_path is not None:
                            arcname = os.path.normpath(os.path.join(prepend_path, arcname))
                        tar_file.add(entry, filter=reset, recursive=False, arcname=arcname)
        os.rename(temp_file, dest_archive) 
开发者ID:paulrouget,项目名称:servoshell,代码行数:39,代码来源:command_base.py


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