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

Python dates.parse_pattern函数代码示例

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

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



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

示例1: test_parse_pattern

def test_parse_pattern():
    assert dates.parse_pattern("MMMMd").format == u'%(MMMM)s%(d)s'
    assert (dates.parse_pattern("MMM d, yyyy").format ==
            u'%(MMM)s %(d)s, %(yyyy)s')
    assert (dates.parse_pattern("H:mm' Uhr 'z").format ==
            u'%(H)s:%(mm)s Uhr %(z)s')
    assert dates.parse_pattern("hh' o''clock'").format == u"%(hh)s o'clock"
开发者ID:python-babel,项目名称:babel,代码行数:7,代码来源:test_dates.py


示例2: processFormats

    def processFormats(self, locale, formats):
        '''
        Process the formats to a complete list of formats that will be used by conversion.
        '''
        assert isinstance(formats, dict), 'Invalid formats %s' % formats
        assert isinstance(locale, Locale), 'Invalid locale %s' % locale

        for clsTyp, format in formats.items():
            # In here we just check that the format is valid.
            try:
                if clsTyp in (Number, Percentage): bn.parse_pattern(format)
                elif format not in self.formats[clsTyp]: bd.parse_pattern(format)
            except Exception as e:
                raise FormatError('invalid %s format \'%s\' because: %s' % (clsTyp.__name__, format, str(e)))

        if Number not in formats: formats[Number] = locale.decimal_formats.get(None).pattern
        if Percentage not in formats: formats[Percentage] = locale.percent_formats.get(None).pattern

        for clsTyp, default in self.defaults.items():
            if clsTyp not in formats: formats[clsTyp] = default

        return formats
开发者ID:ahilles107,项目名称:Superdesk,代码行数:22,代码来源:text_conversion.py


示例3: babel2datepicker

def babel2datepicker(pattern):
  """
  Converts date format from babel
  (http://babel.pocoo.org/docs/dates/#date-fields)) to a format understood by
  bootstrap-datepicker.
  """
  if not isinstance(pattern, DateTimePattern):
    pattern = parse_pattern(pattern)

  map_fmt = {
    # days
    'd'    : 'dd',
    'dd'   : 'dd',
    'EEE'  : 'D',
    'EEEE' : 'DD',
    'EEEEE': 'D',  # narrow name => short name
    # months
    'M'   : 'mm',
    'MM'  : 'mm',
    'MMM' : 'M',
    'MMMM': 'MM',
    # years
    'y'   : 'yyyy',
    'yy'  : 'yyyy',
    'yyy' : 'yyyy',
    'yyyy': 'yyyy',

    # time picker format
    # hours
    'h' : '%I',
    'hh': '%I',
    'H' : '%H',
    'HH': '%H',
    # minutes,
    'm' : '%M',
    'mm': '%M',
    # seconds
    's' : '%S',
    'ss': '%S',
    # am/pm
    'a': '%p',

    }

  return pattern.format % map_fmt
开发者ID:mmariani,项目名称:abilian-core,代码行数:45,代码来源:filters.py


示例4: 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


示例5: babel2datepicker

def babel2datepicker(pattern):
    """Convert date format from babel (http://babel.pocoo.org/docs/dates/#date-
    fields)) to a format understood by bootstrap-datepicker."""
    if not isinstance(pattern, DateTimePattern):
        pattern = parse_pattern(pattern)

    map_fmt = {
        # days
        "d": "dd",
        "dd": "dd",
        "EEE": "D",
        "EEEE": "DD",
        "EEEEE": "D",  # narrow name => short name
        # months
        "M": "mm",
        "MM": "mm",
        "MMM": "M",
        "MMMM": "MM",
        # years
        "y": "yyyy",
        "yy": "yyyy",
        "yyy": "yyyy",
        "yyyy": "yyyy",
        # time picker format
        # hours
        "h": "%I",
        "hh": "%I",
        "H": "%H",
        "HH": "%H",
        # minutes,
        "m": "%M",
        "mm": "%M",
        # seconds
        "s": "%S",
        "ss": "%S",
        # am/pm
        "a": "%p",
    }

    return pattern.format % map_fmt
开发者ID:abilian,项目名称:abilian-core,代码行数:40,代码来源:filters.py


示例6: 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


示例7: main


#.........这里部分代码省略.........
                width_type = NAME_MAP[width.tag]
                widths = eras.setdefault(width_type, {})
                for elem in width.getiterator():
                    if elem.tag == 'era':
                        if ('draft' in elem.attrib or 'alt' in elem.attrib) \
                                and int(elem.attrib['type']) in widths:
                            continue
                        widths[int(elem.attrib.get('type'))] = text_type(elem.text)
                    elif elem.tag == 'alias':
                        eras[width_type] = Alias(
                            _translate_alias(['eras', width_type],
                                             elem.attrib['path'])
                        )

            # 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)

            date_formats = data.setdefault('date_formats', {})
            for format in calendar.findall('dateFormats'):
                for elem in format.getiterator():
                    if elem.tag == 'dateFormatLength':
                        if 'draft' in elem.attrib and \
                                elem.attrib.get('type') in date_formats:
                            continue
                        try:
                            date_formats[elem.attrib.get('type')] = \
                                dates.parse_pattern(text_type(
                                    elem.findtext('dateFormat/pattern')))
                        except ValueError as e:
                            error(e)
                    elif elem.tag == 'alias':
                        date_formats = Alias(_translate_alias(
                            ['date_formats'], elem.attrib['path'])
                        )

            time_formats = data.setdefault('time_formats', {})
            for format in calendar.findall('timeFormats'):
                for elem in format.getiterator():
                    if elem.tag == 'timeFormatLength':
                        if ('draft' in elem.attrib or 'alt' in elem.attrib) \
                                and elem.attrib.get('type') in time_formats:
                            continue
                        try:
                            time_formats[elem.attrib.get('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'])
                        )

            datetime_formats = data.setdefault('datetime_formats', {})
            for format in calendar.findall('dateTimeFormats'):
                for elem in format.getiterator():
                    if elem.tag == 'dateTimeFormatLength':
                        if ('draft' in elem.attrib or 'alt' in elem.attrib) \
                                and elem.attrib.get('type') in datetime_formats:
开发者ID:rjollos,项目名称:babel,代码行数:67,代码来源:import_cldr.py


示例8: main


#.........这里部分代码省略.........
            for ctxt in calendar.findall('days/dayContext'):
                ctxt_type = ctxt.attrib['type']
                ctxts = days.setdefault(ctxt_type, {})
                for width in ctxt.findall('dayWidth'):
                    width_type = width.attrib['type']
                    widths = ctxts.setdefault(width_type, {})
                    for elem in width.getiterator():
                        if elem.tag == 'day':
                            dtype = weekdays[elem.attrib['type']]
                            if ('draft' in elem.attrib or 'alt' not in elem.attrib) \
                                    and dtype in widths:
                                continue
                            widths[dtype] = unicode(elem.text)
                        elif elem.tag == 'alias':
                            ctxts[width_type] = Alias(
                                _translate_alias(['days', ctxt_type, width_type],
                                                 elem.attrib['path'])
                            )

            quarters = data.setdefault('quarters', {})
            for ctxt in calendar.findall('quarters/quarterContext'):
                ctxt_type = ctxt.attrib['type']
                ctxts = quarters.setdefault(ctxt.attrib['type'], {})
                for width in ctxt.findall('quarterWidth'):
                    width_type = width.attrib['type']
                    widths = ctxts.setdefault(width_type, {})
                    for elem in width.getiterator():
                        if elem.tag == 'quarter':
                            if ('draft' in elem.attrib or 'alt' in elem.attrib) \
                                    and int(elem.attrib['type']) in widths:
                                continue
                            widths[int(elem.attrib['type'])] = unicode(elem.text)
                        elif elem.tag == 'alias':
                            ctxts[width_type] = Alias(
                                _translate_alias(['quarters', ctxt_type, width_type],
                                                 elem.attrib['path'])
                            )

            eras = data.setdefault('eras', {})
            for width in calendar.findall('eras/*'):
                width_type = NAME_MAP[width.tag]
                widths = eras.setdefault(width_type, {})
                for elem in width.getiterator():
                    if elem.tag == 'era':
                        if ('draft' in elem.attrib or 'alt' in elem.attrib) \
                                and int(elem.attrib['type']) in widths:
                            continue
                        widths[int(elem.attrib.get('type'))] = unicode(elem.text)
                    elif elem.tag == 'alias':
                        eras[width_type] = Alias(
                            _translate_alias(['eras', width_type],
                                             elem.attrib['path'])
                        )

            # AM/PM
            periods = data.setdefault('periods', {})
            for elem in calendar.findall('am'):
                if ('draft' in elem.attrib or 'alt' in elem.attrib) \
                        and elem.tag in periods:
                    continue
                periods[elem.tag] = unicode(elem.text)
            for elem in calendar.findall('pm'):
                if ('draft' in elem.attrib or 'alt' in elem.attrib) \
                        and elem.tag in periods:
                    continue
                periods[elem.tag] = unicode(elem.text)

            date_formats = data.setdefault('date_formats', {})
            for format in calendar.findall('dateFormats'):
                for elem in format.getiterator():
                    if elem.tag == 'dateFormatLength':
                        if 'draft' in elem.attrib and \
                                elem.attrib.get('type') in date_formats:
                            continue
                        try:
                            date_formats[elem.attrib.get('type')] = \
                                dates.parse_pattern(unicode(elem.findtext('dateFormat/pattern')))
                        except ValueError, e:
                            print>>sys.stderr, 'ERROR: %s' % e
                    elif elem.tag == 'alias':
                        date_formats = Alias(_translate_alias(
                            ['date_formats'], elem.attrib['path'])
                        )

            time_formats = data.setdefault('time_formats', {})
            for format in calendar.findall('timeFormats'):
                for elem in format.getiterator():
                    if elem.tag == 'timeFormatLength':
                        if ('draft' in elem.attrib or 'alt' in elem.attrib) \
                                and elem.attrib.get('type') in time_formats:
                            continue
                        try:
                            time_formats[elem.attrib.get('type')] = \
                                dates.parse_pattern(unicode(elem.findtext('timeFormat/pattern')))
                        except ValueError, e:
                            print>>sys.stderr, 'ERROR: %s' % e
                    elif elem.tag == 'alias':
                        time_formats = Alias(_translate_alias(
                            ['time_formats'], elem.attrib['path'])
                        )
开发者ID:cc-archive,项目名称:babel,代码行数:101,代码来源:import_cldr.py


示例9: main


#.........这里部分代码省略.........
                for width in ctxt.findall("monthWidth"):
                    width_type = width.attrib["type"]
                    widths = ctxts.setdefault(width_type, {})
                    for elem in width.getiterator():
                        if elem.tag == "month":
                            if ("draft" in elem.attrib or "alt" in elem.attrib) and int(elem.attrib["type"]) in widths:
                                continue
                            widths[int(elem.attrib.get("type"))] = unicode(elem.text)
                        elif elem.tag == "alias":
                            ctxts[width_type] = Alias(
                                _translate_alias(["months", ctxt_type, width_type], elem.attrib["path"])
                            )

            days = data.setdefault("days", {})
            for ctxt in calendar.findall("days/dayContext"):
                ctxt_type = ctxt.attrib["type"]
                ctxts = days.setdefault(ctxt_type, {})
                for width in ctxt.findall("dayWidth"):
                    width_type = width.attrib["type"]
                    widths = ctxts.setdefault(width_type, {})
                    for elem in width.getiterator():
                        if elem.tag == "day":
                            dtype = weekdays[elem.attrib["type"]]
                            if ("draft" in elem.attrib or "alt" not in elem.attrib) and dtype in widths:
                                continue
                            widths[dtype] = unicode(elem.text)
                        elif elem.tag == "alias":
                            ctxts[width_type] = Alias(
                                _translate_alias(["days", ctxt_type, width_type], elem.attrib["path"])
                            )

            quarters = data.setdefault("quarters", {})
            for ctxt in calendar.findall("quarters/quarterContext"):
                ctxt_type = ctxt.attrib["type"]
                ctxts = quarters.setdefault(ctxt.attrib["type"], {})
                for width in ctxt.findall("quarterWidth"):
                    width_type = width.attrib["type"]
                    widths = ctxts.setdefault(width_type, {})
                    for elem in width.getiterator():
                        if elem.tag == "quarter":
                            if ("draft" in elem.attrib or "alt" in elem.attrib) and int(elem.attrib["type"]) in widths:
                                continue
                            widths[int(elem.attrib["type"])] = unicode(elem.text)
                        elif elem.tag == "alias":
                            ctxts[width_type] = Alias(
                                _translate_alias(["quarters", ctxt_type, width_type], elem.attrib["path"])
                            )

            eras = data.setdefault("eras", {})
            for width in calendar.findall("eras/*"):
                width_type = NAME_MAP[width.tag]
                widths = eras.setdefault(width_type, {})
                for elem in width.getiterator():
                    if elem.tag == "era":
                        if ("draft" in elem.attrib or "alt" in elem.attrib) and int(elem.attrib["type"]) in widths:
                            continue
                        widths[int(elem.attrib.get("type"))] = unicode(elem.text)
                    elif elem.tag == "alias":
                        eras[width_type] = Alias(_translate_alias(["eras", width_type], elem.attrib["path"]))

            # AM/PM
            periods = data.setdefault("periods", {})
            for elem in calendar.findall("am"):
                if ("draft" in elem.attrib or "alt" in elem.attrib) and elem.tag in periods:
                    continue
                periods[elem.tag] = unicode(elem.text)
            for elem in calendar.findall("pm"):
                if ("draft" in elem.attrib or "alt" in elem.attrib) and elem.tag in periods:
                    continue
                periods[elem.tag] = unicode(elem.text)

            date_formats = data.setdefault("date_formats", {})
            for format in calendar.findall("dateFormats"):
                for elem in format.getiterator():
                    if elem.tag == "dateFormatLength":
                        if "draft" in elem.attrib and elem.attrib.get("type") in date_formats:
                            continue
                        try:
                            date_formats[elem.attrib.get("type")] = dates.parse_pattern(
                                unicode(elem.findtext("dateFormat/pattern"))
                            )
                        except ValueError, e:
                            print >>sys.stderr, "ERROR: %s" % e
                    elif elem.tag == "alias":
                        date_formats = Alias(_translate_alias(["date_formats"], elem.attrib["path"]))

            time_formats = data.setdefault("time_formats", {})
            for format in calendar.findall("timeFormats"):
                for elem in format.getiterator():
                    if elem.tag == "timeFormatLength":
                        if ("draft" in elem.attrib or "alt" in elem.attrib) and elem.attrib.get("type") in time_formats:
                            continue
                        try:
                            time_formats[elem.attrib.get("type")] = dates.parse_pattern(
                                unicode(elem.findtext("timeFormat/pattern"))
                            )
                        except ValueError, e:
                            print >>sys.stderr, "ERROR: %s" % e
                    elif elem.tag == "alias":
                        time_formats = Alias(_translate_alias(["time_formats"], elem.attrib["path"]))
开发者ID:h4ck3rm1k3,项目名称:Babel-CLDR,代码行数:101,代码来源:import_cldr.py


示例10: main


#.........这里部分代码省略.........
                            widths[int(elem.attrib["type"])] = text_type(elem.text)
                        elif elem.tag == "alias":
                            ctxts[width_type] = Alias(
                                _translate_alias(["quarters", ctxt_type, width_type], elem.attrib["path"])
                            )

            eras = data.setdefault("eras", {})
            for width in calendar.findall("eras/*"):
                width_type = NAME_MAP[width.tag]
                widths = eras.setdefault(width_type, {})
                for elem in width.getiterator():
                    if elem.tag == "era":
                        if ("draft" in elem.attrib or "alt" in elem.attrib) and int(elem.attrib["type"]) in widths:
                            continue
                        widths[int(elem.attrib.get("type"))] = text_type(elem.text)
                    elif elem.tag == "alias":
                        eras[width_type] = Alias(_translate_alias(["eras", width_type], elem.attrib["path"]))

            # 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)

            date_formats = data.setdefault("date_formats", {})
            for format in calendar.findall("dateFormats"):
                for elem in format.getiterator():
                    if elem.tag == "dateFormatLength":
                        if "draft" in elem.attrib and elem.attrib.get("type") in date_formats:
                            continue
                        try:
                            date_formats[elem.attrib.get("type")] = dates.parse_pattern(
                                text_type(elem.findtext("dateFormat/pattern"))
                            )
                        except ValueError as e:
                            error(e)
                    elif elem.tag == "alias":
                        date_formats = Alias(_translate_alias(["date_formats"], elem.attrib["path"]))

            time_formats = data.setdefault("time_formats", {})
            for format in calendar.findall("timeFormats"):
                for elem in format.getiterator():
                    if elem.tag == "timeFormatLength":
                        if ("draft" in elem.attrib or "alt" in elem.attrib) and elem.attrib.get("type") in time_formats:
                            continue
                        try:
                            time_formats[elem.attrib.get("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"]))

            datetime_formats = data.setdefault("datetime_formats", {})
            for format in calendar.findall("dateTimeFormats"):
                for elem in format.getiterator():
                    if elem.tag == "dateTimeFormatLength":
                        if ("draft" in elem.attrib or "alt" in elem.attrib) and elem.attrib.get(
                            "type"
                        ) in datetime_formats:
                            continue
                        try:
                            datetime_formats[elem.attrib.get("type")] = text_type(
开发者ID:josephbreihan,项目名称:babel,代码行数:67,代码来源:import_cldr.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python localedata.exists函数代码示例发布时间:2022-05-24
下一篇:
Python dates.get_timezone函数代码示例发布时间: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