Ñò ž²Hc@stdZddklZddklZddklZddklZddklZddk Z ye Wn#e j oddk l Z nXddkZdd klZdd klZdd klZdd klZdd klZlZlZlZlZdddgZdZe i dƒZ!de"fd„ƒYZ#de$fd„ƒYZ%dZ&de"fd„ƒYZ'dS(s%Data structures for message catalogs.iÿÿÿÿ(t parse_header(tdatetime(tget_close_matches(tmessage_from_string(tcopyN(tSet(t __version__(tLocale(tformat_datetime(t get_plural(todicttdistincttLOCALTZtUTCtFixedOffsetTimezonetMessagetCatalogtTranslationErrorsrestructuredtext ens¬(?x) \% (?:\(([\w]*)\))? ( [-#0\ +]?(?:\*|[\d]+)? (?:\.(?:\*|[\d]+))? [hlL]? ) ([diouxXeEfFgGcrs%]) cBs¤eZdZdddddddd„Zd„Zd„Zd„Zdd„Zd„Z e e dd ƒZ d „Z e e dd ƒZ d „Z e e dd ƒZ RS(s0Representation of a single message in a catalog.uc Csí||_| o|io d}n||_tt|ƒƒ|_t|ƒ|_|o|io|ii dƒn|ii dƒtt|ƒƒ|_ tt|ƒƒ|_ t |tƒo|g|_nt|ƒ|_||_dS(s4Create the message object. :param id: the message ID, or a ``(singular, plural)`` tuple for pluralizable messages :param string: the translated message string, or a ``(singular, plural)`` tuple for pluralizable messages :param locations: a sequence of ``(filenname, lineno)`` tuples :param flags: a set or sequence of flags :param auto_comments: a sequence of automatic comments for the message :param user_comments: a sequence of user comments for the message :param previous_id: the previous message ID, or a ``(singular, plural)`` tuple for pluralizable messages :param lineno: the line number on which the msgid line was found in the PO file, if any us python-formatN(uu(tidt pluralizabletstringtlistR t locationstsettflagst python_formattaddtdiscardt auto_commentst user_commentst isinstancet basestringt previous_idtlineno( tselfRRRRRRR R!((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt__init__5s   cCs&dt|ƒi|it|iƒfS(Ns<%s %r (flags: %r)>(ttypet__name__RRR(R"((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt__repr__XscCs¡t|tƒo~|i}|i}|o#|ot|id|idƒS|ot|id|iƒS|ot|i|idƒSnt|i|iƒS(s0Compare Messages, taking into account plural idsi(RRRtcmpR(R"tobjtpluralt obj_plural((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt__cmp__\s  c CsCttt|i|i|i|i|i|i|i |i fƒŒS(N( RtmapRRRRRRRR R!(R"((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pytcloneis  cCsaddkl}g}xD|D]<}y|||ƒWqtj o}|i|ƒqXqW|S(s•Run various validation checks on the message. Some validations are only performed if the catalog is provided. This method returns a sequence of `TranslationError` objects. :rtype: ``iterator`` :param catalog: A catalog instance that is passed to the checkers :see: `Catalog.check` for a way to perform checks for all messages in a catalog. iÿÿÿÿ(tcheckers(tbabel.messages.checkersR.Rtappend(R"tcatalogR.terrorstcheckerte((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pytcheckos cCs d|ijS(Ntfuzzy(R(R"((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyR6‚stdocs Whether the translation is fuzzy. >>> Message('foo').fuzzy False >>> msg = Message('foo', 'foo', flags=['fuzzy']) >>> msg.fuzzy True >>> msg :type: `bool` cCst|ittfƒS(N(RRRttuple(R"((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyR’ssÀ Whether the message is plurizable. >>> Message('foo').pluralizable False >>> Message(('foo', 'bar')).pluralizable True :type: `bool` cCsc|i}t|ttfƒp |g}nttdg}|D]}|ti|ƒq@~ƒƒS(N( RRRR8tbooltfiltertNonet PYTHON_FORMATtsearch(R"tidst_[1]R((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyRŸs  só Whether the message contains Python-style parameters. >>> Message('foo %(name)s bar').python_format True >>> Message(('foo %(name)s', 'foo %(name)s')).python_format True :type: `bool` (((((N( R%t __module__t__doc__R;R#R&R+R-R5R6tpropertyRR(((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyR2s  "         cBseZdZRS(s_Exception thrown by translation checkers when invalid message translations are encountered.(R%R@RA(((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyR°su¸# Translations template for PROJECT. # Copyright (C) YEAR ORGANIZATION # This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR , YEAR. #cBsXeZdZddeddddddddded„ Zd„Zd„Ze eeddƒZ d„Z d„Z e e e dd ƒZ d „Ze edd ƒZd „Ze edd ƒZd„Ze eddƒZd„Zd„Zd„Zd„Zd„Zd„Zd„Zdddddd dd„Zd„Zed„Zd„ZRS(!s$Representation of a message catalog.sutf-8cCs||_|oti|ƒ}n||_||_tƒ|_|pd|_|pd|_|pd|_ |pd|_ | pd|_ | pd|_ | pd|_ |d jotitƒ}n2t|tƒo!|i o|idtƒ}n||_| d jotitƒ} n2t| tƒo!| i o| idtƒ} n| |_| |_tƒ|_d |_d |_d S( s0Initialize the catalog object. :param locale: the locale identifier or `Locale` object, or `None` if the catalog is not bound to a locale (which basically means it's a template) :param domain: the message domain :param header_comment: the header comment as string, or `None` for the default header :param project: the project's name :param version: the project's version :param copyright_holder: the copyright holder of the catalog :param msgid_bugs_address: the email address or URL to submit bug reports to :param creation_date: the date the catalog was created :param revision_date: the date the catalog was revised :param last_translator: the name and email of the last translator :param language_team: the name and email of the language team :param charset: the encoding to use in the output :param fuzzy: the fuzzy bit on the catalog header tPROJECTtVERSIONt ORGANIZATIONs EMAIL@ADDRESSsFULL NAME sLANGUAGE sutf-8ttzinfoN(tdomainRtparsetlocalet_header_commentR t _messagestprojecttversiontcopyright_holdertmsgid_bugs_addresstlast_translatort language_teamtcharsetR;RtnowR RRFtreplacet creation_datet revision_dateR6tobsoletet _num_pluralst _plural_expr(R"RIRGtheader_commentRLRMRNRORURVRPRQRRR6((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyR#Às6           cCs‚|i}|id|iƒid|iƒid|iidƒƒid|iƒ}|io |idd|iiƒ}n|S(NRCRDtYEARs%YREsTranslations templates%s translations( RJRTRLRMRVtstrftimeRNRIt english_name(R"tcomment((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt_get_header_commentüs   cCs ||_dS(N(RJ(R"R((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt_set_header_commentsR7sƒ The header comment for the catalog. >>> catalog = Catalog(project='Foobar', version='1.0', ... copyright_holder='Foo Company') >>> print catalog.header_comment #doctest: +ELLIPSIS # Translations template for Foobar. # Copyright (C) ... Foo Company # This file is distributed under the same license as the Foobar project. # FIRST AUTHOR , .... # The header can also be set from a string. Any known upper-case variables will be replaced when the header is retrieved again: >>> catalog = Catalog(project='Foobar', version='1.0', ... copyright_holder='Foo Company') >>> catalog.header_comment = '''\ ... # The POT for my really cool PROJECT project. ... # Copyright (C) 1990-2003 ORGANIZATION ... # This file is distributed under the same license as the PROJECT ... # project. ... #''' >>> print catalog.header_comment # The POT for my really cool Foobar project. # Copyright (C) 1990-2003 Foo Company # This file is distributed under the same license as the Foobar # project. # :type: `unicode` cCsjg}|idd|i|iffƒ|id|ifƒ|idt|idddƒfƒ|idjo+|idƒ|idƒ|idƒn}|idt|idddƒfƒ|id |i fƒ|id |i i dt |iƒƒfƒ|id|i fƒ|idƒ|idd|ifƒ|idƒ|iddtfƒ|S(NsProject-Id-Versions%s %ssReport-Msgid-Bugs-TosPOT-Creation-Datesyyyy-MM-dd HH:mmZRItensPO-Revision-DatesYEAR-MO-DA HO:MI+ZONEsLast-TranslatorsFULL NAME s Language-TeamsLANGUAGE tLANGUAGEs Plural-Formss MIME-Versions1.0s Content-Typestext/plain; charset=%ssContent-Transfer-Encodingt8bits Generated-Bys Babel %s (sPO-Revision-DatesYEAR-MO-DA HO:MI+ZONE(sLast-TranslatorsFULL NAME (s Language-TeamsLANGUAGE (s MIME-Versions1.0(sContent-Transfer-EncodingRc(R0RLRMRORRURIR;RVRPRQRTtstrt plural_formsRRRD(R"theaders((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt_get_mime_headers+s2            c Cs.xb|D]Z\}}|iƒdjo;t|ƒ\}}d|jo|diƒ|_nPqqWxÂ|D]º\}}|iƒi|iƒ}|i|iƒ}|djo6|idƒ}di|d ƒ|_|d|_ql|djo ||_ql|djo ||_ ql|d jo ||_ ql|d joJtd |ƒ\}}t |i d d ƒƒ|_ |i ddƒ|_ql|djotid|dƒ\}}}ti|dƒ} ti| ƒ} tt |d ƒdt |d ƒƒ}ti| ƒ} | id|ƒ|_qlqlWdS(Ns content-typeRRsproject-id-versiont u iÿÿÿÿsreport-msgid-bugs-toslast-translators language-teams plural-formss ;tnpluralsiR)s(n != 1)spot-creation-dates [+-](\d{4})$is%Y-%m-%d %H:%Mi<RF(tlowerRRRtdecodetsplittjoinRLRMRORPRQtinttgetRXRYtrettimetstrptimetmktimeRRt fromtimestampRTRU( R"Rftnametvaluetmimetypetparamstpartst_ttzoffsettttttstdt((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt_set_mime_headersGsB             s‰ The MIME headers of the catalog, used for the special ``msgid ""`` entry. The behavior of this property changes slightly depending on whether a locale is set or not, the latter indicating that the catalog is actually a template for actual translations. Here's an example of the output for such a catalog template: >>> created = datetime(1990, 4, 1, 15, 30, tzinfo=UTC) >>> catalog = Catalog(project='Foobar', version='1.0', ... creation_date=created) >>> for name, value in catalog.mime_headers: ... print '%s: %s' % (name, value) Project-Id-Version: Foobar 1.0 Report-Msgid-Bugs-To: EMAIL@ADDRESS POT-Creation-Date: 1990-04-01 15:30+0000 PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE Last-Translator: FULL NAME Language-Team: LANGUAGE MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Generated-By: Babel ... And here's an example of the output when the locale is set: >>> revised = datetime(1990, 8, 3, 12, 0, tzinfo=UTC) >>> catalog = Catalog(locale='de_DE', project='Foobar', version='1.0', ... creation_date=created, revision_date=revised, ... last_translator='John Doe ', ... language_team='de_DE ') >>> for name, value in catalog.mime_headers: ... print '%s: %s' % (name, value) Project-Id-Version: Foobar 1.0 Report-Msgid-Bugs-To: EMAIL@ADDRESS POT-Creation-Date: 1990-04-01 15:30+0000 PO-Revision-Date: 1990-08-03 12:00+0000 Last-Translator: John Doe Language-Team: de_DE Plural-Forms: nplurals=2; plural=(n != 1) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Generated-By: Babel ... :type: `list` cCsK|idjo4d}|iot|iƒd}n||_n|iS(Nii(RXR;RIR (R"tnum((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt num_plurals›s   s® The number of plurals used by the catalog or locale. >>> Catalog(locale='en').num_plurals 2 >>> Catalog(locale='ga').num_plurals 3 :type: `int` cCsK|idjo4d}|iot|iƒd}n||_n|iS(Ns(n != 1)i(RYR;RIR (R"texpr((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt plural_expr­s   sØ The plural expression used by the catalog or locale. >>> Catalog(locale='en').plural_expr '(n != 1)' >>> Catalog(locale='ga').plural_expr '(n==1 ? 0 : n==2 ? 1 : 2)' :type: `basestring` cCsd|i|ifS(Nsnplurals=%s; plural=%s(RRƒ(R"((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyRe¿ssé Return the plural forms declaration for the locale. >>> Catalog(locale='en').plural_forms 'nplurals=2; plural=(n != 1)' >>> Catalog(locale='pt_BR').plural_forms 'nplurals=2; plural=(n > 1)' :type: `str` cCs|i|ƒ|ijS(s?Return whether the catalog has a message with the specified ID.(t_key_forRK(R"R((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt __contains__ÌscCs t|iƒS(snThe number of messages in the catalog. This does not include the special ``msgid ""`` entry. (tlenRK(R"((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt__len__Ðsccs¢g}x.|iD]#\}}|id||fƒqWtƒ}|io|tdgƒO}ntddi|ƒd|ƒVx|iD]}|i|VqˆWdS(sªIterates through all the entries in the catalog, in the order they were added, yielding a `Message` object for every entry. :rtype: ``iterator`` s%s: %sR6us RN(t mime_headersR0RR6RRmRK(R"tbufRuRvRtkey((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt__iter__×s    cCs>d}|iod|i}ndt|ƒi|i|fS(Nts %ss <%s %r%s>(RIR$R%RG(R"RI((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyR&çs cCs1|i|ƒ}||ijo|i|=ndS(s)Delete the message with the specified ID.N(R„RK(R"RRŠ((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt __delitem__íscCs|ii|i|ƒƒS(sãReturn the message with the specified ID. :param id: the message ID :return: the message with the specified ID, or `None` if no such message is in the catalog :rtype: `Message` (RKRoR„(R"R((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt __getitem__óscCsx|i|ƒ}|ii|ƒ}|oª|io'|i o|i|_|i|_ntt|i|iƒƒ|_tt|i |i ƒƒ|_ tt|i |i ƒƒ|_ |i |i O_ |}n£|djont |ii |iƒƒ}|iƒ|_dig}|i D]}|d|q~ƒ|_|i|_n(t|ttfƒon||i|>> catalog = Catalog() >>> catalog[u'foo'] = Message(u'foo') >>> catalog[u'foo'] If a message with that ID is already in the catalog, it is updated to include the locations and flags of the new message. >>> catalog = Catalog() >>> catalog[u'foo'] = Message(u'foo', locations=[('main.py', 1)]) >>> catalog[u'foo'].locations [('main.py', 1)] >>> catalog[u'foo'] = Message(u'foo', locations=[('utils.py', 5)]) >>> catalog[u'foo'].locations [('main.py', 1), ('utils.py', 5)] :param id: the message ID :param message: the `Message` object RŒs s# %sN(R„RKRoRRRRR RRRRRtencodeRRtitemsRˆRmRZR6RR8(R"RtmessageRŠtcurrentRfR?R^((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyt __setitem__ýs.       'c Cs2t||t|ƒ||||d|ƒ||>> catalog = Catalog() >>> catalog.add(u'foo') >>> catalog[u'foo'] This method simply constructs a `Message` object with the given arguments and invokes `__setitem__` with that object. :param id: the message ID, or a ``(singular, plural)`` tuple for pluralizable messages :param string: the translated message string, or a ``(singular, plural)`` tuple for pluralizable messages :param locations: a sequence of ``(filenname, lineno)`` tuples :param flags: a set or sequence of flags :param auto_comments: a sequence of automatic comments :param user_comments: a sequence of user comments :param previous_id: the previous message ID, or a ``(singular, plural)`` tuple for pluralizable messages :param lineno: the line number on which the msgid line was found in the PO file, if any R!N(RR( R"RRRRRRR R!((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyR0sccsFx?|iiƒD].}|id|ƒ}|o||fVqqWdS(sBRun various validation checks on the translations in the catalog. For every message which fails validation, this method yield a ``(message, errors)`` tuple, where ``message`` is the `Message` object and ``errors`` is a sequence of `TranslationError` objects. :rtype: ``iterator`` R1N(RKtvaluesR5(R"R‘R2((s:/usr/lib/python2.6/site-packages/babel/messages/catalog.pyR5Ls c sˆi‰ˆiƒ‰tƒˆ_g}|pGg}ˆD]/}|o"ˆ|io|ˆi|ƒq9q9~}ntƒ‰‡‡‡‡fd†}x­|D]¥}|io•ˆi|iƒ}|ˆjo||||ƒqB|tjoDt|i ƒi ƒ|dƒ} | o||| d|ƒqq1n|ˆ|i>> from babel.messages import Catalog >>> template = Catalog() >>> template.add('green', locations=[('main.py', 99)]) >>> template.add('blue', locations=[('main.py', 100)]) >>> template.add(('salad', 'salads'), locations=[('util.py', 42)]) >>> catalog = Catalog(locale='de_DE') >>> catalog.add('blue', u'blau', locations=[('main.py', 98)]) >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)]) >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'), ... locations=[('util.py', 38)]) >>> catalog.update(template) >>> len(catalog) 3 >>> msg1 = catalog['green'] >>> msg1.string >>> msg1.locations [('main.py', 99)] >>> msg2 = catalog['blue'] >>> msg2.string u'blau' >>> msg2.locations [('main.py', 100)] >>> msg3 = catalog['salad'] >>> msg3.string (u'Salat', u'Salate') >>> msg3.locations [('util.py', 42)] Messages that are in the catalog but not in the template are removed from the main collection, but can still be accessed via the `obsolete` member: >>> 'head' in catalog False >>> catalog.obsolete.values() [] :param template: the reference catalog, usually read from a POT file :param no_fuzzy_matching: whether to use fuzzy matching of message IDs csÉ|iƒ}t}||jo^t}ˆi|ƒˆi|ƒ}t|itƒo|ig|_qt |iƒ|_nˆi |dƒ}|i |_ t|it t fƒoœt|i t t fƒp7t}t |i gdgt|iƒdƒ|_ qƒt|i ƒt|iƒjo)t}t |i t|i ƒ ƒ|_ qƒn4t|i t t fƒot}|i d|_ n|i|iO_|o|itdgƒO_n|ˆ|is0  ( ~