
    ƪb                     >    d Z ddlZddlZddlmZmZ dZdZd ZddZ	y)	z
    babel.messages.mofile
    ~~~~~~~~~~~~~~~~~~~~~

    Writing of files in the ``gettext`` MO (machine object) format.

    :copyright: (c) 2013-2022 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    N)CatalogMessagel   * l   $< c                 V   t               }i }t        | dd      }| j                         }t        |      }t        j
                  } |d|dd       d   }|t        k(  r |d|dd       \  }}	}
}d	}n*|t        k(  r |d
|dd       \  }}	}
}d}nt        dd|      t        d|	      D ]  } ||||
|
dz          \  }}||z   } |||||dz          \  }}||z   }||k  r||k  r||| }||| }nt        dd|      |dk(  rdx}}|j                         D ]u  }|j                         }|sd|v rI|j                  dd      \  }}|j                         j                         x}}|j                         ||<   c|sf||xx   d|z   z  cc<   w d|v r|j                  d      \  }}nd}d|v r|j                  d      }|j                  d      }|j                  r|D cg c]  }|j                  |j                         }}|D cg c]  }|j                  |j                         }}nB|j                  r6|j                  |j                        }|j                  |j                        }t!        |||      ||<   |
dz  }
|dz  } |j#                         |_        |S c c}w c c}w )aa  Read a binary MO file from the given file-like object and return a
    corresponding `Catalog` object.

    :param fileobj: the file-like object to read the MO file from

    :note: The implementation of this function is heavily based on the
           ``GNUTranslations._parse`` method of the ``gettext`` module in the
           standard library.
    name z<IN   r   z<4I   z<IIz>4Iz>IIzBad magic number   zFile is corrupt   :      
       )context)r   getattrreadlenstructunpackLE_MAGICBE_MAGICOSErrorrange
splitlinesstripsplitlowercharsetdecoder   itemsmime_headers)fileobjcatalogheadersfilenamebufbuflenr   magicversionmsgcountorigidxtransidxiiimlenmoffmendtlentofftendmsgtmsglastkeykeyitemvaluectxtxs                               7/usr/lib/python3/dist-packages/babel/messages/mofile.pyread_mor>      s    iGGw+H
,,.CXF]]F 4Ra!!$E/5eS2Y/G,7H	(	/5eS2Y/G,7Ha+X66 1h -BGGaK 89
dd{BHX\ :;
dd{&=TF]d4.CtD>D!.99 19  Gc) 	5zz|4<!%D!!4JC$'IIK$5$5$77Gc#(;;=GCLG$4$	5 c>		'*ID#Dc>))G$C::g&D:=>Qqxx0>>;?@a1@@jj1{{7??3sD$7 	1A[-^ #==?GN ?@s   "J!"J&c                    t        |      }|dd D cg c]  }|j                  r|s|j                  s|  c}|dd |j                          dx}}g }|D ]  }|j                  rdj                  |j                  D 	cg c]  }	|	j                  |j                         c}	      }	g }
t        |j                        D ]J  \  }}|s2|
j                  |j                  t        t        |      d                :|
j                  |       L dj                  |
D cg c]  }|j                  |j                         c}      }nJ|j                  j                  |j                        }	|j                  j                  |j                        }|j                  r6dj                  |j                  j                  |j                        |	g      }	|j                  t        |      t        |	      t        |      t        |      f       ||	dz   z  }||dz   z  } ddt        |      z  z   }|t        |      z   }g }g }|D ]  \  }}}}||||z   gz  }||||z   gz  } ||z   }| j                  t!        j"                  dt$        d	t        |      ddt        |      d
z  z   d	d	      t&        j&                  j)                  t'        j&                  d|            z   |z   |z          yc c}w c c}	w c c}w )a  Write a catalog to the specified file-like object using the GNU MO file
    format.

    >>> import sys
    >>> from babel.messages import Catalog
    >>> from gettext import GNUTranslations
    >>> from io import BytesIO

    >>> catalog = Catalog(locale='en_US')
    >>> catalog.add('foo', 'Voh')
    <Message ...>
    >>> catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
    <Message ...>
    >>> catalog.add('fuz', 'Futz', flags=['fuzzy'])
    <Message ...>
    >>> catalog.add('Fizz', '')
    <Message ...>
    >>> catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
    <Message ...>
    >>> buf = BytesIO()

    >>> write_mo(buf, catalog)
    >>> x = buf.seek(0)
    >>> translations = GNUTranslations(fp=buf)
    >>> if sys.version_info[0] >= 3:
    ...     translations.ugettext = translations.gettext
    ...     translations.ungettext = translations.ngettext
    >>> 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
    r   N    r   r         Iiiiiiir   r
   r.   )liststringfuzzysortpluralizablejoinidencoder   	enumerateappendminintr   r   writer   packr   arraytobytes)r"   r#   	use_fuzzymessagesmidsstrsoffsetsmessagemsgidmsgstrsidxrE   msgstrkeystart
valuestartkoffsetsvoffsetso1l1o2l2s                         r=   write_morg   i   s   ` G}H'| @!xxYagg  @HQRLMMOC$G ! LL;B::"27W__-" E G(8 +VNN7::c#c(A.>#?@NN6*	+
 \\=D#39goo.# F JJ%%goo6E^^**7??;F??LL'//"8"8"I"'") *EC#e*c$iVEFuw  1!8 rCM))HCH$J HH! *BBRh''Rj))* !GMM&++i&!(m##c(ma&77  #(++"5"5ekk#w6O"PQ TWW Z^^ __@"#s   #K%="K*
"K/
)F)
__doc__rR   r   babel.messages.catalogr   r   r   r   r>   rg    r@   r=   <module>rk      s/      3 Qhg_r@   