3 4\0XW @ s d Z ddlZddlZddlmZ ddlmZmZmZm Z ddl mZmZm Z mZmZ ddlmZmZmZ G dd deZG d d d eZG dd dejeZG d d deejZdS )a( babel.support ~~~~~~~~~~~~~ Several classes and functions that help with integrating and using Babel in applications. .. note: the code in this module is not used by Babel itself :copyright: (c) 2013 by the Babel Team. :license: BSD, see LICENSE for more details. N)Locale)format_dateformat_datetimeformat_timeformat_timedelta) format_numberformat_decimalformat_currencyformat_percentformat_scientific)PY2 text_typetext_to_nativec @ sn e Zd ZdZdddZdddZddd Zdd dZdddZdd Z d ddZ dd Zd!ddZdd Z dS )"FormataC Wrapper class providing the various date and number formatting functions bound to a specific locale and time-zone. >>> from babel.util import UTC >>> from datetime import date >>> fmt = Format('en_US', UTC) >>> fmt.date(date(2007, 4, 1)) u'Apr 1, 2007' >>> fmt.decimal(1.2345) u'1.234' Nc C s t j|| _|| _dS )zInitialize the formatter. :param locale: the locale identifier or `Locale` instance :param tzinfo: the time-zone info (a `tzinfo` instance or `None`) N)r parselocaletzinfo)selfr r r /usr/lib/python3.6/support.py__init__' s zFormat.__init__mediumc C s t ||| jdS )zReturn a date formatted according to the given pattern. >>> from datetime import date >>> fmt = Format('en_US') >>> fmt.date(date(2007, 4, 1)) u'Apr 1, 2007' )r )r r )r dateformatr r r r 0 s zFormat.datec C s t ||| j| jdS )a6 Return a date and time formatted according to the given pattern. >>> from datetime import datetime >>> from pytz import timezone >>> fmt = Format('en_US', tzinfo=timezone('US/Eastern')) >>> fmt.datetime(datetime(2007, 4, 1, 15, 30)) u'Apr 1, 2007, 11:30:00 AM' )r r )r r r )r datetimer r r r r : s zFormat.datetimec C s t ||| j| jdS )a Return a time formatted according to the given pattern. >>> from datetime import datetime >>> from pytz import timezone >>> fmt = Format('en_US', tzinfo=timezone('US/Eastern')) >>> fmt.time(datetime(2007, 4, 1, 15, 30)) u'11:30:00 AM' )r r )r r r )r timer r r r r F s zFormat.timesecond333333?Fc C s t |||||| jdS )zReturn a time delta according to the rules of the given locale. >>> from datetime import timedelta >>> fmt = Format('en_US') >>> fmt.timedelta(timedelta(weeks=11)) u'3 months' )granularity thresholdr add_directionr )r r )r Zdeltar r r r r r r timedeltaQ s zFormat.timedeltac C s t || jdS )zReturn an integer number formatted for the locale. >>> fmt = Format('en_US') >>> fmt.number(1099) u'1,099' )r )r r )r numberr r r r" _ s z Format.numberc C s t ||| jdS )zReturn a decimal number formatted for the locale. >>> fmt = Format('en_US') >>> fmt.decimal(1.2345) u'1.234' )r )r r )r r" r r r r decimalh s zFormat.decimalc C s t ||| jdS )zHReturn a number in the given currency formatted for the locale. )r )r r )r r" currencyr r r r$ q s zFormat.currencyc C s t ||| jdS )zReturn a number formatted as percentage for the locale. >>> fmt = Format('en_US') >>> fmt.percent(0.34) u'34%' )r )r r )r r" r r r r percentv s zFormat.percentc C s t || jdS )zLReturn a number formatted using scientific notation for the locale. )r )r r )r r" r r r scientific s zFormat.scientific)N)Nr )Nr )Nr )r r r F)N)N)__name__ __module____qualname____doc__r r r r r! r" r# r$ r% r&