
    1yi                        U d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 erddl
mZmZ dZded	<   d
Zded<   ddZdddZy)z
babel.messages.mofile
~~~~~~~~~~~~~~~~~~~~~

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

:copyright: (c) 2013-2026 by the Babel Team.
:license: BSD, see LICENSE for more details.
    )annotationsN)TYPE_CHECKING)CatalogMessage)SupportsReadSupportsWritel   * intLE_MAGICl   $< BE_MAGICc                $   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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 rs|j                  d      }|j                  d      }|D cg c]  }|j                  |j                         }}|D cg c]  }|j                  |j                         }}n6|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unpackr
   r   OSErrorrange
splitlinesstripsplitlowerdecodecharsetr   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                               W/var/www/html/content_weaver/venv/lib/python3.12/site-packages/babel/messages/mofile.pyread_morC      s    iGGw+H
,,.CXF]]F 4Ra!!$E/5eS2Y/G,7H	(	/5eS2Y/G,7Ha+X66 Ho +BGgk :;
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&D69:188GOO,:C:7;<!AHHW__-<D<**W__-C;;w/DsD$7 	1AW+Z #==?GN ;<s   "J8"Jc                f   t              }|dd D cg c]   }|j                  s|s|j                  r|" c}|dd |j                          dx}}g }|D ]  }|j                  rdj                  fd|j                  D              }	g }
t        |j                        D ]J  \  }}|s2|
j                  |j                  t        t        |      d                :|
j                  |       L dj                  fd|
D              }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   }t        j                   d
t"        dt        |      ddt        |      dz  z   dd      }| j%                  |t&        j&                  j)                  t'        j&                  d|            z   |z   |z          y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(('bar', 'baz'), ('Bahr', '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')
    'Voh'
    >>> translations.ungettext('bar', 'baz', 1)
    'Bahr'
    >>> translations.ungettext('bar', 'baz', 2)
    'Batz'
    >>> translations.ugettext('fuz')
    'fuz'
    >>> translations.ugettext('Fizz')
    'Fizz'
    >>> translations.ugettext('Fuzz')
    'Fuzz'
    >>> translations.ugettext('Fuzzes')
    '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   c              3  T   K   | ]  }|j                  j                         ! y wNencoder$   ).0msgidr(   s     rB   	<genexpr>zwrite_mo.<locals>.<genexpr>   s      W5goo!> W   %(c              3  T   K   | ]  }|j                  j                         ! y wrG   rH   )rJ   msgstrr(   s     rB   rL   zwrite_mo.<locals>.<genexpr>   s     !WV&--"@!WrM   r         Iiiiiiir   r   i)liststringfuzzysortpluralizablejoinid	enumerateappendminr	   rI   r$   r   r   r   packr
   writearraytobytes)r'   r(   	use_fuzzymessagesmidsstrsoffsetsmessagerK   msgstrsidxrU   rO   keystart
valuestartkoffsetsvoffsetso1l1o2l2headers    `                     rB   write_mort   l   sw   ` G}H'|W!qxxYaggAWHQRLMMOC$G ! LL WGJJ WWEG(8 +VNN7::c#c(A.>#?@NN6*	+
 \\!Ww!WWFJJ%%goo6E^^**7??;F??LL'//"8"8"I5!QREC#e*c$iVEFuw  '!. rCM))HCH$J HH! *BBRh''Rj))* !G[[	HH!!			F MM&5;;..u{{3/HIICORVVWi Xs   J.J.J.)r'   zSupportsRead[bytes]returnr   )F)r'   zSupportsWrite[bytes]r(   r   rb   boolru   None)__doc__
__future__r   r`   r   typingr   babel.messages.catalogr   r   	_typeshedr   r   r
   __annotations__r   rC   rt    rE   rB   <module>r      sC    #     35# # OdeXrE   