Ñò
ž²Hc @ s d Z d d k l Z l Z d d k Z d d k Z y e Wn# e j
o d d k l Z n Xd d k l
Z d d k l
Z
l Z d d k l Z l Z d d g Z d
Z d „ Z d „ Z d d e d
„ Z e i d ƒ Z d „ Z d d d „ Z d e e e e e e d „ Z d S( s¸ Reading and writing of files in the ``gettext`` PO (portable object)
format.
:see: `The Format of PO Files
`_
iÿÿÿÿ( t datet datetimeN( t Set( t __version__( t Catalogt Message( t wraptextt LOCALTZt read_pot write_pos restructuredtext enc C sG | d d !i d d ƒ i d d ƒ i d d ƒ i d d
ƒ i d 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`
i iÿÿÿÿs \\s \s \ts s \rs
s \ns
s \"s "( t replace( t string( ( s9 /usr/lib/python2.6/site-packages/babel/messages/pofile.pyt unescape$ s
c C s` | i d ƒ oB g } x+ | i ƒ d D] } | i t | ƒ ƒ q' Wd i | ƒ St | ƒ Sd S( 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 ""i t N( t
startswitht
splitlinest appendR t join( R t linest line( ( s9 /usr/lib/python2.6/site-packages/babel/messages/pofile.pyt denormalize6 s c s t d | d | ƒ ‰ d g ‰ d g ‰ g ‰
g ‰ g ‰ g ‰ g ‰ g ‰ t g ‰ t g ‰ t g ‰ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡
‡ ‡ f d † ‰
‡ ‡
‡
‡ ‡ ‡ f d † } xt | i ƒ ƒ D]ð\ } } | i ƒ i ˆ i ƒ } | i d ƒ o¯t ˆ d <ˆ d <ˆ
o ˆ o ˆ
ƒ n | d i d ƒ o xi| d i ƒ i ƒ D]n } | i
d ƒ } | d j oL y t | | d ƒ } Wn t j
o
qNn Xˆ i
| | | f ƒ qNqNWq´| d i d
ƒ o; xÈ | d i ƒ i d
ƒ D] } ˆ i
| i ƒ ƒ qòWq´| d i d ƒ o% t ˆ d <| | | d i ƒ ƒ q´| d i d ƒ o, | d i ƒ }
|
o ˆ i
|
ƒ q£q´ˆ i
| d i ƒ ƒ qÄ | | | ƒ qÄ Wˆ
o ˆ
ƒ nM ˆ d o@ ˆ p ˆ p ˆ o+ ˆ
i
d
ƒ ˆ i
d d
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``
t localet domaini c s· ˆ i ƒ t ˆ ƒ d j o1 t g } ˆ D] } | t | ƒ q+ ~ ƒ } n t ˆ d ƒ } t | t t f ƒ o“ g } xU t ˆ i ƒ D]D } y | i ˆ | ƒ WqŠ t j
o | i | d f ƒ qŠ XqŠ Wt g } | D] } | t | d ƒ qà ~ ƒ } n t ˆ d d ƒ } t
| | t ˆ ƒ t ˆ ƒ ˆ ˆ d ˆ d d ƒ} ˆ d o ˆ
p | ˆ i |