ok
Direktori : /proc/self/root/proc/self/root/proc/thread-self/root/lib/python2.7/site-packages/babel/ |
Current File : //proc/self/root/proc/self/root/proc/thread-self/root/lib/python2.7/site-packages/babel/support.pyc |
� ��Mc @ s d Z d d l m Z m Z m Z d d l Z d d l m Z d d l m Z m Z m Z m Z d d l m Z m Z m Z m Z m Z m Z d d l m Z m Z d d d g Z d Z d e f d � � YZ d e f d � � YZ d e j e f d � � YZ d S( s� 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 i����( t datet datetimet timeN( t Locale( t format_datet format_datetimet format_timet LC_TIME( t format_numbert format_decimalt format_currencyt format_percentt format_scientifict LC_NUMERIC( t sett UTCt Formatt LazyProxyt Translationss restructuredtext enc B sz e Z d Z d d � Z d d d � Z d d d � Z d d d � Z d � Z d d � Z d � Z d d � Z d � Z RS( s Wrapper class providing the various date and number formatting functions bound to a specific locale and time-zone. >>> 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 j | � | _ | | _ 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 ( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyt __init__, s t mediumc C s t | | d | j �S( s� Return a date formatted according to the given pattern. >>> fmt = Format('en_US') >>> fmt.date(date(2007, 4, 1)) u'Apr 1, 2007' :see: `babel.dates.format_date` R ( R R ( R R t format( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyR 5 s c C s t | | d | j d | j �S( sH Return a date and time formatted according to the given pattern. >>> 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' :see: `babel.dates.format_datetime` R R ( R R R ( R R R ( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyR @ s c C s t | | d | j d | j �S( s+ Return a time formatted according to the given pattern. >>> 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' :see: `babel.dates.format_time` R R ( R R R ( R R R ( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyR M s c C s t | d | j �S( s� Return an integer number formatted for the locale. >>> fmt = Format('en_US') >>> fmt.number(1099) u'1,099' :see: `babel.numbers.format_number` R ( R R ( R t number( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyR Y s c C s t | | d | j �S( s� Return a decimal number formatted for the locale. >>> fmt = Format('en_US') >>> fmt.decimal(1.2345) u'1.234' :see: `babel.numbers.format_decimal` R ( R R ( R R R ( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyt decimald s c C s t | | d | j �S( s Return a number in the given currency formatted for the locale. :see: `babel.numbers.format_currency` R ( R R ( R R t currency( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyR o s c C s t | | d | j �S( s� Return a number formatted as percentage for the locale. >>> fmt = Format('en_US') >>> fmt.percent(0.34) u'34%' :see: `babel.numbers.format_percent` R ( R R ( R R R ( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyt percentv s c C s t | d | j �S( s� Return a number formatted using scientific notation for the locale. :see: `babel.numbers.format_scientific` R ( R R ( R R ( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyt scientific� s N( t __name__t __module__t __doc__t NoneR R R R R R R R R ( ( ( s1 /usr/lib/python2.7/site-packages/babel/support.pyR ! s c B s( e Z d Z d d d d g Z d � Z d � Z e e � 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 _valuec O sP t j | d | � t j | d | � t j | d | � t j | d d � d S( NR# R$ R% R&