/usr/lib/python2.6/site-packages/babel
Edit: /usr/lib/python2.6/site-packages/babel/support.pyc (25510B)
zDVc @ s d Z d d k Z d d k Z d d k l Z d d k l Z l Z l Z l Z d d k
l Z l Z l
Z
l Z l Z d d k l Z l Z l Z d e f d YZ d e f d
YZ d e i e f d YZ d
e e i f d YZ d S( s(
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.
iN( t Locale( t format_datet format_datetimet format_timet format_timedelta( t
format_numbert format_decimalt format_currencyt format_percentt format_scientific( t PY2t text_typet text_to_nativet Formatc B s e Z d Z d d Z d d d Z d d d Z d d d Z d d d e d Z d Z
d d
Z d Z d d Z
d
Z RS( sC 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'
c C s t i | | _ | | _ d S( s Initialize the formatter.
:param locale: the locale identifier or `Locale` instance
:param tzinfo: the time-zone info (a `tzinfo` instance or `None`)
N( R t parset localet tzinfo( t selfR R ( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyt __init__' s t mediumc C s t | | d | i S( s Return 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 t datet format( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyR 0 s c C s t | | d | i d | i S( s6 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 t datetimeR ( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyR : s c C s t | | d | i d | i S( s 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 t timeR ( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyR F s t secondg333333?c C s+ t | d | d | d | d | d | i S( s Return 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'
t granularityt thresholdR t
add_directionR ( R R ( R t deltaR R R R ( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyt timedeltaQ s c C s t | d | i S( s Return an integer number formatted for the locale.
>>> fmt = Format('en_US')
>>> fmt.number(1099)
u'1,099'
R ( R R ( R t number( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyR _ s c C s t | | d | i S( s Return a decimal number formatted for the locale.
>>> fmt = Format('en_US')
>>> fmt.decimal(1.2345)
u'1.234'
R ( R R ( R R R ( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyt decimalh s c C s t | | d | i S( sH Return a number in the given currency formatted for the locale.
R ( R R ( R R t currency( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyR q s c C s t | | d | i S( s Return a number formatted as percentage for the locale.
>>> fmt = Format('en_US')
>>> fmt.percent(0.34)
u'34%'
R ( R R ( R R R ( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyt percentv s c C s t | d | i S( sL Return a number formatted using scientific notation for the locale.
R ( R R ( R R ( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyt
scientific s N( t __name__t
__module__t __doc__t NoneR R R R t FalseR R R R R! R" ( ( ( s, /tmp/pip-build-lt8jXN/Babel/babel/support.pyR
s
t LazyProxyc B s% e Z d Z d d d d d g Z d Z e d Z d Z d Z d
Z d Z
d Z d
Z d Z
d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d! Z RS(" s Class for proxy objects that delegate to a specified function to evaluate
the actual object.
>>> def greeting(name='world'):
... return 'Hello, %s!' % name
>>> lazy_greeting = LazyProxy(greeting, name='Joe')
>>> print lazy_greeting
Hello, Joe!
>>> u' ' + lazy_greeting
u' Hello, Joe!'
>>> u'(%s)' % lazy_greeting
u'(Hello, Joe!)'
This can be used, for example, to implement lazy translation functions that
delay the actual translation until the string is actually used. The
rationale for such behavior is that the locale of the user may not always
be available. In web applications, you only know the locale when processing
a request.
The proxy implementation attempts to be as complete as possible, so that
the lazy objects should mostly work as expected, for example for sorting:
>>> greetings = [
... LazyProxy(greeting, 'world'),
... LazyProxy(greeting, 'Joe'),
... LazyProxy(greeting, 'universe'),
... ]
>>> greetings.sort()
>>> for greeting in greetings:
... print greeting
Hello, Joe!
Hello, universe!
Hello, world!
t _funct _argst _kwargst _valuet _is_cache_enabledc O su | i d t } t i | d | t i | d | t i | d | t i | d | t i | d d d S( Nt enable_cacheR) R* R+ R- R, ( t popt Truet objectt __setattr__R&