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

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

项目:gprime    作者:GenealogyCollective    | 项目源码 | 文件源码
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
项目:Frontdown    作者:pfirsich    | 项目源码 | 文件源码
def relativeWalk(path, startPath = None):
    if startPath == None: startPath = path
    # strxfrm -> local aware sorting - https://docs.python.org/3/howto/sorting.html#odd-and-ends
    for entry in sorted(os.scandir(path), key = lambda x: locale.strxfrm(x.name)):
        try:
            #print(entry.path, " ----- ",  entry.name)
            if entry.is_file():
                yield os.path.relpath(entry.path, startPath), False
            elif entry.is_dir():
                yield os.path.relpath(entry.path, startPath), True
                yield from relativeWalk(entry.path, startPath)
            else:
                logging.error("Encountered an object which is neither directory nor file: " + entry.path)
        except OSError as e:
            logging.error(e)

# Possible actions:
# copy (always from source to target),
# delete (always in target)
# hardlink (always from compare directory to target directory)
# rename (always in target) (2-variate) (only needed for move detection)
# hardlink2 (alway from compare directory to target directory) (2-variate) (only needed for move detection)
项目:TACTIC-Handler    作者:listyque    | 项目源码 | 文件源码
def dumb_sort():
        return strxfrm('A') < strxfrm('a')
项目:SDK    作者:Keypirinha    | 项目源码 | 文件源码
def dumb_sort():
        return strxfrm('A') < strxfrm('a')
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_strxfrm(self):
        self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_strxfrm_with_diacritic(self):
        self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_strxfrm(self):
        self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_strxfrm_with_diacritic(self):
        self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_strxfrm(self):
        self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_strxfrm_with_diacritic(self):
        self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_strxfrm(self):
        self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_strxfrm_with_diacritic(self):
        self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
项目:legal    作者:tompecina    | 项目源码 | 文件源码
def test_stripjudge(self):

        cases = (
            ('Žlou?ou?ký P?íliš', 'Žlou?ou?ký P?íliš'),
            ('JUDr. Žlou?ou?ký P?íliš', 'Žlou?ou?ký P?íliš'),
            ('JUDr. Ing. Žlou?ou?ký P?íliš', 'Žlou?ou?ký P?íliš'),
        )

        for test in cases:
            self.assertTrue(
                test[0],
                views.stripjudge({'judge__name': test[0]}) == strxfrm(test[1]))
项目:legal    作者:tompecina    | 项目源码 | 文件源码
def courts(request):

    LOGGER.debug('List of courts accessed', request)
    rows = sorted([{'short': L2S[x], 'name': L2N[x]}
        for x in Vec.objects.values_list('idOsobyPuvodce', flat=True).distinct()], key=lambda x: strxfrm(x['name']))
    return render(
        request,
        'sir_courts.xhtml',
        {'app': APP,
         'page_title': 'P?ehled insolven?ních soud?',
         'rows': rows})
项目:legal    作者:tompecina    | 项目源码 | 文件源码
def render(self, name, value, *args, **kwargs):
        context = {'ins_courts': self.ins_courts, 'value': value}
        if self.ins_courts:
            context['courts'] = sorted(
                [{'id': x, 'name': L2N[x]} for x in Vec.objects.values_list('idOsobyPuvodce', flat=True).distinct()],
                key=lambda x: strxfrm(x['name']))
        else:
            sel = ['VSPHAAB', 'VSSEMOL']
            if self.supreme_court:
                sel.append('NSJIMBM')
            if self.supreme_administrative_court:
                sel.append('NSS')
            high_courts = Court.objects.filter(id__in=sel).order_by('name')
            high_label = (
                'Nejvyšší a vrchní soudy'
                if self.supreme_administrative_court or self.supreme_administrative_court
                else 'Vrchní soudy')
            high_group = {'label': high_label, 'courts': high_courts}
            context['optgroups'] = [high_group]
            reg_courts = (
                Court.objects.filter(id__startswith='KS').union(Court.objects.filter(id='MSPHAAB')).order_by('name'))
            reg_group = {'label': 'Krajské soudy', 'courts': reg_courts}
            context['optgroups'].append(reg_group)
            for reg_court in reg_courts:
                county_courts = sorted(
                    list(Court.objects.filter(reports=reg_court).order_by('name').values('id', 'name')),
                    key=lambda x: strxfrm('Z' if x['name'].endswith('10') else x['name']))
                county_group = {'label': reg_court.name, 'courts': county_courts}
                context['optgroups'].append(county_group)

        return mark_safe(get_template('widgets/select_court.xhtml').render(context))
项目:legal    作者:tompecina    | 项目源码 | 文件源码
def render(self, name, value, *args, **kwargs):
        high_courts = Publisher.objects.filter(type='SOUD', high=True).order_by('name')
        high_courts_label = 'Nejvyšší a vrchní soudy'
        high_courts_group = {'label': high_courts_label, 'publishers': high_courts}
        context = {'optgroups': [high_courts_group]}
        reg_courts = Publisher.objects.filter(type='SOUD', high=False, reports__isnull=True).order_by('name')
        reg_courts_group = {'label': 'Krajské soudy', 'publishers': reg_courts}
        context['optgroups'].append(reg_courts_group)
        for reg_court in reg_courts:
            county_courts = sorted(
                list(Publisher.objects.filter(
                    reports=reg_court,
                    subsidiary_region=False,
                    subsidiary_county=False,
                ).order_by('name').values('id', 'name')),
                key=lambda x: strxfrm('Z' if x['name'].endswith('10') else x['name']))
            county_courts_group = {'label': reg_court.name, 'publishers': county_courts}
            context['optgroups'].append(county_courts_group)
        high_attorneys = Publisher.objects.filter(type='ZAST', high=True).order_by('name')
        high_attorneys_label = 'Nejvyšší a vrchní státní zastupitelství'
        high_attorneys_group = {'label': high_attorneys_label, 'publishers': high_attorneys}
        context['optgroups'].append(high_attorneys_group)
        reg_attorneys = Publisher.objects.filter(type='ZAST', high=False, reports__isnull=True).order_by('name')
        reg_attorneys_group = {'label': 'Krajská státní zastupitelství', 'publishers': reg_attorneys}
        context['optgroups'].append(reg_attorneys_group)
        for reg_attorney in reg_attorneys:
            county_attorneys = sorted(
                list(Publisher.objects.filter(
                    reports=reg_attorney,
                    subsidiary_region=False,
                    subsidiary_county=False,
                ).order_by('name').values('id', 'name')),
                key=lambda x: strxfrm('Z' if x['name'].endswith('10') else x['name']))
            county_attorneys_group = {'label': reg_attorney.name, 'publishers': county_attorneys}
            context['optgroups'].append(county_attorneys_group)

        return mark_safe(get_template('widgets/select_publisher.xhtml').render(context))
项目:legal    作者:tompecina    | 项目源码 | 文件源码
def stripjudge(name):

    return strxfrm(SJ_RE.match(name['judge__name']).group(2))
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __call__(self, doc):
        return locale.strxfrm(
            doc.get_value(self.db._axi_values["display_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 __call__(self, doc):
        return locale.strxfrm(
            doc.get_value(self.db._axi_values["display_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