• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python _compat.text_type函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中babel._compat.text_type函数的典型用法代码示例。如果您正苦于以下问题:Python text_type函数的具体用法?Python text_type怎么用?Python text_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: parse_decimal_formats

def parse_decimal_formats(data, tree):
    decimal_formats = data.setdefault('decimal_formats', {})
    for df_elem in tree.findall('.//decimalFormats'):
        if _should_skip_number_elem(data, df_elem):  # TODO: Support other number systems
            continue
        for elem in df_elem.findall('./decimalFormatLength'):
            length_type = elem.attrib.get('type')
            if _should_skip_elem(elem, length_type, decimal_formats):
                continue
            if elem.findall('./alias'):
                # TODO map the alias to its target
                continue
            for pattern_el in elem.findall('./decimalFormat/pattern'):
                pattern_type = pattern_el.attrib.get('type')
                pattern = numbers.parse_pattern(text_type(pattern_el.text))
                if pattern_type:
                    # This is a compact decimal format, see:
                    # https://www.unicode.org/reports/tr35/tr35-45/tr35-numbers.html#Compact_Number_Formats

                    # These are mapped into a `compact_decimal_formats` dictionary
                    # with the format {length: {count: {multiplier: pattern}}}.

                    # TODO: Add support for formatting them.
                    compact_decimal_formats = data.setdefault('compact_decimal_formats', {})
                    length_map = compact_decimal_formats.setdefault(length_type, {})
                    length_count_map = length_map.setdefault(pattern_el.attrib['count'], {})
                    length_count_map[pattern_type] = pattern
                else:
                    # Regular decimal format.
                    decimal_formats[length_type] = pattern
开发者ID:Changaco,项目名称:babel,代码行数:30,代码来源:import_cldr.py


示例2: parse_currency_formats

def parse_currency_formats(data, tree):
    currency_formats = data.setdefault('currency_formats', {})
    for currency_format in tree.findall('.//currencyFormats'):
        if _should_skip_number_elem(data, currency_format):  # TODO: Support other number systems
            continue

        for length_elem in currency_format.findall('./currencyFormatLength'):
            curr_length_type = length_elem.attrib.get('type')
            for elem in length_elem.findall('currencyFormat'):
                type = elem.attrib.get('type')
                if curr_length_type:
                    # Handle `<currencyFormatLength type="short">`, etc.
                    # TODO(3.x): use nested dicts instead of colon-separated madness
                    type = '%s:%s' % (type, curr_length_type)
                if _should_skip_elem(elem, type, currency_formats):
                    continue
                for child in elem.getiterator():
                    if child.tag == 'alias':
                        currency_formats[type] = Alias(
                            _translate_alias(['currency_formats', elem.attrib['type']],
                                             child.attrib['path'])
                        )
                    elif child.tag == 'pattern':
                        pattern = text_type(child.text)
                        currency_formats[type] = numbers.parse_pattern(pattern)
开发者ID:Changaco,项目名称:babel,代码行数:25,代码来源:import_cldr.py


示例3: parse_unit_patterns

def parse_unit_patterns(data, tree):
    unit_patterns = data.setdefault('unit_patterns', {})
    for elem in tree.findall('.//units/unitLength'):
        unit_length_type = elem.attrib['type']
        for unit in elem.findall('unit'):
            unit_type = unit.attrib['type']
            for pattern in unit.findall('unitPattern'):
                box = unit_type
                box += ':' + unit_length_type
                unit_patterns.setdefault(box, {})[pattern.attrib['count']] = text_type(pattern.text)

        for unit in elem.findall('compoundUnit'):
            unit_type = unit.attrib['type']
            for pattern in unit.findall('compoundUnitPattern'):
                box = 'compound:' + unit_type
                box += ':' + unit_length_type
                unit_patterns[box] = text_type(pattern.text)
开发者ID:alexbodn,项目名称:babel,代码行数:17,代码来源:import_cldr.py


示例4: parse_percent_formats

def parse_percent_formats(data, tree):
    percent_formats = data.setdefault('percent_formats', {})
    for elem in tree.findall('.//percentFormats/percentFormatLength'):
        type = elem.attrib.get('type')
        if _should_skip_elem(elem, type, percent_formats):
            continue
        pattern = text_type(elem.findtext('percentFormat/pattern'))
        percent_formats[type] = numbers.parse_pattern(pattern)
开发者ID:jtwang,项目名称:babel,代码行数:8,代码来源:import_cldr.py


示例5: parse_currency_names

def parse_currency_names(data, tree):
    currency_names = data.setdefault('currency_names', {})
    currency_names_plural = data.setdefault('currency_names_plural', {})
    currency_symbols = data.setdefault('currency_symbols', {})
    for elem in tree.findall('.//currencies/currency'):
        code = elem.attrib['type']
        for name in elem.findall('displayName'):
            if ('draft' in name.attrib) and code in currency_names:
                continue
            if 'count' in name.attrib:
                currency_names_plural.setdefault(code, {})[
                    name.attrib['count']] = text_type(name.text)
            else:
                currency_names[code] = text_type(name.text)
        # TODO: support choice patterns for currency symbol selection
        symbol = elem.find('symbol')
        if symbol is not None and 'draft' not in symbol.attrib and 'choice' not in symbol.attrib:
            currency_symbols[code] = text_type(symbol.text)
开发者ID:jtwang,项目名称:babel,代码行数:18,代码来源:import_cldr.py


示例6: parse_currency_unit_patterns

def parse_currency_unit_patterns(data, tree):
    currency_unit_patterns = data.setdefault('currency_unit_patterns', {})
    for currency_formats_elem in tree.findall('.//currencyFormats'):
        if _should_skip_number_elem(data, currency_formats_elem):  # TODO: Support other number systems
            continue
        for unit_pattern_elem in currency_formats_elem.findall('./unitPattern'):
            count = unit_pattern_elem.attrib['count']
            pattern = text_type(unit_pattern_elem.text)
            currency_unit_patterns[count] = pattern
开发者ID:Changaco,项目名称:babel,代码行数:9,代码来源:import_cldr.py


示例7: parse_date_fields

def parse_date_fields(data, tree):
    date_fields = data.setdefault('date_fields', {})
    for elem in tree.findall('.//dates/fields/field'):
        field_type = elem.attrib['type']
        date_fields.setdefault(field_type, {})
        for rel_time in elem.findall('relativeTime'):
            rel_time_type = rel_time.attrib['type']
            for pattern in rel_time.findall('relativeTimePattern'):
                type_dict = date_fields[field_type].setdefault(rel_time_type, {})
                type_dict[pattern.attrib['count']] = text_type(pattern.text)
开发者ID:jtwang,项目名称:babel,代码行数:10,代码来源:import_cldr.py


示例8: parse_number_symbols

def parse_number_symbols(data, tree):
    number_symbols = data.setdefault('number_symbols', {})
    for symbol_elem in tree.findall('.//numbers/symbols'):
        if _should_skip_number_elem(data, symbol_elem):  # TODO: Support other number systems
            continue

        for elem in symbol_elem.findall('./*'):
            if _should_skip_elem(elem):
                continue
            number_symbols[elem.tag] = text_type(elem.text)
开发者ID:Changaco,项目名称:babel,代码行数:10,代码来源:import_cldr.py


示例9: parse_decimal_formats

def parse_decimal_formats(data, tree):
    decimal_formats = data.setdefault('decimal_formats', {})
    for elem in tree.findall('.//decimalFormats/decimalFormatLength'):
        type = elem.attrib.get('type')
        if _should_skip_elem(elem, type, decimal_formats):
            continue
        if elem.findall('./alias'):
            # TODO map the alias to its target
            continue
        pattern = text_type(elem.findtext('./decimalFormat/pattern'))
        decimal_formats[type] = numbers.parse_pattern(pattern)
开发者ID:jtwang,项目名称:babel,代码行数:11,代码来源:import_cldr.py


示例10: _extract_plural_rules

def _extract_plural_rules(file_path):
    rule_dict = {}
    prsup = parse(file_path)
    for elem in prsup.findall('.//plurals/pluralRules'):
        rules = []
        for rule in elem.findall('pluralRule'):
            rules.append((rule.attrib['count'], text_type(rule.text)))
        pr = PluralRule(rules)
        for locale in elem.attrib['locales'].split():
            rule_dict[locale] = pr
    return rule_dict
开发者ID:jtwang,项目名称:babel,代码行数:11,代码来源:import_cldr.py


示例11: _set_locale

    def _set_locale(self, locale):
        if locale is None:
            self._locale_identifier = None
            self._locale = None
            return

        if isinstance(locale, Locale):
            self._locale_identifier = text_type(locale)
            self._locale = locale
            return

        if isinstance(locale, string_types):
            self._locale_identifier = text_type(locale)
            try:
                self._locale = Locale.parse(locale)
            except UnknownLocaleError:
                self._locale = None
            return

        raise TypeError('`locale` must be a Locale, a locale identifier string, or None; got %r' % locale)
开发者ID:JonathanRRogers,项目名称:babel,代码行数:20,代码来源:catalog.py


示例12: parse_currency_names

def parse_currency_names(data, tree):
    currency_names = data.setdefault('currency_names', {})
    currency_names_plural = data.setdefault('currency_names_plural', {})
    currency_symbols = data.setdefault('currency_symbols', {})
    for elem in tree.findall('.//currencies/currency'):
        code = elem.attrib['type']
        for name in elem.findall('displayName'):
            if ('draft' in name.attrib) and code in currency_names:
                continue
            if 'count' in name.attrib:
                currency_names_plural.setdefault(code, {})[
                    name.attrib['count']] = text_type(name.text)
            else:
                currency_names[code] = text_type(name.text)
        for symbol in elem.findall('symbol'):
            if 'draft' in symbol.attrib or 'choice' in symbol.attrib:  # Skip drafts and choice-patterns
                continue
            if symbol.attrib.get('alt'):  # Skip alternate forms
                continue
            currency_symbols[code] = text_type(symbol.text)
开发者ID:Changaco,项目名称:babel,代码行数:20,代码来源:import_cldr.py


示例13: parse_scientific_formats

def parse_scientific_formats(data, tree):
    scientific_formats = data.setdefault('scientific_formats', {})
    for sf_elem in tree.findall('.//scientificFormats'):
        if _should_skip_number_elem(data, sf_elem):  # TODO: Support other number systems
            continue
        for elem in sf_elem.findall('./scientificFormatLength'):
            type = elem.attrib.get('type')
            if _should_skip_elem(elem, type, scientific_formats):
                continue
            pattern = text_type(elem.findtext('scientificFormat/pattern'))
            scientific_formats[type] = numbers.parse_pattern(pattern)
开发者ID:Changaco,项目名称:babel,代码行数:11,代码来源:import_cldr.py


示例14: parse_calendar_periods

def parse_calendar_periods(data, calendar):
    # AM/PM
    periods = data.setdefault('periods', {})
    for day_period_width in calendar.findall(
        'dayPeriods/dayPeriodContext/dayPeriodWidth'
    ):
        if day_period_width.attrib['type'] == 'wide':
            for day_period in day_period_width.findall('dayPeriod'):
                if 'alt' not in day_period.attrib:
                    periods[day_period.attrib['type']] = text_type(
                        day_period.text)
开发者ID:lukas-b,项目名称:babel,代码行数:11,代码来源:import_cldr.py


示例15: parse_calendar_periods

def parse_calendar_periods(data, calendar):
    # Day periods (AM/PM/others)
    periods = data.setdefault('day_periods', {})
    for day_period_ctx in calendar.findall('dayPeriods/dayPeriodContext'):
        ctx_type = day_period_ctx.attrib["type"]
        for day_period_width in day_period_ctx.findall('dayPeriodWidth'):
            width_type = day_period_width.attrib["type"]
            dest_dict = periods.setdefault(ctx_type, {}).setdefault(width_type, {})
            for day_period in day_period_width.findall('dayPeriod'):
                period_type = day_period.attrib['type']
                if 'alt' not in day_period.attrib:
                    dest_dict[period_type] = text_type(day_period.text)
开发者ID:jtwang,项目名称:babel,代码行数:12,代码来源:import_cldr.py


示例16: unpgettext

    def unpgettext(self, context, singular, plural, num):
        """Do a plural-forms lookup of a message id.  `singular` is used as the
        message id for purposes of lookup in the catalog, while `num` is used to
        determine which plural form to use.  The returned message string is a
        Unicode string.

        If the message id for `context` is not found in the catalog, and a
        fallback is specified, the request is forwarded to the fallback's
        ``unpgettext()`` method.  Otherwise, when `num` is 1 `singular` is
        returned, and `plural` is returned in all other cases.
        """
        ctxt_message_id = self.CONTEXT_ENCODING % (context, singular)
        try:
            tmsg = self._catalog[(ctxt_message_id, self.plural(num))]
        except KeyError:
            if self._fallback:
                return self._fallback.unpgettext(context, singular, plural, num)
            if num == 1:
                tmsg = text_type(singular)
            else:
                tmsg = text_type(plural)
        return tmsg
开发者ID:AaronJaramillo,项目名称:shopDPM,代码行数:22,代码来源:support.py


示例17: parse_calendar_datetime_skeletons

def parse_calendar_datetime_skeletons(data, calendar):
    datetime_formats = data.setdefault('datetime_formats', {})
    datetime_skeletons = data.setdefault('datetime_skeletons', {})
    for format in calendar.findall('dateTimeFormats'):
        for elem in format.getiterator():
            if elem.tag == 'dateTimeFormatLength':
                type = elem.attrib.get('type')
                if _should_skip_elem(elem, type, datetime_formats):
                    continue
                try:
                    datetime_formats[type] = text_type(elem.findtext('dateTimeFormat/pattern'))
                except ValueError as e:
                    error(e)
            elif elem.tag == 'alias':
                datetime_formats = Alias(_translate_alias(
                    ['datetime_formats'], elem.attrib['path'])
                )
            elif elem.tag == 'availableFormats':
                for datetime_skeleton in elem.findall('dateFormatItem'):
                    datetime_skeletons[datetime_skeleton.attrib['id']] = (
                        dates.parse_pattern(text_type(datetime_skeleton.text))
                    )
开发者ID:jtwang,项目名称:babel,代码行数:22,代码来源:import_cldr.py


示例18: upgettext

 def upgettext(self, context, message):
     """Look up the `context` and `message` id in the catalog and return the
     corresponding message string, as a Unicode string.  If there is no entry
     in the catalog for the `message` id and `context`, and a fallback has
     been set, the look up is forwarded to the fallback's ``upgettext()``
     method.  Otherwise, the `message` id is returned.
     """
     ctxt_message_id = self.CONTEXT_ENCODING % (context, message)
     missing = object()
     tmsg = self._catalog.get(ctxt_message_id, missing)
     if tmsg is missing:
         if self._fallback:
             return self._fallback.upgettext(context, message)
         return text_type(message)
     return tmsg
开发者ID:AaronJaramillo,项目名称:shopDPM,代码行数:15,代码来源:support.py


示例19: parse_calendar_time_formats

def parse_calendar_time_formats(data, calendar):
    time_formats = data.setdefault('time_formats', {})
    for format in calendar.findall('timeFormats'):
        for elem in format.getiterator():
            if elem.tag == 'timeFormatLength':
                type = elem.attrib.get('type')
                if _should_skip_elem(elem, type, time_formats):
                    continue
                try:
                    time_formats[type] = dates.parse_pattern(
                        text_type(elem.findtext('timeFormat/pattern'))
                    )
                except ValueError as e:
                    error(e)
            elif elem.tag == 'alias':
                time_formats = Alias(_translate_alias(
                    ['time_formats'], elem.attrib['path'])
                )
开发者ID:jtwang,项目名称:babel,代码行数:18,代码来源:import_cldr.py


示例20: parse_currency_formats

def parse_currency_formats(data, tree):
    currency_formats = data.setdefault('currency_formats', {})
    for length_elem in tree.findall('.//currencyFormats/currencyFormatLength'):
        curr_length_type = length_elem.attrib.get('type')
        for elem in length_elem.findall('currencyFormat'):
            type = elem.attrib.get('type')
            if curr_length_type:
                # Handle `<currencyFormatLength type="short">`, etc.
                type = '%s:%s' % (type, curr_length_type)
            if _should_skip_elem(elem, type, currency_formats):
                continue
            for child in elem.getiterator():
                if child.tag == 'alias':
                    currency_formats[type] = Alias(
                        _translate_alias(['currency_formats', elem.attrib['type']],
                                         child.attrib['path'])
                    )
                elif child.tag == 'pattern':
                    pattern = text_type(child.text)
                    currency_formats[type] = numbers.parse_pattern(pattern)
开发者ID:jtwang,项目名称:babel,代码行数:20,代码来源:import_cldr.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python _compat.BytesIO类代码示例发布时间:2022-05-24
下一篇:
Python babel.Locale类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap