
    BiG                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSr	Sr
/ SQrSr\R                  SS S:  a  S	r\rS
 rS rO
Sr\rS rS rS rS rS rS rS'S jrS rS rS r " S S\5      r " S S\5      r " S S\5      r " S S\ 5      r! " S S \!5      r" " S! S"\!5      r# " S# S$\ 5      r$ " S% S&\ 5      r%g)(ah  
**polib** allows you to manipulate, create, modify gettext files (pot, po and
mo files).  You can load existing files, iterate through it's entries, add,
modify entries, comments or metadata, etc. or create new po files from scratch.

**polib** provides a simple and pythonic API via the :func:`~polib.pofile` and
:func:`~polib.mofile` convenience functions.
    Nz%David Jean Louis <izimobil@gmail.com>z1.1.1)
pofilePOFilePOEntrymofileMOFileMOEntrydefault_encodingescapeunescapedetect_encodingutf-8   )   r   Fc                     U $ N ss    W/var/www/html/backend/Backoffice_Marketplace/venv/lib/python3.13/site-packages/polib.pybr   )           c                     [        U S5      $ )Nunicode_escape)unicoder   s    r   ur   ,   s    q*++r   Tc                 $    U R                  S5      $ )Nzlatin-1)encoder   s    r   r   r   3   s    xx	""r   c                     U $ r   r   r   s    r   r   r   6   r   r   c                 &   UR                  S5      nUc  [        XS:H  5      nUS:H  =(       a    [        =(       d    [        nU" U UUR                  SS5      UR                  S5      S9nUR	                  5       nUR                  SS	5      Ul        U$ )
zc
Internal function used by :func:`polib.pofile` and :func:`polib.mofile` to
honor the DRY concept.
encodingr   r   check_for_duplicatesFklass)r!   r"   r#   	wrapwidthN   )getr   _POFileParser_MOFileParserparser$   )ftypekwargsencklsparserinstances          r   _pofile_or_mofiler1   <   s     **Z
 C
{a!12 (

,}
=C	#ZZ(>Fjj!	F ||~HK4HOr   c                 x     [         R                  R                  U 5      $ ! [        [        [
        4 a     gf = f)z
Safely returns the value of os.path.exists(filename_or_contents).

Arguments:

``filename_or_contents``
    either a filename, or a string holding the contents of some file.
    In the latter case, this function will always return False.
F)ospathisfile	TypeError
ValueErrorUnicodeEncodeError)filename_or_contentss    r   _is_filer:   U   s5    ww~~233z#56 s   ! 99c                     [        U S40 UD6$ )a  
Convenience function that parses the po or pot file ``pofile`` and returns
a :class:`~polib.POFile` instance.

Arguments:

``pofile``
    string, full or relative path to the po/pot file or its content (data).

``wrapwidth``
    integer, the wrap width, only useful when the ``-w`` option was passed
    to xgettext (optional, default: ``78``).

``encoding``
    string, the encoding to use (e.g. "utf-8") (default: ``None``, the
    encoding will be auto-detected).

``check_for_duplicates``
    whether to check for duplicate entries when adding entries to the
    file (optional, default: ``False``).

``klass``
    class which is used to instantiate the return value (optional,
    default: ``None``, the return value with be a :class:`~polib.POFile`
    instance).
r   r1   )r   r,   s     r   r   r   g   s    6 VX888r   c                     [        U S40 UD6$ )a8  
Convenience function that parses the mo file ``mofile`` and returns a
:class:`~polib.MOFile` instance.

Arguments:

``mofile``
    string, full or relative path to the mo file or its content (data).

``wrapwidth``
    integer, the wrap width, only useful when the ``-w`` option was passed
    to xgettext to generate the po file that was used to format the mo file
    (optional, default: ``78``).

``encoding``
    string, the encoding to use (e.g. "utf-8") (default: ``None``, the
    encoding will be auto-detected).

``check_for_duplicates``
    whether to check for duplicate entries when adding entries to the
    file (optional, default: ``False``).

``klass``
    class which is used to instantiate the return value (optional,
    default: ``None``, the return value with be a :class:`~polib.POFile`
    instance).
r   r<   )r   r,   s     r   r   r      s    8 VX888r   c                    Sn[         R                  " [        U5      5      n[         R                  " [        U5      5      nS n[	        U 5      (       dL  UR                  U 5      nU(       a.  UR                  S5      R                  5       nU" U5      (       a  U$ [        $ U(       d  [        (       a  SnUn	OSnUn	[        X5      n
U
R                  5        H  nU	R                  U5      nU(       d  M  U
R                  5         UR                  S5      R                  5       n[        U[        5      (       d  UR                  S5      nU" U5      (       d  M  Us  $    U
R                  5         [        $ )a  
Try to detect the encoding used by the ``file``. The ``file`` argument can
be a PO or MO file path or a string containing the contents of the file.
If the encoding cannot be detected, the function will return the value of
``default_encoding``.

Arguments:

``file``
    string, full or relative path to the po/mo file or its content.

``binary_mode``
    boolean, set this to True if ``file`` is a mo file.
z("?Content-Type:.+? charset=([\w_\-:\.]+)c                 R     [         R                  " U 5        g! [         a     gf = f)z*Check whether ``charset`` is valid or not.FT)codecslookupLookupError)charsets    r   charset_exists'detect_encoding.<locals>.charset_exists   s,    	MM'"   		s    
&&   rbrr   )recompiler   r   r:   searchgroupstripPY3open	readlinesclose
isinstance	text_typedecoder	   )filebinary_modePATTERNrxtrxbrD   matchr-   moderxr*   lines               r   r   r      s     :G
**QwZ
 C
**QwZ
 C D>>

4 ++a.&&(Cc""
( # ##DBDBKKMDIIdOEu	kk!n**,!#y11**W-C!#&&J " 	
	r   c                     U R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  S	S
5      $ )zl
Escapes the characters ``\\``, ``\t``, ``\n``, ``\r`` and ``"`` in
the given string ``st`` and returns it.
\z\\	z\tz\r
z\n"z\")replace)sts    r   r
   r
      sG    
 ::dE"gdE"gdE"gdE"gdE"	#r   c                 6    S n[         R                  " SX5      $ )zn
Unescapes the characters ``\\``, ``\t``, ``\n``, ``\r`` and ``"`` in
the given string ``st`` and returns it.
c                 `    U R                  S5      n U S:X  a  gU S:X  a  gU S:X  a  gU S:X  a  gU $ )	NrF   nrb   tr`   rH   ra   r_   )rL   )ms    r   unescape_replunescape.<locals>.unescape_repl   s<    GGAJ8889r   z\\(\\|n|t|r|"))rI   sub)re   rk   s     r   r   r      s    

 66#]77r   c                 (   ^ S mU4S jn[        XS9$ )zL
Sort naturally the given list.
Credits: http://stackoverflow.com/a/4836734
c                 b    U R                  5       (       a  [        U 5      $ U R                  5       $ r   )isdigitintlower)texts    r   convertnatural_sort.<locals>.convert	  s!     LLNNs4y<

<r   c                 j   > [         R                  " SU 5       Vs/ s H  nT" U5      PM     sn$ s  snf )Nz([0-9]+))rI   split)keycrt   s     r   alphanum_key"natural_sort.<locals>.alphanum_key  s,    $&HHZ$=>$=q
$=>>>s   0rx   )sorted)lstrz   rt   s     @r   natural_sortr     s    
=? #((r   c                      ^  \ rS rSrSrS rS r\(       a  S rOS rS r	S r
U 4S	 jrU 4S
 jrS rSS jr  SS jrS rS rS rSrU =r$ )	_BaseFilei  z
Common base class for the :class:`~polib.POFile` and :class:`~polib.MOFile`
classes. This class should **not** be instantiated directly.
c                 v   [         R                  U 5        UR                  SS5      nU(       a  [        U5      (       a  X0l        OUR                  S5      U l        UR                  SS5      U l        UR                  S[        5      U l        UR                  SS5      U l        S	U l	        0 U l
        S
U l        g)a  
Constructor, accepts the following keyword arguments:

``pofile``
    string, the path to the po or mo file, or its content as a string.

``wrapwidth``
    integer, the wrap width, only useful when the ``-w`` option was
    passed to xgettext (optional, default: ``78``).

``encoding``
    string, the encoding to use, defaults to ``default_encoding``
    global variable (optional).

``check_for_duplicates``
    whether to check for duplicate entries when adding entries to the
    file, (optional, default: ``False``).
r   Nfpathr$   r%   r!   r"   F r   )list__init__r&   r:   r   r$   r	   r!   r"   headermetadatametadata_is_fuzzy)selfargsr,   r   s       r   r   _BaseFile.__init__  s    & 	dHd+hv&&JG,DJK4

:/?@$*JJ/Eu$M!!"r   c                    / nU R                  5       /U  Vs/ s H  o"R                  (       a  M  UPM     sn-   nU H-  nUR                  UR                  U R                  5      5        M/     U R                  5        H-  nUR                  UR                  U R                  5      5        M/     [        S5      R                  U5      nU$ s  snf )z1
Returns the unicode representation of the file.
rb   )metadata_as_entryobsoleteappend__unicode__r$   obsolete_entriesr   join)r   reteentriesentrys        r   r   _BaseFile.__unicode__A  s     ))+,"5d**1d56EJJu((89 **,EJJu((89 -gll3
 6s
   C
C
c                 "    U R                  5       $ r   r   r   s    r   __str___BaseFile.__str__P      ##%%r   c                 J    [        U 5      R                  U R                  5      $ )z0
Returns the string representation of the file.
r   r   r!   r   s    r   r   r   S       4=''66r   c                 P    U R                  UR                  SUR                  S9SL$ )aD  
Overridden ``list`` method to implement the membership test (in and
not in).
The method considers that an entry is in the file if it finds an entry
that has the same msgid (the test is **case sensitive**) and the same
msgctxt (or none for both entries).

Argument:

``entry``
    an instance of :class:`~polib._BaseEntry`.
msgid)bymsgctxtN)findr   r   )r   r   s     r   __contains___BaseFile.__contains__Y  s+     yy%--yH 	r   c                 0    [        U 5      [        U5      :H  $ r   strr   others     r   __eq___BaseFile.__eq__i      4yCJ&&r   c                    > [        U SS5      (       a  X;   a  [        SUR                  -  5      e[        [        U ]  U5        g)z
Overridden method to check for duplicates entries, if a user tries to
add an entry that is already in the file, the method will raise a
``ValueError`` exception.

Argument:

``entry``
    an instance of :class:`~polib._BaseEntry`.
r"   FEntry "%s" already existsN)getattrr7   r   superr   r   )r   r   	__class__s     r   r   _BaseFile.appendl  s=     4/77EM85;;FGGi%e,r   c                    > U R                   (       a  X ;   a  [        SUR                  -  5      e[        [        U ]  X5        g)a%  
Overridden method to check for duplicates entries, if a user tries to
add an entry that is already in the file, the method will raise a
``ValueError`` exception.

Arguments:

``index``
    index at which the entry should be inserted.

``entry``
    an instance of :class:`~polib._BaseEntry`.
r   N)r"   r7   r   r   r   insert)r   indexr   r   s      r   r   _BaseFile.insert}  s6     $$85;;FGGi%e3r   c                    [        SS9nU R                  5       nU(       a>  / nU H  u  pEUR                  U< SU< 35        M     SR                  U5      S-   Ul        U R
                  (       a  UR                  R                  S5        U$ )zA
Returns the file metadata as a :class:`~polib.POFile` instance.
r   )r   z: rb   fuzzy)r   ordered_metadatar   r   msgstrr   flags)r   r   mdatastrsnamevalues         r   r   _BaseFile.metadata_as_entry  su     "%%'D$e45  % yy-AH!!GGNN7#r   c                    U R                   c  Uc  [        S5      e[        X5      " 5       nUc  U R                   nUS:X  a  [        US5      nOQ[        R                  " USU R
                  US9n[        U[        5      (       d  UR                  U R
                  5      nUR                  U5        UR                  5         U R                   c  U(       a  Xl         ggg)a]  
Saves the po file to ``fpath``.
If it is an existing file and no ``fpath`` is provided, then the
existing file is rewritten with the modified data.

Keyword arguments:

``fpath``
    string, full or relative path to the file.

``repr_method``
    string, the method to use for output.

``newline``
    string, controls how universal newlines works
Nz-You must provide a file path to save() method	to_binarywbw)r!   newline)r   IOErrorr   rO   ior!   rR   rS   rT   writerQ   )r   r   repr_methodr   contentsfhandles         r   save_BaseFile.save  s    " ::%-IJJ4-/=JJE+%5$'Ggg	G h	22#??4==9h::%J #(r   c                    U(       a  U SS nO$U  Vs/ s H  ofR                   (       a  M  UPM     nn/ nU H<  n[        Xb5      U:X  d  M  USLa  UR                  U:w  a  M+  UR                  U5        M>     [	        U5      S:X  a  US   $ [	        U5      S:  a5  U(       d.  SnU H  nUR                  (       a  M  UnM     U(       a  U$ US   $ gs  snf )a  
Find the entry which msgid (or property identified by the ``by``
argument) matches the string ``st``.

Keyword arguments:

``st``
    string, the string to search for.

``by``
    string, the property to use for comparison (default: ``msgid``).

``include_obsolete_entries``
    boolean, whether to also search in entries that are obsolete.

``msgctxt``
    string, allows specifying a specific message context for the
    search.
NFrF   r   )r   r   r   r   len)	r   re   r   include_obsolete_entriesr   r   r   matchesrj   s	            r   r   _BaseFile.find  s    * $1gG"&9$Qjjq$G9Aq~#%'AII,@q!	 
 w<11:\A A999 ! Hqz!) :s
   CCc                 .   U R                   R                  5       n/ SQn/ nU H'  n UR                  U5      nUR                  XE45        M)     [        UR                  5       5       H  nX   nUR                  XE45        M     U$ ! [         a     Mp  f = f)z
Convenience method that returns an ordered version of the metadata
dictionary. The return value is list of tuples (metadata name,
metadata_value).
)zProject-Id-VersionzReport-Msgid-Bugs-TozPOT-Creation-DatezPO-Revision-DatezLast-TranslatorzLanguage-TeamLanguagezMIME-VersionzContent-TypezContent-Transfer-EncodingzPlural-Forms)r   copypopr   KeyErrorr   keys)r   r   
data_orderordered_datadatar   s         r   r   _BaseFile.ordered_metadata  s     ==%%'

 D T*##TM2  !1DNE. 2   s   #B
BBc           
         / nU R                  5       nS nUR                  S S9  U R                  5       nU/U-   n[        U5      n[	        S5      [	        S5      pvU GHx  n[	        S5      n	UR
                  (       a  U R                  UR
                  S-   5      n	UR                  (       a  / n
[        UR                  R                  5       5       H!  nU
R                  UR                  U   5        M#     XR                  UR                  S-   UR                  -   5      -  n	U R                  SR                  U
5      5      n
O8XR                  UR                  5      -  n	U R                  UR                  5      n
UR                  [        U5      [        U	5      [        U5      [        U
5      45        Xi[	        S5      -   -  nXz[	        S5      -   -  nGM{     SSU-  -   nU[        U5      -   n/ n/ nU H  u  nnnnUUUU-   /-  nUUUU-   /-  nM     X-   n[        R                   " S	["        R$                  S
USSUS-  -   S
U5      n[&        (       aG  [(        R*                  R,                  S:  a)  U[.        R.                  " SU5      R1                  5       -  nO(U[.        R.                  " SU5      R3                  5       -  nUU-  nUU-  nU$ )z/
Return the binary representation of the file.
c                     U R                   =(       a    U R                   =(       d    U R                  nUR                   =(       a    UR                   =(       d    UR                  nX#:  a  gX#:  a  gg)NrF   r   r   r   )_selfr   
self_msgidother_msgids       r   cmp _BaseFile.to_binary.<locals>.cmp  sM    85==GEKKJ--9EMMHU[[K')r   c                 8    U R                   R                  S5      $ )Nr   )msgid_with_contextr   )os    r   <lambda>%_BaseFile.to_binary.<locals>.<lambda>*  s    1#7#7#>#>w#Gr   r|   r          Iiiiiiir      rF   i)translated_entriessortr   r   r   r   _encodemsgid_pluralr}   msgstr_pluralr   r   r   r   r   structpackr   MAGICrN   sysversion_infominorarraytobytestostring)r   offsetsr   r   mentryentries_lenidsr   r   r   r   r   keystart
valuestartkoffsetsvoffsetso1l1o2l2outputs                        r   r   _BaseFile.to_binary  s    ))+		 	GH'')(W$'lbE1R5TA bEEyy QYY%56~~#AOO$8$8$:;EMM!//%"89 <aggnq~~&EFFdii&78agg..ahh/NNCHc%j#d)S[IJ1T7?"CQtW$$D' , 2++C(
 &NBBR(]++HR*_--H & %LLK!O#x
  33##))A-ekk#w/7799Fekk#w/88::F#$r   c                 f    [        U[        5      (       a  UR                  U R                  5      nU$ )z
Encodes the given ``mixed`` argument with the file encoding if and
only if it's an unicode string and returns the encoded string.
)rR   rS   r   r!   )r   mixeds     r   r   _BaseFile._encodei  s(    
 eY''LL/Er   )r"   r!   r   r   r   r   r$   )Nr   N)r   FF)__name__
__module____qualname____firstlineno____doc__r   r   rN   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__)r   s   @r   r   r     sg    
$#L 	&	7 '-"4$ %N =B,\!FPd r   r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)r   iu  z
Po (or Pot) file reader/writer.
This class inherits the :class:`~polib._BaseFile` class and, by extension,
the python ``list`` type.
c                 @   SU R                   R                  S5      p!U H5  n[        U5      (       d  US-  nM  USS S;   a
  USU-  -  nM-  USU-  -  nM7     [        U[        5      (       d  UR                  U R                  5      nU[        R                  U 5      -   $ )	z4
Returns the unicode representation of the po file.
r   rb   z#
NrF   ),:z#%s
z# %s
)	r   rw   r   rR   rS   rT   r!   r   r   )r   r   headersr   s       r   r   POFile.__unicode__|  s     4;;,,T2WFv;;uz)w''x&((  #y))**T]]+CY**4000r   c                 0    [         R                  XS5        g)z
Saves the binary representation of the file to given ``fpath``.

Keyword argument:

``fpath``
    string, full or relative path to the mo file.
r   Nr   r   r   r   s     r   save_as_mofilePOFile.save_as_mofile       	tK0r   c                     [        U  Vs/ s H  oR                  (       a  M  UPM     sn5      nUS:X  a  g[        U R                  5       5      n[        US-  [	        U5      -  5      $ s  snf )zH
Convenience method that returns the percentage of translated
messages.
r   d   )r   r   r   rq   float)r   r   total
translateds       r   percent_translatedPOFile.percent_translated  s\    
 71JJQ78A:0023
:#eEl233	 8s
   A)A)c                 ^    U  Vs/ s H  oR                  5       (       d  M  UPM     sn$ s  snf )zA
Convenience method that returns the list of translated entries.
)r,  r   r   s     r   r   POFile.translated_entries  s"      24a<<>4222s   **c                     U  Vs/ s HA  oR                  5       (       a  M  UR                  (       a  M,  UR                  (       a  M?  UPMC     sn$ s  snf )zC
Convenience method that returns the list of untranslated entries.
)r,  r   r   r0  s     r   untranslated_entriesPOFile.untranslated_entries  s>       !4a||~ajj 4 ! 	! !s   AAAAc                 V    U  Vs/ s H  oR                   (       d  M  UPM     sn$ s  snf )z<
Convenience method that returns the list of fuzzy entries.
)r   r0  s     r   fuzzy_entriesPOFile.fuzzy_entries  s       +4a774+++   &&c                 V    U  Vs/ s H  oR                   (       d  M  UPM     sn$ s  snf )z?
Convenience method that returns the list of obsolete entries.
)r   r0  s     r   r   POFile.obsolete_entries  s       .4a::4...r8  c                 6   [        S U  5       5      n[        S U 5       5      nU HM  nUR                  UR                  5      nUc  [	        5       nU R                  U5        UR                  U5        MO     U  H  nUR                  U;  d  M  SUl        M     g)a  
Convenience method that merges the current pofile with the pot file
provided. It behaves exactly as the gettext msgmerge utility:

* comments of this file will be preserved, but extracted comments and
  occurrences will be discarded;
* any translations or comments in the file will be discarded, however,
  dot comments and file positions will be preserved;
* the fuzzy flags are preserved.

Keyword argument:

``refpot``
    object POFile, the reference catalog.
c              3   <   #    U  H  oR                   U4v   M     g 7fr   r   .0r   s     r   	<genexpr>POFile.merge.<locals>.<genexpr>  s      
;?%%%u-4s   c              3   8   #    U  H  oR                   v   M     g 7fr   r=  r>  s     r   r@  rA    s     I&44&s   NT)dictsetr&   r   r   r   merger   )r   refpotself_entriesrefpot_msgidsr   r   s         r   rE  POFile.merge  s    "  
;?
 
 I&IIE  !9!9:AyIAGGEN  E''}<!% r   r   N)r  r  r  r  r  r   r%  r-  r   r3  r6  r   rE  r  r   r   r   r   r   u  s/    1$	1	43!,/&r   r   c                   T    \ rS rSrSrSrSrS rS rSS jr	S	 r
S
 rS rS rS rSrg)r   i  z}
Mo file reader/writer.
This class inherits the :class:`~polib._BaseFile` class and, by
extension, the python ``list`` type.
l   * l   $< c                 T    [         R                  " U /UQ70 UD6  SU l        SU l        g)zZ
Constructor, accepts all keywords arguments accepted by
:class:`~polib._BaseFile` class.
Nr   )r   r   magic_numberversionr   r   r,   s      r   r   MOFile.__init__  s+    
 	41$1&1 r   c                 .    [         R                  X5        g)zy
Saves the mofile as a pofile to ``fpath``.

Keyword argument:

``fpath``
    string, full or relative path to the file.
Nr#  r$  s     r   save_as_pofileMOFile.save_as_pofile  s     	t#r   Nc                 0    [         R                  XS5        g)zm
Saves the mofile to ``fpath``.

Keyword argument:

``fpath``
    string, full or relative path to the file.
r   Nr#  r$  s     r   r   MOFile.save  r'  r   c                     g)F
Convenience method to keep the same interface with POFile instances.
r)  r   r   s    r   r-  MOFile.percent_translated	  s     r   c                     U $ rV  r   r   s    r   r   MOFile.translated_entries  s	     r   c                     / $ rY  r   r   s    r   r3  MOFile.untranslated_entries  	     	r   c                     / $ rY  r   r   s    r   r6  MOFile.fuzzy_entries  r]  r   c                     / $ rY  r   r   s    r   r   MOFile.obsolete_entries!  r]  r   )rL  rM  r   )r  r  r  r  r  r   MAGIC_SWAPPEDr   rQ  r   r-  r   r3  r6  r   r  r   r   r   r   r     s;    
 EM	$	1r   r   c                   f    \ rS rSrSrS rSS jr\(       a  S rOS rS r	 SS jr
\S	 5       rS
rg)
_BaseEntryi*  z
Base class for :class:`~polib.POEntry` and :class:`~polib.MOEntry` classes.
This class should **not** be instantiated directly.
c                 N   UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  S0 5      U l        UR                  SS5      U l        UR                  SS	5      U l        UR                  S
[        5      U l        g)a  
Constructor, accepts the following keyword arguments:

``msgid``
    string, the entry msgid.

``msgstr``
    string, the entry msgstr.

``msgid_plural``
    string, the entry msgid_plural.

``msgstr_plural``
    list, the entry msgstr_plural lines.

``msgctxt``
    string, the entry context (msgctxt).

``obsolete``
    bool, whether the entry is "obsolete" or not.

``encoding``
    string, the encoding to use, defaults to ``default_encoding``
    global variable (optional).
r   r   r   r   r   r   Nr   Fr!   )	r&   r   r   r   r   r   r   r	   r!   rN  s      r   r   _BaseEntry.__init__0  s    4 ZZ,
jj2."JJ~r:#ZZ<zz)T2

:u5

:/?@r   c           	         U R                   (       a  SnOSn/ nU R                  b!  X0R                  SUSU R                  U5      -  nX0R                  SUSU R                  U5      -  nU R                  (       a!  X0R                  SUSU R                  U5      -  nU R
                  (       aP  U R
                  n[        U5      nUR                  5         U H"  nXF   nSU-  nX0R                  SX(UU5      -  nM$     O!X0R                  SUSU R                  U5      -  nUR                  S5        [        S5      R                  U5      nU$ )	2
Returns the unicode representation of the entry.
z#~ r   r   r   r   z[%s]r   rb   )r   r   
_str_fieldr   r   r   r   r   r   r   r   r   )	r   r$   delflagr   msgstrsr   r   r   plural_indexs	            r   r   _BaseEntry.__unicode__R  s6    ==GG<<#??9gr4<<#,. .C 	wTZZKK??>7B#'#4#4iA AC((G=DIIK %~x'02 2  ??8Wb$++#,. .C

2gll3
r   c                 "    U R                  5       $ r   r   r   s    r   r   _BaseEntry.__str__x  r   r   c                 J    [        U 5      R                  U R                  5      $ )z1
Returns the string representation of the entry.
r   r   s    r   r   ro  {  r   r   c                 0    [        U 5      [        U5      :H  $ r   r   r   s     r   r   _BaseEntry.__eq__  r   r   c           	         UR                  S5      n[        U5      S:  a  S/U-   nO[        U5      nSnS H  n	XR                  U	5      -  nM     [        U5      S-   n
U(       a  U
[        U5      -  n
XZ-
  U-   nUS:  aH  [        U5      U:  a9  S/[        R
                  " UUS-
  SSS	9 Vs/ s H  n[        U5      PM     sn-   nOU/nUR                  S
5      (       a  USS  nU< U< U< S[        UR                  S5      5      < S3/nU H%  nUR                  U< S[        U5      < S35        M'     U$ s  snf )NTrF   r   r   )r_   rb   ra   r`   rc   r   r   F)drop_whitespacebreak_long_words	previous_	   z "rc   )

splitlinesr   r
   counttextwrapwrapr   
startswithr   r   )r   	fieldnamerj  rl  fieldr$   linesescaped_fieldspecialchars_country   flengthreal_wrapwidthitemr   r]   s                  r   ri  _BaseEntry._str_field  sI     &u:>D5LE"5MM!"2"kk!n4" 3 )nq(G3|,,&03EEN1}Un!<8==!M$)%*	<   <4 <    ,,!!"I 'L &uyy| 46 7DJJ7F4L9: 
! s   .D=c                 z    U R                   (       a  U R                   < S< U R                  < 3$ U R                  $ )Nr   r   r   s    r   r   _BaseEntry.msgid_with_context  s(    <<#||VTZZ@@zzr   )r!   r   r   r   r   r   r   Nr%   )r  r  r  r  r  r   r   rN   r   r   ri  propertyr   r  r   r   r   rd  rd  *  sG    
 AD#J 	&	7'  "H  r   rd  c                   t    \ rS rSrSrS rSS jrS rS rS r	S r
S	 rS
 rS rS rS r\S 5       rS rSrg)r   i  z
Represents a po file entry.
c                    [         R                  " U /UQ70 UD6  UR                  SS5      U l        UR                  SS5      U l        UR                  S/ 5      U l        UR                  S/ 5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  S	S5      U l	        UR                  S
S5      U l
        g)a  
Constructor, accepts the following keyword arguments:

``comment``
    string, the entry comment.

``tcomment``
    string, the entry translator comment.

``occurrences``
    list, the entry occurrences.

``flags``
    list, the entry flags.

``previous_msgctxt``
    string, the entry previous context.

``previous_msgid``
    string, the entry previous msgid.

``previous_msgid_plural``
    string, the entry previous msgid_plural.

``linenum``
    integer, the line number of the entry
commentr   tcommentoccurrencesr   previous_msgctxtNprevious_msgidprevious_msgid_plurallinenum)rd  r   r&   r  r  r  r   r  r  r  r  rN  s      r   r   POEntry.__init__  s    8 	D24262zz)R0

:r2!::mR8ZZ,
 &

+=t D$jj)94@%+ZZ0G%N"zz)T2r   c                    / nU R                   (       a  S/nOSS/nU H  n[        XS   5      nU(       d  M  UR                  S5       Hd  nUS:  aA  [        U5      [        US   5      -   U:  a#  U[        R
                  " UUUS   US   SS9-  nMJ  UR                  US   < U< 35        Mf     M     U R                   (       d  U R                  (       a  / nU R                   H7  u  pU	(       a  UR                  U< SU	< 35        M&  UR                  U5        M9     S	R                  U5      n
US:  a^  [        U
5      S
-   U:  aL  U[        R
                  " U
R                  SS5      USSSS9 Vs/ s H  oR                  SS5      PM     sn-  nOUR                  SU
-   5        U R                  (       a-  UR                  SSR                  U R                  5      -  5        / SQnU R                   (       a  SnOSnU H,  n[        X5      nU(       d  M  X R                  XSXQ5      -  nM.     UR                  [        R                  X5      5        [        S5      R                  U5      nU$ s  snf )rh  )r  z# )r  z#. r   rb   rF   F)initial_indentsubsequent_indentru  r   r   -*z#: z#, %sz, )r  r  r  z#~| z#| r   )r   r   rw   r   rz  r{  r   r  r   rd   r   ri  rd  r   r   )r   r$   r   commentsry   valr  filelistr   linenofilestrr]   fieldsprefixr*   s                  r   r   POEntry.__unicode__  s*    ==*+H*,>?HA$!%Cs"yyG 1}WAaD	)AI)Mx}}#%+,Q4./d-2   

QqT7#;<  /   }}!1!1H!%!1!1OOuf$=>OOE*	 "2
 hhx(G1}W!1I!=
 8==OOC-#(&+%*<  <4S#. <   

57?+ ::JJw4::!667+==FFA$"Csq"cEE 
 	

:))$:;gll3
9s   4I3c                    U R                   UR                   :w  a  U R                   (       a  gg[        U R                  SS 5      n[        UR                  SS 5      nX#:  a  gX#:  a  gU R                  =(       d    SnUR                  =(       d    SnXE:  a  gXE:  a  gU R                  =(       d    SnUR                  =(       d    SnXg:  a  gXg:  a  gU R
                  =(       d    SnUR
                  =(       d    Sn	X:  a  gX:  a  gU R                  UR                  :  a  gU R                  UR                  :  a  gU R                  UR                  :  a  gU R                  UR                  :  a  gg)zD
Called by comparison operations if rich comparison is not defined.
r   rF   N0r   )r   r}   r  r   r   r   r   r   )
r   r   occ1occ2r   othermsgctxtr   othermsgid_pluralr   othermsgstr_plurals
             r   __cmp__POEntry.__cmp__!  s>   
 ==ENN*}}d&&q)*e''*+;;,,%#}}+!#((/C!..5#+-**1c"007C-/::#ZZ%++%;;%[[5<<'r   c                 *    U R                  U5      S:  $ Nr   r  r   s     r   __gt__POEntry.__gt__S      ||E"Q&&r   c                 *    U R                  U5      S:  $ r  r  r   s     r   __lt__POEntry.__lt__V  r  r   c                 *    U R                  U5      S:  $ r  r  r   s     r   __ge__POEntry.__ge__Y      ||E"a''r   c                 *    U R                  U5      S:*  $ r  r  r   s     r   __le__POEntry.__le__\  r  r   c                 *    U R                  U5      S:H  $ r  r  r   s     r   r   POEntry.__eq___  r  r   c                 *    U R                  U5      S:g  $ r  r  r   s     r   __ne__POEntry.__ne__b  r  r   c                     U R                   (       d  U R                  (       a  gU R                  S:w  a  gU R                  (       a)  U R                   H  nU R                  U   S:X  d  M    g   gg)zK
Returns ``True`` if the entry has been translated or ``False``
otherwise.
Fr   T)r   r   r   r   )r   poss     r   r,  POEntry.translatede  sZ    
 ==DJJ;;"))%%c*b0  * r   c                 d   UR                   U l         UR                  U l        UR                  U l        UR                  U l        U R                  nUR
                  SS U l        U(       a  U R
                  R                  S5        UR                  U l        UR                  U l        UR                  U l	        UR                  U l
        UR                  U l        UR                  (       a$  UR                   H  n U R                  U     M     gg! [         a    SU R                  U'    M5  f = f)z3
Merge the current entry with the given pot entry.
Nr   r   )r   r   r  r  r   r   r   r   r   r  r  r  r   r   )r   r   r   r  s       r   rE  POEntry.mergeu  s     [[
}} ,,}}

[[^
JJg&!.. % 6 6#22%*%@%@"**1&&s+ + 
   1.0D&&s+1s   =DD/.D/c                      SU R                   ;   $ )Nr   )r   r   s    r   r   POEntry.fuzzy  s    $**$$r   c                 D    [        U R                  U R                  45      $ r   hashr   r   r   s    r   __hash__POEntry.__hash__      TZZ-..r   )r  r   r  r   r   r   r   r  r  r  r  r  Nr  )r  r  r  r  r  r   r   r  r  r  r  r  r   r  r,  rE  r  r   r  r  r   r   r   r   r     s[    $3LCJ0d''(((( 12 % %/r   r   c                   $    \ rS rSrSrS rS rSrg)r   i  z
Represents a mo file entry.
c                     [         R                  " U /UQ70 UD6  SU l        SU l        / U l        / U l        SU l        SU l        SU l        g)aa  
Constructor, accepts the following keyword arguments,
for consistency with :class:`~polib.POEntry`:

``comment``
``tcomment``
``occurrences``
``flags``
``previous_msgctxt``
``previous_msgid``
``previous_msgid_plural``

Note: even though these keyword arguments are accepted,
they hold no real meaning in the context of MO files
and are simply ignored.
r   N)	rd  r   r  r  r  r   r  r  r  rN  s      r   r   MOEntry.__init__  sQ    " 	D24262
 $"%)"r   c                 D    [        U R                  U R                  45      $ r   r  r   s    r   r  MOEntry.__hash__  r  r   )r  r   r  r  r  r  r  N)r  r  r  r  r  r   r  r  r   r   r   r   r     s    *4/r   r   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rSrg)r'   i  zK
A finite state machine to parse efficiently and correctly po
file format.
c                 F   UR                  S[        5      n[        U5      (       a   [        R                  " USUS9U l        OUR                  5       U l        UR                  S5      nUc  [        nU" UUUR                  SS5      S9U l	        0 U l
        S	U l        [        U R                  S
9U l        SU l        SU l        S	U l        S	U l        / SQnU R%                  SSS/S5        U R%                  S/ SQS5        U R%                  SUS5        U R%                  SUS5        U R%                  SUS5        U R%                  SUS5        U R%                  SUS5        U R%                  SUS5        U R%                  S/ SQS5        U R%                  S/ SQS5        U R%                  S/ SQS5        U R%                  S/ SQS5        U R%                  S/ SQS5        U R%                  S / S!QS 5        g! [         a%    [        n[        R                  " USUS9U l         GNf = f)"aV  
Constructor.

Keyword arguments:

``pofile``
    string, path to the po file or its content

``encoding``
    string, the encoding to use, defaults to ``default_encoding``
    global variable (optional).

``check_for_duplicates``
    whether to check for duplicate entries when adding entries to the
    file (optional, default: ``False``).
r!   rt)r!   r#   Nr"   F)r   r!   r"   r   r  re   )re   hegcocflctpcpmpptcmsmpmxmir  r  )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )re   r  r  r  r  r  r  r  r  r  r  r  )re   r  r  r  r  r  r  r  r  r  r  r  r  )r  r  r  r  r  r  r  )r  r  r  r  )r  r  r  r  mc)r  r  r  r  r  r  r  r  )r&   r	   r:   r   rO   r   rB   rx  r   r0   transitionscurrent_liner   current_entrycurrent_statecurrent_tokenmsgstr_indexentry_obsoleteadd)r   r   r   r,   r-   r#   alls          r   r   _POFileParser.__init__  s   " jj%56FC!wwvtcB
 ",,.DL

7#=E!',BE!J

 $T->->?!!$' 	d|N *IM	OsNsNsNsNsNsN *IM	O )IM	O;N)N/NGNu  C&!wwvtcBCs   G1 1+H H c           
      |   SSSSS.nSSSS	.n/ nU R                   R                  (       a  S
U R                   R                  -  OSnU R                   GH  nU =R                  S-  sl        U R                  S:X  aC  [        R
                  R                  S5      nUR                  U5      (       a  U[        U5      S nUR                  5       nUS:X  a  M  UR                  SS5      n[        U5      nUS   S:X  a  M  US   S:X  a+  US:  a%  USS R                  5       nUSS nUS-  nSU l        OSU l        US   U;   a  US:  a{  U[        US   5      S R                  5       n[        R                  " SUSS 5      (       a  [        SU< SU R                  < S35      eXPl        U R#                  XS      5        GMq  XPl        US   S:X  a  US::  a  GM  U R#                  S5        GM  USS S:X  aQ  [        R                  " SUSS 5      (       a  [        SU< SU R                  < S35      eU R#                  S5        GM  USS S:X  a  U R#                  S5        GM  US   S :X  a  US::  a  GM&  U R#                  S!5        GM:  US   S":X  d  US   R                  S#5      (       a  US":X  a  US$-  nU R#                  S%5        GM{  US   S&:X  a  US::  a  GM  U R#                  S'5        GM  US   S(:X  a  US::  a  [        SU< SU R                  < S)35      eUSS R                  5       nXPl        US   R                  S5      (       a  U R#                  S5        GM  US:X  a  [        SU< SU R                  < S*35      eUS   U;  a$  [        SU< SU R                  < S+US   < 35      eU[        US   5      S R                  5       nXPl        U R#                  X#S      5        GM  [        SU< SU R                  < S)35      e   U R$                  (       aM  [        U5      S:  a>  US   R                  S"5      (       d%  U R                   R'                  U R$                  5        U R                   R)                  S5      nU(       a  U R                   R+                  U5        UR,                  U R                   l        Sn	UR0                  R3                  5        H?  n
 U
R                  S,S5      u  pUR                  5       U R                   R4                  U	'   MA     [;        U R                  [<        5      (       d  U R                  R?                  5         U R                   $ ! [6        [8        4 a<    U	b5  U R                   R4                  U	==   S-U
R                  5       -   -  ss'    M   M  f = f).zh
Run the state machine, parse the file line by line and call process()
with the current matched symbol.
r  r  r  r  )r   r   r   r   r  r  r  )r   r   r   z%s r   rF   r   Nr   r   z#~|z#~r   z
([^\\]|^)"r   zSyntax error in po file z(line z): unescaped double quote foundz#:r  rc   r     zmsgstr[r  z#,r  #z##r  r  z#.r  z#|)z): invalid continuation linez): unknown keyword r  rb   ) r0   r   r   r  r@   BOM_UTF8rT   r|  r   rM   rw   r  lstriprI   rK   r   r  processr  r   r   remover   r   r   rx  r   r7   r   rR   r   rQ   )r   keywordsprev_keywordstokensr   r]   BOM	nb_tokensmetadataentryrx   msgr  s               r   r)   _POFileParser.parse  s,     	
 !

 /3}}/B/B+++LLD"  A%oo,,W5??3''C	?D::<DrzZZa(FFIayE!ayD Y]ABx~~'Q	&'#&'# ayH$QCq	NO,33599]D2J77!#($*;*;#= > > &*"XQi01!%ayD >T"bqS99]D2J77!#($*;*;#= > > T"bqY&T"d">T"c!VAY%9%9$%?%?3;CKDT"d">T"d">!#($*;*;#= > > ABx(%)"!9'',,LL&>!#($*;*;#= > >
 !9M1!#($*;*;#)!9#. / / Cq	NO,335%)"]!956 $d&7&79 : :[ !` #f+/ay##C(( MM  !3!34 **2.MM  /.;.A.ADMM+C$++668J"yya0HC25))+DMM**3/ 9 $,,--LL }} #H- J..s3tciik7II3 'Js   +;U//AV;:V;c                 V    U H#  n[        U SU-  5      nXS4U R                  X4'   M%     g)z
Add a transition to the state machine.

Keywords arguments:

``symbol``
    string, the matched token (two chars symbol).

``states``
    list, a list of states (two chars symbols).

``next_state``
    the next state the fsm will have after the action.
z	handle_%sN)r   r  )r   symbolstates
next_statestateactions         r   r  _POFileParser.add  s4     ET;#;<F170DDf_- r   c                      U R                   XR                  4   u  p#U" 5       (       a  X0l        gg! [         a    [        SU R                  -  5      ef = f)z
Process the transition corresponding to the current state and the
symbol provided.

Keywords arguments:

``symbol``
    string, the matched token (two chars symbol).

``linenum``
    integer, the current line number of the parsed file.
z!Syntax error in po file (line %s)N)r  r  	Exceptionr   r  )r   r  r  r  s       r   r  _POFileParser.process  sa    	-"..8J8J/KLOVxx%*"  	-=++, - -	-s	   .2 #Ac                     U R                   R                  S:w  a  U R                   =R                  S-  sl        U R                   =R                  U R                  SS -  sl        g)zHandle a header comment.r   rb   r   NrF   )r0   r   r  r   s    r   	handle_he_POFileParser.handle_he  sN    ==2%MM  D(  2 212 66r   c                    U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        U R                  R                  S:w  a  U R                  =R                  S-  sl        U R                  R                  S5      nUR                  S5      (       a  USS nU R                  =R                  U-  sl        g	)
zHandle a translator comment.r  r  r  r  r   rb   r  r  rF   NT)
r  r0   r   r  r   r  r  r  r  r|  )r   r  s     r   	handle_tc_POFileParser.handle_tc  s    !33MM  !3!34!(1B1B!CD&&",''4/'%%,,S1s##|H##x/#r   c                 h   U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        U R                  R                  S:w  a  U R                  =R                  S-  sl        U R                  =R                  U R                  SS -  sl        g)zHandle a generated comment.r  r  r   rb   r   NT)r  r0   r   r  r   r  r  r  r   s    r   	handle_gc_POFileParser.handle_gc  s    !33MM  !3!34!(1B1B!CD%%+&&$.&""d&8&8&<<"r   c                    U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        U R                  SS R                  5       nU H_  nUS:w  d  M   UR                  SS5      u  p4UR                  5       (       d  UnSnU R                  R                  R                  X445        Ma     g! [        [        4 a+    U R                  R                  R                  US45         M  f = f)	zHandle a file:num occurrence.r  r  r   Nr   r  rF   T)r  r0   r   r  r   r  r  rw   rsplitrp   r  r7   AttributeError)r   r  
occurrencefilr]   s        r   	handle_oc_POFileParser.handle_oc  s    !33MM  !3!34!(1B1B!CD((,224%JRL * 1 1#q 9IC<<>>(!&&22993+F &  #N3 L&&2299:r:JKLs   9AC7DDc                 Z   U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        U R                  =R                  U R                  SS R                  S5       Vs/ s H  oR                  5       PM     sn-  sl        gs  snf )zHandle a flags line.r  r  r   Nr  T)
r  r0   r   r  r   r  r   r  rw   rM   )r   ry   s     r   	handle_fl_POFileParser.handle_fl  s    !33MM  !3!34!(1B1B!CD  %)%7%7%;%A%A#%F%H%F 45WWY%F%H 	H %Hs   B(c                     U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        [        U R                  SS 5      U R                  l        g)z$Handle a previous msgid_plural line.r  r  rF   r   T)	r  r0   r   r  r   r  r   r  r  r   s    r   	handle_pp_POFileParser.handle_pp  sb    !33MM  !3!34!(1B1B!CDT''"-. 	0r   c                     U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        [        U R                  SS 5      U R                  l        g)zHandle a previous msgid line.r  r  rF   r   T)	r  r0   r   r  r   r  r   r  r  r   s    r   	handle_pm_POFileParser.handle_pm  sb    !33MM  !3!34!(1B1B!CDT''"-. 	)r   c                     U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        [        U R                  SS 5      U R                  l        g)zHandle a previous msgctxt line.r  r  rF   r   T)	r  r0   r   r  r   r  r   r  r  r   s    r   	handle_pc_POFileParser.handle_pc'  sb    !33MM  !3!34!(1B1B!CDT''"-. 	+r   c                     U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        [        U R                  SS 5      U R                  l        g)zHandle a msgctxt.r  r  rF   r   T)	r  r0   r   r  r   r  r   r  r   r   s    r   	handle_ct_POFileParser.handle_ct0  s_    !33MM  !3!34!(1B1B!CD%-d.@.@2.F%G"r   c                 "   U R                   S;   a=  U R                  R                  U R                  5        [	        U R
                  S9U l        U R                  U R                  l        [        U R                  SS 5      U R                  l
        g)zHandle a msgid.r  r  rF   r   T)r  r0   r   r  r   r  r  r   r   r  r   r   s    r   	handle_mi_POFileParser.handle_mi8  ss    !33MM  !3!34!(1B1B!CD&*&9&9##+D,>,>q,D#E r   c                 R    [        U R                  SS 5      U R                  l        g)zHandle a msgid plural.rF   r   T)r   r  r  r   r   s    r   	handle_mp_POFileParser.handle_mpA  s%    *243E3Ea3K*L'r   c                 R    [        U R                  SS 5      U R                  l        g)zHandle a msgstr.rF   r   T)r   r  r  r   r   s    r   	handle_ms_POFileParser.handle_msF  s%    $,T-?-?"-E$F!r   c                     U R                   S   nU R                   U R                   R                  S5      S-   S n[        U5      U R                  R                  [        U5      '   [        U5      U l        g)zHandle a msgstr plural.r  rc   rF   r   T)r  r   r   r  r   rq   r  )r   r   r   s      r   	handle_mx_POFileParser.handle_mxK  sg    ""1%""4#5#5#:#:3#?!#CBG7?((U4Jr   c                 J   [        U R                  SS 5      nU R                  S:X  a   U R                  =R                  U-  sl        gU R                  S:X  a   U R                  =R
                  U-  sl        gU R                  S:X  a   U R                  =R                  U-  sl        gU R                  S:X  a   U R                  =R                  U-  sl        gU R                  S:X  a,  U R                  R                  U R                  ==   U-  ss'   gU R                  S:X  a   U R                  =R                  U-  sl
        gU R                  S	:X  a   U R                  =R                  U-  sl        gU R                  S
:X  a  U R                  =R                  U-  sl        g)z+Handle a msgid or msgstr continuation line.rF   r   r  r  r  r  r  r  r  r  F)r   r  r  r  r   r   r   r   r   r  r  r  r  )r   tokens     r   	handle_mc_POFileParser.handle_mcS  s   ++Ab12%&&%/&   4'$$-$  4'++u4+  4'%%.%  4',,T->->?5H?  4'44=4  4'--6-  4'//58/r   )	r  r  r  r  r  r   r0   r  r  N)r  r  r  r  r  r   r)   r  r  r	  r  r  r  r  r  r   r#  r&  r)  r,  r/  r2  r6  r  r   r   r   r'   r'     sg    
OOb\|E&-.$

r   r'   c                   >    \ rS rSrSrS rS rS r  S
S jrS r	S	r
g)r(   il  z#
A class to parse binary mo files.
c                     [        US5      U l        UR                  S5      nUc  [        nU" UUR                  S[        5      UR                  SS5      S9U l        g)aV  
Constructor.

Keyword arguments:

``mofile``
    string, path to the mo file or its content

``encoding``
    string, the encoding to use, defaults to ``default_encoding``
    global variable (optional).

``check_for_duplicates``
    whether to check for duplicate entries when adding entries to the
    file (optional, default: ``False``).
rG   r#   Nr!   r"   F)r   r!   r"   )rO   r   r&   r   r	   r0   )r   r   r   r,   r#   s        r   r   _MOFileParser.__init__q  sW    " FD)

7#=EZZ
,<=!',BE!J
r   c                 \    U R                   (       a  U R                   R                  5         gg)zn
Make sure the file is closed, this prevents warnings on unclosed file
when running tests with python >= 3.2.
N)r   rQ   r   s    r   __del___MOFileParser.__del__  s     
 <<LL  r   c                    U R                  SS5      nU[        R                  :X  a  SnO"U[        R                  :X  a  SnO[	        S5      eXR
                  l        U R                  US5      u  p4US-	  S;  a  [	        S	5      eX0R
                  l        U R                  US5      u  pVU R                  R                  U5        / n[        U5       H$  nUR                  U R                  US5      5        M&     U R                  R                  U5        / n	[        U5       H$  nU	R                  U R                  US5      5        M&     U R
                  R                  n
[        U5       GH  nU R                  R                  Xx   S
   5        U R                  R                  Xx   S   5      nU R                  R                  X   S
   5        U R                  R                  X   S   5      nUS:X  a  U(       d  UR                  [        S5      5      0 pU Hn  nUR                  [        S5      S
5      nUS   [        S5      :w  d  M2   US   R!                  U
5      nUS
   R!                  U
5      nUR#                  5       UU'   Mp     XR
                  l        GM3  UR                  [        S5      5      n[+        U5      S
:  aI  U R-                  US   US
   [/        S [1        UR                  [        S5      5      5       5       5      S9nOU R-                  XS9nU R
                  R                  U5        GM     U R                  R3                  5         U R
                  $ ! [$         a    ['        S5      UW'    GMh  f = f)zF
Build the instance with the file handle provided in the
constructor.
z<I   z<IIz>IIz,Invalid mo file, magic number is incorrect !r   r   )r   rF   z1Invalid mo file, unexpected major revision numberrF   r   rb   r  r   r   c              3   ,   #    U  H
  u  pX4v   M     g 7fr   r   )r?  kvs      r   r@  &_MOFileParser.parse.<locals>.<genexpr>  s      'I'G 37!v'Gs   )r   r   r   )r   r   )_readbinaryr   r   rb  r   r0   rL  rM  r   seekranger   r!   readrw   r   rT   rM   
IndexErrorr   r   r   _build_entryrC  	enumeraterQ   )r   rL  iirM  numofstringsmsgids_hash_offsetmsgstrs_hash_offsetmsgids_indexr   msgstrs_indexr!   r   r   raw_metadatar   r]   r  rA  rB  msgid_tokensr   s                        r   r)   _MOFileParser.parse  s    ''a06<<'BV111BHII%1" $ 0 0Q 7 b=&MNN '262B2B2q2I/,-|$A 0 0Q 78 % 	-.|$A  !1!1"a!89 % ==))|$ALLloa01LL%%loa&89ELLm.q12\\&&}'7':;FAve)/ag)>h(D!ZZ#2FayAbE)0 &q	 0 0 :A &q	 0 0 :A*+'')HQK ) *2& ;;qw/L< 1$))&q/!-a"& 'I'0ag1F'G'I #I *  )))EMM  '= %@ 	}}%  * 0*+B%HQK0s   
;M##N ?N Nc                    UR                  [        S5      5      nU R                  R                  n[	        U5      S:  a*  US   R                  U5      US   R                  U5      S.nOSUR                  U5      0nU(       a  UR                  U5      US'   U(       a  UR                  U5      US'   U(       a"  U H  nXH   R                  U5      XH'   M     XGS'   [        S	0 UD6$ )
Nr   rF   r   r   r   r   r   r   r   )rw   r   r0   r!   r   rT   r   )	r   r   r   r   r   msgctxt_msgidr!   r,   rA  s	            r   rI  _MOFileParser._build_entry  s    AfI.==))}!(+228<&q)00:F
 u||H56F%}}X6F8%1%8%8%BF>""#0#3#:#:8#D  #&3?#   r   c                     U R                   R                  U5      n[        R                  " X5      n[	        U5      S:X  a  US   $ U$ )z~
Private method that unpack n bytes of data using format <fmt>.
It returns a tuple or a mixed value if the tuple length is 1.
rF   r   )r   rG  r   unpackr   )r   fmtnumbytesbytestups        r   rD  _MOFileParser._readbinary  s?    
 !!(+mmC's8q=q6M
r   )r   r0   )NNN)r  r  r  r  r  r   r<  r)   rI  rD  r  r   r   r   r(   r(   l  s+    
8!DL =A#'!*	r   r(   )F)&r  r  r@   r3   rI   r   r   rz  r   
__author____version____all__r	   r   rN   r   rS   r   r   r   r1   r:   r   r   r   r
   r   r   r   r   r   r   objectrd  r   r   r'   r(   r   r   r   <module>rb     s!     	 	  
  	 5
J
  
 BQ& 
CI, CI#2$9@9B4r	#8*)"[ [@g&Y g&XDY DRB BNb/j b/N/j /JjF j^MF Mr   