Python locale 模块,strcoll() 实例源码

我们从Python开源项目中,提取了以下32个代码示例,用于说明如何使用locale.strcoll()

项目:PandasDataFrameGUI    作者:bluenote10    | 项目源码 | 文件源码
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
项目:fritzchecksum    作者:mementum    | 项目源码 | 文件源码
def ColumnSorter(self, key1, key2):
        '''In comparison with the original we don't need the column, because the data
        for the specific column has been already gathered and saved along the
        key (item data)
        '''
        ascending = self.sortflags[self.col]
        item1 = self.sortdata[key1]
        item2 = self.sortdata[key2]

        # --- 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 not cmpVal:
            cmpVal = apply(cmp,
                           self.GetSecondarySortValues(self.col, key1, key2))

        return cmpVal if ascending else -cmpVal
项目:QGIS-applications    作者:liaduarte    | 项目源码 | 文件源码
def getLayerNames( vTypes ):
    layermap = QgsMapLayerRegistry.instance().mapLayers()
    layerlist = []
    if vTypes == "all":
        for name, layer in layermap.iteritems():
            layerlist.append( layer.name() )
    else:
        for name, layer in layermap.iteritems():
            if layer.type() == QgsMapLayer.VectorLayer:
                if layer.geometryType() in vTypes:
                    layerlist.append( layer.name() )
            elif layer.type() == QgsMapLayer.RasterLayer:
                if "Raster" in vTypes:
                    layerlist.append( layer.name() )
    return sorted( layerlist, cmp=locale.strcoll )

# Return list of names of all fields from input QgsVectorLayer
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def main():
    # ???????????????????,???????????????.??????????
    # ????????UK????????.
    print(loc.setlocale(loc.LC_ALL, ""))
    # print(loc.currency(350)) # ??????
    print(time.strftime("%x %X", time.localtime()))

    # ?????????????????????????????.
    print("{:n}".format(3.14159))
    print("{:n}".format(42))

    # locale.strcoll()?????????????,?????????????????????.
    # ??????????"?"??,?????1,?????-1,????????,???0
    print(loc.strcoll("Spanish", "Inquisition"))
    print(loc.strcoll("Inquisition", "Spanish"))
    print(loc.strcoll("Spanish", "Spanish"))

    # local???????,???????????????:atoi()?atof()?str()?format()?format_string()
项目:qgis-compactness    作者:gerrymandr    | 项目源码 | 文件源码
def getLayerNames(vTypes):
    layermap = QgsMapLayerRegistry.instance().mapLayers()
    layerlist = []
    if vTypes == "all":
        for name, layer in layermap.iteritems():
            layerlist.append(unicode(layer.name()))
    else:
        for name, layer in layermap.iteritems():
            if layer.type() == QgsMapLayer.VectorLayer:
                if layer.geometryType() in vTypes:
                    layerlist.append(unicode(layer.name()))
            elif layer.type() == QgsMapLayer.RasterLayer:
                if "raster" in vTypes:
                    layerlist.append(unicode(layer.name()))
    return sorted(layerlist, cmp=locale.strcoll)

# Generate a save file dialog with a dropdown box for choosing encoding style
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_category_by_name(categories, untrans_name):
    # find a specific category
    cat = [cat for cat in categories if cat.untranslated_name == untrans_name]
    if cat:
        return cat[0]
    return None


#def categories_sorted_by_name(categories):
    # sort categories by name
#    sorted_catnames = []
    # first pass, sort by translated names
#    for cat in categories:
#        sorted_catnames.append(cat.name)
#    sorted_catnames = sorted(sorted_catnames, cmp=locale.strcoll)

    # second pass, assemble cats by sorted their sorted catnames
#    sorted_cats = []
#    for name in sorted_catnames:
#        for cat in categories:
#            if cat.name == name:
#                sorted_cats.append(cat)
#                break
#    return sorted_cats
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def categories_sorted_by_name(categories):
    # sort categories by name
    sorted_catnames = []
    # first pass, sort by translated names
    for cat in categories:
        sorted_catnames.append(cat.name)
    #sorted_catnames = sorted(sorted_catnames, cmp=locale.strcoll)

    # second pass, assemble cats by sorted their sorted catnames
    sorted_cats = []
    for name in sorted_catnames:
        for cat in categories:
            if cat.name == name:
                sorted_cats.append(cat)
                break
    return sorted_cats
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def categories_sorted_by_name(categories):
    # sort categories by name
    sorted_catnames = []
    # first pass, sort by translated names
    for cat in categories:
        sorted_catnames.append(cat.name)
    #sorted_catnames = sorted(sorted_catnames, cmp=locale.strcoll)

    # second pass, assemble cats by sorted their sorted catnames
    sorted_cats = []
    for name in sorted_catnames:
        for cat in categories:
            if cat.name == name:
                sorted_cats.append(cat)
                break
    return sorted_cats
项目:zing    作者:evernote    | 项目源码 | 文件源码
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([(lang[0], tr_lang(lang[1]))
                        for lang in qs.values_list('code', 'fullname')],
                       cmp=locale.strcoll,
                       key=lambda x: x[1])
            )
            cache.set(key, languages, settings.POOTLE_CACHE_TIMEOUT)

        return languages
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_strcoll_with_diacritic(self):
        self.assertLess(locale.strcoll('à', 'b'), 0)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_strcoll_3303(self):
            # test crasher from bug #3303
            self.assertRaises(TypeError, locale.strcoll, u"a", None)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_strcoll_3303(self):
            # test crasher from bug #3303
            self.assertRaises(TypeError, locale.strcoll, u"a", None)
项目:QGIS-applications    作者:liaduarte    | 项目源码 | 文件源码
def getFieldNames( vlayer ):
    fieldmap = getFieldList( vlayer )
    fieldlist = []
    for field in fieldmap:
        if not field.name() in fieldlist:
            fieldlist.append( field.name() )
    return sorted( fieldlist, cmp=locale.strcoll )

# Return QgsVectorLayer from a layer name ( as string )
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_strcoll_with_diacritic(self):
        self.assertLess(locale.strcoll('à', 'b'), 0)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_strcoll_3303(self):
            # test crasher from bug #3303
            self.assertRaises(TypeError, locale.strcoll, u"a", None)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_strcoll_with_diacritic(self):
        self.assertLess(locale.strcoll('à', 'b'), 0)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_strcoll_3303(self):
            # test crasher from bug #3303
            self.assertRaises(TypeError, locale.strcoll, u"a", None)
项目:servoshell    作者:paulrouget    | 项目源码 | 文件源码
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)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_strcoll_with_diacritic(self):
        self.assertLess(locale.strcoll('à', 'b'), 0)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def apps_cmp(x, y):
        """ sort method for the applications """
        # sort(key=locale.strxfrm) would be more efficient, but its
        # currently broken, see http://bugs.python.org/issue2481
        if x.appname and y.appname:
            return locale.strcoll(x.appname, y.appname)
        elif x.appname:
            return locale.strcoll(x.appname, y.pkgname)
        elif y.appname:
            return locale.strcoll(x.pkgname, y.appname)
        else:
            return cmp(x.pkgname, y.pkgname)


# the details
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _cat_sort_cmp(self, a, b):
        """sort helper for the categories sorting"""
        #print "cmp: ", a.name, b.name
        if a.untranslated_name == "System":
            return 1
        elif b.untranslated_name == "System":
            return -1
        elif a.untranslated_name == "Developer Tools":
            return 1
        elif b.untranslated_name == "Developer Tools":
            return -1
        return locale.strcoll(a.name, b.name)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def apps_cmp(x, y):
        """ sort method for the applications """
        # sort(key=locale.strxfrm) would be more efficient, but its
        # currently broken, see http://bugs.python.org/issue2481
        if x.appname and y.appname:
            return locale.strcoll(x.appname, y.appname)
        elif x.appname:
            return locale.strcoll(x.appname, y.pkgname)
        elif y.appname:
            return locale.strcoll(x.pkgname, y.appname)
        else:
            return cmp(x.pkgname, y.pkgname)


# the details
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _cat_sort_cmp(self, a, b):
        """sort helper for the categories sorting"""
        #print "cmp: ", a.name, b.name
        if a.untranslated_name == "System":
            return 1
        elif b.untranslated_name == "System":
            return -1
        elif a.untranslated_name == "Developer Tools":
            return 1
        elif b.untranslated_name == "Developer Tools":
            return -1
        return locale.strcoll(a.name, b.name)
项目:animalid    作者:alex-dr    | 项目源码 | 文件源码
def test_all_lists_sorted(list_name, list_of_words):
    """All lists are sorted alphabetically."""
    locale.setlocale(locale.LC_ALL, 'C')
    assert sorted(list_of_words, cmp=locale.strcoll) == list_of_words