Ñò ž²Hc @s-dZddklZlZlZddkZyeWn#ej oddklZnXddkl Z ddk l Z l Z l Z lZddklZlZlZlZlZlZddklZd d d gZd Zd efd „ƒYZd efd„ƒYZd eiefd„ƒ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(tset(tLocale(t format_datetformat_datetimet format_timetLC_TIME(t format_numbertformat_decimaltformat_currencytformat_percenttformat_scientifict LC_NUMERIC(tUTCtFormatt 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' cCsti|ƒ|_||_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.6/site-packages/babel/support.pyt__init__1stmediumcCst||d|iƒ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.6/site-packages/babel/support.pyR:s cCst||d|id|iƒ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.6/site-packages/babel/support.pyREs cCst||d|id|iƒ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.6/site-packages/babel/support.pyRRs cCst|d|iƒ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(Rtnumber((s1/usr/lib/python2.6/site-packages/babel/support.pyR^s cCst||d|iƒ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.6/site-packages/babel/support.pytdecimalis cCst||d|iƒ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.6/site-packages/babel/support.pyRtscCst||d|iƒ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.6/site-packages/babel/support.pytpercent{s cCst|d|iƒ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.6/site-packages/babel/support.pyt scientific†sN( t__name__t __module__t__doc__tNoneRRRRRRRRR(((s1/usr/lib/python2.6/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_valuecOsPti|d|ƒti|d|ƒti|d|ƒti|ddƒdS(NR#R$R%R&(tobjectt __setattr__R"(Rtfunctargstkwargs((s1/usr/lib/python2.6/site-packages/babel/support.pyR³scCsF|idjo/|i|i|iŽ}ti|d|ƒn|iS(NR&(R&R"R#R$R%R'R((Rtvalue((s1/usr/lib/python2.6/site-packages/babel/support.pyR,ºscCs ||ijS(N(R,(Rtkey((s1/usr/lib/python2.6/site-packages/babel/support.pyt __contains__ÁscCs t|iƒS(N(tboolR,(R((s1/usr/lib/python2.6/site-packages/babel/support.pyt __nonzero__ÄscCs t|iƒS(N(tdirR,(R((s1/usr/lib/python2.6/site-packages/babel/support.pyt__dir__ÇscCs t|iƒS(N(titerR,(R((s1/usr/lib/python2.6/site-packages/babel/support.pyt__iter__ÊscCs t|iƒS(N(tlenR,(R((s1/usr/lib/python2.6/site-packages/babel/support.pyt__len__ÍscCs t|iƒS(N(tstrR,(R((s1/usr/lib/python2.6/site-packages/babel/support.pyt__str__ÐscCs t|iƒS(N(tunicodeR,(R((s1/usr/lib/python2.6/site-packages/babel/support.pyt __unicode__ÓscCs |i|S(N(R,(Rtother((s1/usr/lib/python2.6/site-packages/babel/support.pyt__add__ÖscCs ||iS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__radd__ÙscCs |i|S(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__mod__ÜscCs ||iS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__rmod__ßscCs |i|S(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__mul__âscCs ||iS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__rmul__åscOs|i||ŽS(N(R,(RR*R+((s1/usr/lib/python2.6/site-packages/babel/support.pyt__call__èscCs |i|jS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__lt__ëscCs |i|jS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__le__îscCs |i|jS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__eq__ñscCs |i|jS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__ne__ôscCs |i|jS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__gt__÷scCs |i|jS(N(R,(RR;((s1/usr/lib/python2.6/site-packages/babel/support.pyt__ge__úscCst|i|ƒdS(N(tdelattrR,(Rtname((s1/usr/lib/python2.6/site-packages/babel/support.pyt __delattr__ýscCst|i|ƒS(N(tgetattrR,(RRJ((s1/usr/lib/python2.6/site-packages/babel/support.pyt __getattr__scCst|i||ƒdS(N(tsetattrR,(RRJR,((s1/usr/lib/python2.6/site-packages/babel/support.pyR(scCs|i|=dS(N(R,(RR-((s1/usr/lib/python2.6/site-packages/babel/support.pyt __delitem__scCs |i|S(N(R,(RR-((s1/usr/lib/python2.6/site-packages/babel/support.pyt __getitem__ scCs||i|R?R@RARBRCRDRERFRGRHRKRMR(RORPRQ(((s1/usr/lib/python2.6/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.tmessagescCsMtii|d|ƒtdt|ddƒgƒ|_||_h|_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.6/site-packages/babel/support.pyRs! cCs²|dj oNt|ttfƒp |g}ng}|D]}|t|ƒq;~}n|p |i}nti|||ƒ}|p tiƒ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(tclstdirnametlocalesRZt_[1]Rtfilename((s1/usr/lib/python2.6/site-packages/babel/support.pytload s  +  cCs#dt|ƒi|iidƒfS(Ns <%s: "%s">sproject-id-version(ttypeRt_infotget(R((s1/usr/lib/python2.6/site-packages/babel/support.pyt__repr__8scCst|d|iƒ}|o||ijo|i|ƒS|ii|ƒ}|o|dj o|i|ƒn|i|ƒ||i|<|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[RmR"t add_fallback(Rt translationsRoRZtexisting((s1/usr/lib/python2.6/site-packages/babel/support.pytadd<s  cCsUt|tiƒo>|ii|iƒt|tƒo|ii|iƒqQn|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(RRq((s1/usr/lib/python2.6/site-packages/babel/support.pyRoYs cCs|ii||ƒi|ƒS(sULike ``gettext()``, but look the message up in the specified domain. (R[RmRV(RRZtmessage((s1/usr/lib/python2.6/site-packages/babel/support.pytdgettextlscCs|ii||ƒi|ƒS(sWLike ``lgettext()``, but look the message up in the specified domain. (R[Rmtlgettext(RRZRw((s1/usr/lib/python2.6/site-packages/babel/support.pyt ldgettextrscCs|ii||ƒi|ƒS(sVLike ``ugettext()``, but look the message up in the specified domain. (R[Rmtugettext(RRZRw((s1/usr/lib/python2.6/site-packages/babel/support.pyt dugettextxscCs"|ii||ƒi|||ƒS(sVLike ``ngettext()``, but look the message up in the specified domain. (R[Rmtngettext(RRZtsingulartpluraltnum((s1/usr/lib/python2.6/site-packages/babel/support.pyt dngettext~scCs"|ii||ƒi|||ƒS(sWLike ``lngettext()``, but look the message up in the specified domain. (R[Rmt lngettext(RRZR~RR€((s1/usr/lib/python2.6/site-packages/babel/support.pyt ldngettext„scCs"|ii||ƒi|||ƒS(sVLike ``ungettext()`` but look the message up in the specified domain. (R[Rmt ungettext(RRZR~RR€((s1/usr/lib/python2.6/site-packages/babel/support.pyt dungettextŠsN(RR R!RaR"RRjt classmethodRntTrueRsRoRxRzR|RRƒR…(((s1/usr/lib/python2.6/site-packages/babel/support.pyRs          (R!RRRRVRt NameErrortsetst babel.coreRt babel.datesRRRRt babel.numbersR R R R R Rt babel.utilRt__all__t __docformat__R'RRRWR(((s1/usr/lib/python2.6/site-packages/babel/support.pyts ".h‚