Ñò ž²Hc@sdZddklZlZddkZddkZyeWn#ej oddklZnXddk l Z ddk l Z lZddklZlZdd gZd Zd „Zd „Zdded „ZeidƒZd„Zddd„Zdeeeeeed„ZdS(s¸Reading and writing of files in the ``gettext`` PO (portable object) format. :see: `The Format of PO Files `_ iÿÿÿÿ(tdatetdatetimeN(tSet(t __version__(tCatalogtMessage(twraptexttLOCALTZtread_potwrite_posrestructuredtext encCsG|dd!iddƒiddƒiddƒid d ƒid d ƒS( sÿReverse `escape` the given string. >>> print unescape('"Say:\\n \\"hello, world!\\"\\n"') Say: "hello, world!" :param string: the string to unescape :return: the unescaped string :rtype: `str` or `unicode` iiÿÿÿÿs\\s\s\ts s\rs s\ns s\"s"(treplace(tstring((s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pytunescape$s    cCs`|idƒoBg}x+|iƒdD]}|it|ƒƒq'Wdi|ƒSt|ƒSdS(s.Reverse the normalization done by the `normalize` function. >>> print denormalize(r'''"" ... "Say:\n" ... " \"hello, world!\"\n"''') Say: "hello, world!" >>> print denormalize(r'''"" ... "Say:\n" ... " \"Lorem ipsum dolor sit " ... "amet, consectetur adipisicing" ... " elit, \"\n"''') Say: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " :param string: the string to denormalize :return: the denormalized string :rtype: `unicode` or `str` s""itN(t startswitht splitlinestappendR tjoin(R tlinestline((s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pyt denormalize6sc std|d|ƒ‰dg‰ dg‰g‰ g‰g‰g‰ g‰g‰tg‰tg‰tg‰‡‡‡‡‡‡‡‡ ‡ ‡ ‡ f d†‰ ‡‡ ‡ ‡‡‡fd†}xt|iƒƒD]ð\}}|iƒiˆiƒ}|idƒo¯tˆd<ˆd<ˆ oˆo ˆ ƒn|didƒoxi|d iƒi ƒD]n}|i dƒ}|djoLyt ||dƒ}Wnt j o qNnXˆi || |fƒqNqNWq´|did ƒo;xÈ|d iƒi d ƒD]} ˆ i | iƒƒqòWq´|did ƒo%tˆd<|||d iƒƒq´|did ƒo,|d iƒ} | oˆi | ƒq£q´ˆi |diƒƒqÄ|||ƒqÄWˆ o ˆ ƒnMˆ d o@ˆ pˆpˆo+ˆ i d ƒˆi dd gƒˆ ƒnˆS(s×Read messages from a ``gettext`` PO (portable object) file from the given file-like object and return a `Catalog`. >>> from StringIO import StringIO >>> buf = StringIO(''' ... #: main.py:1 ... #, fuzzy, python-format ... msgid "foo %(name)s" ... msgstr "" ... ... # A user comment ... #. An auto comment ... #: main.py:3 ... msgid "bar" ... msgid_plural "baz" ... msgstr[0] "" ... msgstr[1] "" ... ''') >>> catalog = read_po(buf) >>> catalog.revision_date = datetime(2007, 04, 01) >>> for message in catalog: ... if message.id: ... print (message.id, message.string) ... print ' ', (message.locations, message.flags) ... print ' ', (message.user_comments, message.auto_comments) (u'foo %(name)s', '') ([(u'main.py', 1)], set([u'fuzzy', u'python-format'])) ([], []) ((u'bar', u'baz'), ('', '')) ([(u'main.py', 3)], set([])) ([u'A user comment'], [u'An auto comment']) :param fileobj: the file-like object to read the PO file from :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 ignore_obsolete: whether to ignore obsolete messages in the input :return: an iterator over ``(message, translation, location)`` tuples :rtype: ``iterator`` tlocaletdomainics·ˆiƒtˆƒdjo1tg}ˆD]}|t|ƒq+~ƒ}ntˆdƒ}t|ttfƒo“g}xUtˆiƒD]D}y|iˆ|ƒWqŠt j o|i|dfƒqŠXqŠWtg}|D]}|t|dƒqà~ƒ}ntˆddƒ}t ||tˆƒt ˆ ƒˆˆdˆddƒ}ˆdoˆ p|ˆi |>> escape('''Say: ... "hello, world!" ... ''') '"Say:\\n \\"hello, world!\\"\\n"' :param string: the string to escape :return: the escaped string :rtype: `str` or `unicode` s"%s"s\s\\s s\ts s\rs s\ns"s\"(R (R ((s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pytescape÷s    R iLc Cs×|o?|djo2t|ƒ}g}x,t|itƒƒD]\}}tt|ƒƒ||joÌti|ƒ}|iƒx½|o¤g}d} x{|ostt|dƒƒd|} | | |jo!|i|i ƒƒ| | 7} q—|p|i|i ƒƒnPq—W|idi |ƒƒqWq<|i|ƒq<Wn|itƒ}t|ƒdjo t|ƒS|o'|d o|d=|dcd7>> print normalize('''Say: ... "hello, world!" ... ''', width=None) "" "Say:\n" " \"hello, world!\"\n" >>> print normalize('''Say: ... "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " ... ''', width=32) "" "Say:\n" " \"Lorem ipsum dolor sit " "amet, consectetur adipisicing" " elit, \"\n" :param string: the string to normalize :param prefix: a string that should be prepended to every line :param width: the maximum line width; use `None`, 0, or a negative number to completely disable line wrapping :return: the normalized string :rtype: `unicode` iiiÿÿÿÿuis u"" u ( RRIRR:RUtWORD_SEPR<treverseRtpopR( R tprefixtwidtht prefixlenRR&RtchunkstbuftsizetlR#((s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pyt normalize s<    c sød‡‡fd†‰‡‡fd†‰d‡‡fd†} d‡‡‡fd†} tˆƒ} |o| iƒn|o| id„ƒnx| D]ü} | ip‰|oq—nˆi} ˆo]ˆdjoPg}x0| iƒD]"}|t|dˆd d ƒ7}qåWd i|ƒd } nˆ| ƒnx| iD]}| |ƒq:Wx!| iD]}| |d d ƒqXW|p`dig}| i D],\}}|d|i t i dƒ|fq~ƒ}| |d dƒn| i o+ˆddidgt| i ƒƒƒn| iog|o`| dˆ| idƒd dƒt| iƒdjo%| dˆ| idƒd dƒqn| | ƒˆdƒq—W|pVxSˆiiƒD]>} x| iD]}| |ƒq¾W| | d dƒˆdƒq®WndS(s\Write a ``gettext`` PO (portable object) template file for a given message catalog to the provided file-like object. >>> catalog = Catalog() >>> catalog.add(u'foo %(name)s', locations=[('main.py', 1)], ... flags=('fuzzy',)) >>> catalog.add((u'bar', u'baz'), locations=[('main.py', 3)]) >>> from StringIO import StringIO >>> buf = StringIO() >>> write_po(buf, catalog, omit_header=True) >>> print buf.getvalue() #: main.py:1 #, fuzzy, python-format msgid "foo %(name)s" msgstr "" #: main.py:3 msgid "bar" msgid_plural "baz" msgstr[0] "" msgstr[1] "" :param fileobj: the file-like object to write to :param catalog: the `Catalog` instance :param width: the maximum line width for the generated output; use `None`, 0, or a negative number to completely disable line wrapping :param no_location: do not emit a location comment for every message :param omit_header: do not include the ``msgid ""`` entry at the top of the output :param sort_output: whether to sort the messages in the output by msgid :param sort_by_file: whether to sort the messages in the output by their locations :param ignore_obsolete: whether to ignore obsolete messages and not include them in the output; by default they are included as comments :param include_previous: include the old msgid as a comment when updating the catalog R cs%t|d|dˆƒiˆidƒS(NRYRZtbackslashreplace(R`tencodeRM(tkeyRY(RZR.(s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pyt _normalizesscs7t|tƒo|iˆiƒ}nˆi|ƒdS(N(RtunicodeRbRMtwrite(ttext(R.RP(s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pyt_writewscs\|}ˆo ˆdjot|ˆƒ}nx(|D] }ˆd||iƒfƒq4WdS(Nis#%s %s (RRK(RTRYRR(RZRh(s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pyt_write_comment|s c st|ittfƒo³ˆd|ˆ|id|ƒfƒˆd|ˆ|id|ƒfƒx¯tˆiƒD]S}y|i|}Wntj o d}nXˆd||ˆ||ƒfƒqqWnHˆd|ˆ|i|ƒfƒˆd|ˆ|ipd|ƒfƒdS(Ns %smsgid %s is%smsgid_plural %s iR s%smsgstr[%d] %s s %smsgstr %s (RtidRRRRR R(R)RYR&R (R.RdRh(s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pyt_write_messageƒs$ " cSst|i|iƒS((tcmpR*(txty((s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pytœsiRZtsubsequent_indents# u RYRHu u%s:%dt/REs#%s s, smsgid %st|ismsgid_plural %ss s#~ N(RRRjtheader_commentRRRR+R,R*R tostsepR2t previous_idRR!tvalues(RPR.RZt no_locationt omit_headert sort_outputt sort_by_fileR3tinclude_previousRiRkR1R)tcomment_headerRRRTR#tfilenameRtlocs((RPRhRZR.Rds9/usr/lib/python2.6/site-packages/babel/messages/pofile.pyR Hsh+       ? +   (t__doc__RRRttreR t NameErrortsetsRtbabelRtVERSIONtbabel.messages.catalogRRt babel.utilRRt__all__t __docformat__R RtNoneR"RtcompileRVRUR`R (((s9/usr/lib/python2.6/site-packages/babel/messages/pofile.pyts*     œ >