ó ™‚Mc@sdZddlmZmZmZddlZddlmZddlmZm Z m Z m Z ddl m Z mZmZmZmZmZddlmZmZdd d gZd Zdefd „ƒYZd efd „ƒYZd ejefd„ƒYZdS(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ÿÿÿÿ(tdatetdatetimettimeN(tLocale(t format_datetformat_datetimet format_timetLC_TIME(t format_numbertformat_decimaltformat_currencytformat_percenttformat_scientifict LC_NUMERIC(tsettUTCtFormatt LazyProxyt Translationssrestructuredtext encBszeZdZd d„Zd dd„Zd dd„Zd dd„Zd„Zd d„Z d„Z d d „Z d „Z RS( sWrapper 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' cCstj|ƒ|_||_dS(s·Initialize the formatter. :param locale: the locale identifier or `Locale` instance :param tzinfo: the time-zone info (a `tzinfo` instance or `None`) N(Rtparsetlocalettzinfo(tselfRR((s1/usr/lib/python2.7/site-packages/babel/support.pyt__init__,stmediumcCst||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(RR(RRtformat((s1/usr/lib/python2.7/site-packages/babel/support.pyR5s cCst||d|jd|jƒS(sHReturn 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` RR(RRR(RRR((s1/usr/lib/python2.7/site-packages/babel/support.pyR@s cCst||d|jd|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` RR(RRR(RRR((s1/usr/lib/python2.7/site-packages/babel/support.pyRMs cCst|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(RR(Rtnumber((s1/usr/lib/python2.7/site-packages/babel/support.pyRYs cCst||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(RRR((s1/usr/lib/python2.7/site-packages/babel/support.pytdecimalds cCst||d|jƒS(sReturn a number in the given currency formatted for the locale. :see: `babel.numbers.format_currency` R(R R(RRtcurrency((s1/usr/lib/python2.7/site-packages/babel/support.pyRoscCst||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(RRR((s1/usr/lib/python2.7/site-packages/babel/support.pytpercentvs cCst|d|jƒS(s…Return a number formatted using scientific notation for the locale. :see: `babel.numbers.format_scientific` R(R R(RR((s1/usr/lib/python2.7/site-packages/babel/support.pyt scientificsN( t__name__t __module__t__doc__tNoneRRRRRRRRR(((s1/usr/lib/python2.7/site-packages/babel/support.pyR!s      cBs(eZdZddddgZd„Zd„ZeeƒZd„Zd„Zd „Z d „Z d „Z d „Z d „Z d„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd „Z RS(!sClass 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_valuecOsPtj|d|ƒtj|d|ƒtj|d|ƒtj|ddƒdS(NR#R$R%R&(tobjectt __setattr__R"(Rtfunctargstkwargs((s1/usr/lib/python2.7/site-packages/babel/support.pyR®scCsD|jdkr=|j|j|jŽ}tj|d|ƒn|jS(NR&(R&R"R#R$R%R'R((Rtvalue((s1/usr/lib/python2.7/site-packages/babel/support.pyR,µscCs ||jkS(N(R,(Rtkey((s1/usr/lib/python2.7/site-packages/babel/support.pyt __contains__¼scCs t|jƒS(N(tboolR,(R((s1/usr/lib/python2.7/site-packages/babel/support.pyt __nonzero__¿scCs t|jƒS(N(tdirR,(R((s1/usr/lib/python2.7/site-packages/babel/support.pyt__dir__ÂscCs t|jƒS(N(titerR,(R((s1/usr/lib/python2.7/site-packages/babel/support.pyt__iter__ÅscCs t|jƒS(N(tlenR,(R((s1/usr/lib/python2.7/site-packages/babel/support.pyt__len__ÈscCs t|jƒS(N(tstrR,(R((s1/usr/lib/python2.7/site-packages/babel/support.pyt__str__ËscCs t|jƒS(N(tunicodeR,(R((s1/usr/lib/python2.7/site-packages/babel/support.pyt __unicode__ÎscCs |j|S(N(R,(Rtother((s1/usr/lib/python2.7/site-packages/babel/support.pyt__add__ÑscCs ||jS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__radd__ÔscCs |j|S(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__mod__×scCs ||jS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__rmod__ÚscCs |j|S(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__mul__ÝscCs ||jS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__rmul__àscOs|j||ŽS(N(R,(RR*R+((s1/usr/lib/python2.7/site-packages/babel/support.pyt__call__ãscCs |j|kS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__lt__æscCs |j|kS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__le__éscCs |j|kS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__eq__ìscCs |j|kS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__ne__ïscCs |j|kS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__gt__òscCs |j|kS(N(R,(RR;((s1/usr/lib/python2.7/site-packages/babel/support.pyt__ge__õscCst|j|ƒdS(N(tdelattrR,(Rtname((s1/usr/lib/python2.7/site-packages/babel/support.pyt __delattr__øscCst|j|ƒS(N(tgetattrR,(RRJ((s1/usr/lib/python2.7/site-packages/babel/support.pyt __getattr__ûscCst|j||ƒdS(N(tsetattrR,(RRJR,((s1/usr/lib/python2.7/site-packages/babel/support.pyR(þscCs|j|=dS(N(R,(RR-((s1/usr/lib/python2.7/site-packages/babel/support.pyt __delitem__scCs |j|S(N(R,(RR-((s1/usr/lib/python2.7/site-packages/babel/support.pyt __getitem__scCs||j|R?R@RARBRCRDRERFRGRHRKRMR(RORPRQ(((s1/usr/lib/python2.7/site-packages/babel/support.pyR‰s>"                            cBs•eZdZdZd ed„Zd d ed„ZeeƒZd„Ze d„Z d„Z d„Z d„Z d „Zd „Zd „Zd „ZRS(s&An extended translation catalog class.tmessagescCsMtjj|d|ƒtdt|ddƒgƒ|_||_i|_dS(s—Initialize the translations catalog. :param fileobj: the file-like object the translation should be read from tfpRJN( tgettexttGNUTranslationsRtfilterR"RLtfilestdomaint_domains(RtfileobjRZ((s1/usr/lib/python2.7/site-packages/babel/support.pyRs! cCs¢|dk rOt|ttfƒs-|g}ng|D]}t|ƒ^q4}n|sa|j}ntj|||ƒ}|s†tjƒS|dt |dƒd|ƒS(sùLoad translations from the given directory. :param dirname: the directory containing the ``MO`` files :param locales: the list of locales in order of preference (items in this list can be either `Locale` objects or locale strings) :param domain: the message domain :return: the loaded catalog, or a ``NullTranslations`` instance if no matching translations were found :rtype: `Translations` R\trbRZN( R"t isinstancetlistttupleR7tDEFAULT_DOMAINRVtfindtNullTranslationstopen(tclstdirnametlocalesRZRtfilename((s1/usr/lib/python2.7/site-packages/babel/support.pytloads  "  cCs#dt|ƒj|jjdƒfS(Ns <%s: "%s">sproject-id-version(ttypeRt_infotget(R((s1/usr/lib/python2.7/site-packages/babel/support.pyt__repr__3scCs‰t|d|jƒ}|r7||jkr7|j|ƒS|jj|ƒ}|rk|dk rk|j|ƒn|j|ƒ||j|<|S(sµAdd the given translations to the catalog. If the domain of the translations is different than that of the current catalog, they are added as a catalog that is only accessible by the various ``d*gettext`` functions. :param translations: the `Translations` instance with the messages to add :param merge: whether translations for message domains that have already been added should be merged with the existing translations :return: the `Translations` instance (``self``) so that `merge` calls can be easily chained :rtype: `Translations` RZN(RLRaRZtmergeR[RlR"t add_fallback(Rt translationsRnRZtexisting((s1/usr/lib/python2.7/site-packages/babel/support.pytadd7s   cCsQt|tjƒrM|jj|jƒt|tƒrM|jj|jƒqMn|S(sÄMerge the given translations into the catalog. Message translations in the specified catalog override any messages with the same identifier in the existing catalog. :param translations: the `Translations` instance with the messages to merge :return: the `Translations` instance (``self``) so that `merge` calls can be easily chained :rtype: `Translations` (R^RVRWt_catalogtupdateRRYtextend(RRp((s1/usr/lib/python2.7/site-packages/babel/support.pyRnTs cCs|jj||ƒj|ƒS(sULike ``gettext()``, but look the message up in the specified domain. (R[RlRV(RRZtmessage((s1/usr/lib/python2.7/site-packages/babel/support.pytdgettextgscCs|jj||ƒj|ƒS(sWLike ``lgettext()``, but look the message up in the specified domain. (R[Rltlgettext(RRZRv((s1/usr/lib/python2.7/site-packages/babel/support.pyt ldgettextmscCs|jj||ƒj|ƒS(sVLike ``ugettext()``, but look the message up in the specified domain. (R[Rltugettext(RRZRv((s1/usr/lib/python2.7/site-packages/babel/support.pyt dugettextsscCs"|jj||ƒj|||ƒS(sVLike ``ngettext()``, but look the message up in the specified domain. (R[Rltngettext(RRZtsingulartpluraltnum((s1/usr/lib/python2.7/site-packages/babel/support.pyt dngettextyscCs"|jj||ƒj|||ƒS(sWLike ``lngettext()``, but look the message up in the specified domain. (R[Rlt lngettext(RRZR}R~R((s1/usr/lib/python2.7/site-packages/babel/support.pyt ldngettextscCs"|jj||ƒj|||ƒS(sVLike ``ungettext()`` but look the message up in the specified domain. (R[Rlt ungettext(RRZR}R~R((s1/usr/lib/python2.7/site-packages/babel/support.pyt dungettext…sN(RR R!RaR"RRit classmethodRmtTrueRrRnRwRyR{R€R‚R„(((s1/usr/lib/python2.7/site-packages/babel/support.pyR s          (R!RRRRVt babel.coreRt babel.datesRRRRt babel.numbersRR R R R R t babel.utilRRt__all__t __docformat__R'RRRWR(((s1/usr/lib/python2.7/site-packages/babel/support.pyts ".h‚