ó
™‚Mc           @   s=   d  Z  d d l Z d d l Z d g Z d Z e d „ Z d S(   s¿   Writing of files in the ``gettext`` MO (machine object) format.

:since: version 0.9
:see: `The Format of MO Files
       <http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files>`_
iÿÿÿÿNt   write_mos   restructuredtext enc      
   C   s¬  t  | ƒ } | s? g  | d D] } | j s | ^ q | d )n  | j ƒ  d } } g  } xp| D]h} | j r0d j g  | j D] }	 |	 j | j ƒ ^ q ƒ }	 g  }
 xV t | j	 ƒ D]E \ } } | sî |
 j
 | j t t | ƒ d ƒ ƒ q¶ |
 j
 | ƒ q¶ Wd j g  |
 D] } | j | j ƒ ^ qƒ } nK | j j | j ƒ }	 | j	 sf| j j | j ƒ } n | j	 j | j ƒ } | j
 t | ƒ t |	 ƒ t | ƒ t | ƒ f ƒ | |	 d 7} | | d 7} q` Wd d t | ƒ } | t | ƒ } g  } g  } xB | D]: \ } } } } | | | | g 7} | | | | g 7} qW| | } |  j t j d d d	 t | ƒ d d t | ƒ d
 d	 d	 ƒ t j d | ƒ j ƒ  | | ƒ d S(   s¶  Write a catalog to the specified file-like object using the GNU MO file
    format.
    
    >>> from babel.messages import Catalog
    >>> from gettext import GNUTranslations
    >>> from StringIO import StringIO
    
    >>> catalog = Catalog(locale='en_US')
    >>> catalog.add('foo', 'Voh')
    >>> catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
    >>> catalog.add('fuz', 'Futz', flags=['fuzzy'])
    >>> catalog.add('Fizz', '')
    >>> catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
    >>> buf = StringIO()
    
    >>> write_mo(buf, catalog)
    >>> buf.seek(0)
    >>> translations = GNUTranslations(fp=buf)
    >>> translations.ugettext('foo')
    u'Voh'
    >>> translations.ungettext('bar', 'baz', 1)
    u'Bahr'
    >>> translations.ungettext('bar', 'baz', 2)
    u'Batz'
    >>> translations.ugettext('fuz')
    u'fuz'
    >>> translations.ugettext('Fizz')
    u'Fizz'
    >>> translations.ugettext('Fuzz')
    u'Fuzz'
    >>> translations.ugettext('Fuzzes')
    u'Fuzzes'
    
    :param fileobj: the file-like object to write to
    :param catalog: the `Catalog` instance
    :param use_fuzzy: whether translations marked as "fuzzy" should be included
                      in the output
    i   t    t    i   i   i   t   Iiiiiiil   Þ* i    i   t   iNi   i   i   (   t   listt   fuzzyt   sortt   pluralizablet   joint   idt   encodet   charsett	   enumeratet   stringt   appendt   mint   intt   lent   writet   structt   packt   arrayt   tostring(   t   fileobjt   catalogt	   use_fuzzyt   messagest   mt   idst   strst   offsetst   messaget   msgidt   msgstrst   idxR   t   msgstrt   keystartt
   valuestartt   koffsetst   voffsetst   o1t   l1t   o2t   l2(    (    s9   /usr/lib/python2.7/site-packages/babel/messages/mofile.pyR       sD    '-

	+&+	1
(   t   __doc__R   R   t   __all__t   __docformat__t   FalseR    (    (    (    s9   /usr/lib/python2.7/site-packages/babel/messages/mofile.pyt   <module>   s
   	