+
    *:gce                       R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHtH	t	 ^ RI
Ht ^ RIHtHt ^ RIHtHt ]'       d   ^ RIHtHt ^ R	IHt R
 R ltR R ltR R lt ! R R]4      t ! R R4      t ! R R4      tR.R R llt]P<                  ! R4      tR R lt R/R R llt!R R lt"R0R! R" llt#R#RR$R R%RR&RR'RR(RR)^L/R* R+ llt$R, R- lt%R# )1z
babel.messages.pofile
~~~~~~~~~~~~~~~~~~~~~

Reading and writing of files in the ``gettext`` PO (portable object)
format.

:copyright: (c) 2013-2025 by the Babel Team.
:license: BSD, see LICENSE for more details.
)annotationsN)Iterable)TYPE_CHECKINGLiteral)Locale)CatalogMessage)TextWrapper_cmp)IOAnyStr)SupportsWritec                    V ^8  d   QhRRRR/#    stringstrreturn )formats   "7/usr/lib/python3/dist-packages/babel/messages/pofile.py__annotate__r      s     J JS JS J    c                X    R p\         P                  ! R4      P                  W^R 4      # )zReverse `escape` the given string.

>>> print(unescape('"Say:\\n  \\"hello, world!\\"\\n"'))
Say:
  "hello, world!"
<BLANKLINE>

:param string: the string to unescape
c                ^    V P                  ^4      pVR8X  d   R# VR8X  d   R# VR8X  d   R# V# )   n
t	r)group)matchms   & r   replace_escapes!unescape.<locals>.replace_escapes&   s2    KKN8#X#Xr   z\\([\\trn"]))recompilesub)r   r%   s   & r   unescaper+      s)    	 ::o&**?1RLIIr   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r   3   s            r   c                    RV 9   dR   V P                  4       pV P                  R4      '       d
   VR,          p\        \        V4      pRP	                  V4      # \        V 4      # )a  Reverse the normalization done by the `normalize` function.

>>> print(denormalize(r'''""
... "Say:\n"
... "  \"hello, world!\"\n"'''))
Say:
  "hello, world!"
<BLANKLINE>

>>> print(denormalize(r'''""
... "Say:\n"
... "  \"Lorem ipsum dolor sit "
... "amet, consectetur adipisicing"
... " elit, \"\n"'''))
Say:
  "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
<BLANKLINE>

:param string: the string to denormalize
r   ""r   NN )
splitlines
startswithmapr+   join)r   escaped_linesliness   &  r   denormalizer7   3   sY    * v~))+T"")"-MHm,wwu~r   c                    V ^8  d   QhRRRR/# )r   liner   r   z	list[str]r   )r   s   "r   r   r   R   s     ) )S )Y )r   c                   RV 9  d&   RV 9  d   V P                  4       P                  4       # . pRpRpV  F  pVR8X  d   V'       d   \        R4      hRpK!  VR8X  d   V'       g   \        R4      hRpK?  VR8X  d2   V'       d   W$,          pKX  V'       d   VP                  V4       RpKu  Kw  W$,          pK  	  V'       d%   V'       d   \        R4      hVP                  V4       V# )	zExtract locations from location comments.

Locations are extracted while properly handling First Strong
Isolate (U+2068) and Pop Directional Isolate (U+2069), used by
gettext to enclose filenames with spaces and tabs in their names.
   ⁨   ⁩r0   Fzglocation comment contains more First Strong Isolate characters, than Pop Directional Isolate charactersTzglocation comment contains more Pop Directional Isolate characters, than First Strong Isolate characters )lstripsplit
ValueErrorappend)r9   	locationslocationin_filenamecs   &    r   _extract_locationsrF   R   s     t 4{{}""$$IHK=  "W X XK(]  "T U UK#X  *  MH) ,   "W X XX&r   c                  2   a  ] tR t^~tRtR V 3R lltRtV ;t# )PoFileErrorzDException thrown by PoParser when an invalid po file is encountered.c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r   messager   catalogr   r9   linenointr   Noner   )r   s   "r   r   PoFileError.__annotate__   s0       g S # RV r   c                	T   < \         SV `  V R V 24       W n        W0n        W@n        R# )z on N)super__init__rK   r9   rL   )selfrJ   rK   r9   rL   	__class__s   &&&&&r   rR   PoFileError.__init__   s*    G9D12	r   )rK   r9   rL   )__name__
__module____qualname____firstlineno____doc__rR   __static_attributes____classcell__)rT   s   @r   rH   rH   ~   s    N r   rH   c                      ] tR t^tR R ltR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltRtR# )_NormalizedStringc                    V ^8  d   QhRRRR/# )r   argsr   r   rN   r   )r   s   "r   r   _NormalizedString.__annotate__   s      c d r   c                	H    . V n         V F  pV P                  V4       K  	  R # N)_strsrA   )rS   r`   args   &* r   rR   _NormalizedString.__init__   s     "
CKK r   c                    V ^8  d   QhRRRR/# )r   sr   r   rN   r   )r   s   "r   r   ra      s     % % % %r   c                	X    V P                   P                  VP                  4       4       R # rc   )rd   rA   strip)rS   rh   s   &&r   rA   _NormalizedString.append   s    

!'')$r   c                   V ^8  d   QhRR/# r   r   r   r   )r   s   "r   r   ra      s     2 2S 2r   c                	T    R P                  \        \        V P                  4      4      # r0   )r4   r3   r+   rd   rS   s   &r   r7   _NormalizedString.denormalize   s    wws8TZZ011r   c                   V ^8  d   QhRR/# )r   r   boolr   )r   s   "r   r   ra      s        $  r   c                	,    \        V P                  4      # rc   )rs   rd   rp   s   &r   __bool___NormalizedString.__bool__   s    DJJr   c                   V ^8  d   QhRR/# rm   r   )r   s   "r   r   ra      s     + +# +r   c                	T    \         P                  P                  V P                  4      # rc   )oslinesepr4   rd   rp   s   &r   __repr___NormalizedString.__repr__   s    zztzz**r   c                    V ^8  d   QhRRRR/# )r   otherobjectr   rM   r   )r   s   "r   r   ra      s     + +V + +r   c                	R    V'       g   ^# \        \        V 4      \        V4      4      # )r   )r
   r   rS   r~   s   &&r   __cmp___NormalizedString.__cmp__   s    CIs5z**r   c                    V ^8  d   QhRRRR/# r   r~   r   r   rs   r   )r   s   "r   r   ra           ' 'F 't 'r   c                	*    V P                  V4      ^ 8  #     r   r   s   &&r   __gt___NormalizedString.__gt__       ||E"Q&&r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   ra      r   r   c                	*    V P                  V4      ^ 8  # r   r   r   s   &&r   __lt___NormalizedString.__lt__   r   r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   ra           ( (F (t (r   c                	*    V P                  V4      ^ 8  # r   r   r   s   &&r   __ge___NormalizedString.__ge__       ||E"a''r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   ra      r   r   c                	*    V P                  V4      ^ 8*  # r   r   r   s   &&r   __le___NormalizedString.__le__   r   r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   ra      r   r   c                	*    V P                  V4      ^ 8H  # r   r   r   s   &&r   __eq___NormalizedString.__eq__   r   r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   ra      r   r   c                	*    V P                  V4      ^ 8g  # r   r   r   s   &&r   __ne___NormalizedString.__ne__   r   r   )rd   N)rV   rW   rX   rY   rR   rA   r7   ru   r{   r   r   r   r   r   r   r   r[   r   r   r   r^   r^      sC    
%2 ++''(((( (r   r^   c                      ] tR t^tRt. ROtRR R lltR R ltR R ltR R	 lt	RR
 R llt
RR R lltR R ltR R ltR R ltR R ltRtR# )PoFileParserzSupport class to  read messages from a ``gettext`` PO (portable object) file
and add them to a `Catalog`

See `read_po` for simple cases.
c               (    V ^8  d   QhRRRRRRRR/# )r   rK   r   ignore_obsoleters   abort_invalidr   rN   r   )r   s   "r   r   PoFileParser.__annotate__   s*     $ $ $$ $W[ $hl $r   c                	f    Wn         W n        ^ V n        ^ V n        W0n        V P                  4        R# )r   N)rK   r   counteroffsetr   _reset_message_state)rS   rK   r   r   s   &&&&r   rR   PoFileParser.__init__   s-    .*!!#r   c                   V ^8  d   QhRR/# r   r   rN   r   )r   s   "r   r   r      s        d  r   c                	    . V n         . V n        . V n        . V n        . V n        . V n        R V n        RV n        RV n        RV n	        RV n
        R # )NF)messagestranslationsrB   flagsuser_commentsauto_commentscontextobsoletein_msgid	in_msgstr
in_msgctxtrp   s   &r   r   !PoFileParser._reset_message_state   sR    
r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r      s     $ $d $r   c                (   V P                   P                  4        \        V P                  4      ^8  dB   \        ;QJ d    . R V P                   4       F  NK  	  5M! R V P                   4       4      pM!V P                  ^ ,          P                  4       p\        V\        \        34      '       d   \        V P                  P                  4       Uu. uF  pRNK  	  ppV P                    FP  w  rEW@P                  P                  8  d    V P                  RV P                  R4       K>  VP                  4       W4&   KR  	  \	        V4      pM(V P                   ^ ,          ^,          P                  4       pV P                  '       d   V P                  P                  4       MRp\        W\        V P                  4      \!        V P"                  4      V P$                  V P&                  V P                  ^,           VR7      pV P(                  '       dE   V P*                  '       g2   WpP                  P(                  V P                  P-                  W4      &   MWpP                  V&   V ;P.                  ^,          un        V P1                  4        R# u upi )zw
Add a message to the catalog based on the current parser state and
clear the state ready to process the next message.
c              3  @   "   T F  qP                  4       x  K  	  R # 5irc   )r7   ).0r$   s   & r   	<genexpr>,PoFileParser._add_message.<locals>.<genexpr>   s     A=a--//=s   r0   z5msg has more translations than num_plurals of catalogN)rL   r   )r   sortlenr   tupler7   
isinstancelistrangerK   num_plurals_invalid_pofiler   r   r   rB   setr   r   r   r   r   _key_forr   r   )rS   msgid_r   idxtranslationmsgctxtrJ   s   &       r   _add_messagePoFileParser._add_message   s   
 	 t}}!EA4==AEEA4==AAEMM!$002EedE]++"'(@(@"AB"AQb"AFB$($5$5 ,,222((T[[:qr)557	 %6
 6]F&&q)!,88:F04$,,**,$%dnn)=s4::,,d.@.@WX")+ ==='''OV%%dll&;&;E&KL")LL!!#' Cs   Jc                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r      s          r   c                	>   V P                   '       d   V P                  '       gg   V P                  R V P                  RV P                   ^ ,          P	                  4        R24       V P                  P                  ^ \        R 4      .4       V P                  4        R# R# )r0   zmissing msgstr for msgid ''N)r   r   r   r   r7   rA   r^   r   rp   s   &r   _finish_current_message$PoFileParser._finish_current_message   s    ===$$$$$R8RSWS`S`abScSoSoSqRrrs6tu!!((!->r-B)CD	 r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r      s     ? ?T ?r   c                	~    VP                  R 4      '       d   V P                  W!4       R# V P                  WV4       R# )"N)r2   !_process_string_continuation_line_process_keyword_line)rS   rL   r9   r   s   &&&&r   _process_message_line"PoFileParser._process_message_line   s/    ??3224@&&vX>r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r     s     '2 '2T '2r   c                	j   V P                    FD  p VP                  V4      '       d*   V\        V4      ,          R9   d   V\        V4      R p MKD  KF  	  V P	                  W!R4       R# VR9   d   V P                  4        W0n        VR8X  d   Wn        VR9   d5   RV n        RV n	        V P                  P                  \        V4      4       R# VR	8X  d   RV n	        RV n        VP                  R4      '       dM   VR
,          P                  R^4      w  rgV P                  P                  \!        V4      \        V4      .4       R# V P                  P                  ^ \        V4      .4       R# VR8X  d   RV n        \        V4      V n        R# R#   \         d    T P	                  Y!R4        EK  i ; i)r=   [Nz$Keyword must be followed by a stringz0Start of line didn't match any expected keyword.r   r   FTmsgstrr/   ])r=   r   )r   r   )r   msgid_plural)	_keywordsr2   r   
IndexErrorr   r   r   r   r   r   r   rA   r^   r   r?   r   rM   r   )rS   rL   r9   r   keywordre   r   msgs   &&&&    r   r   "PoFileParser._process_keyword_line  s   ~~G[??7++S\0Bj0Ps7|}-C 1Q+ &   /ab**((*  g K//#DO DMMM  !23!78 !DM!DN~~c""r7==a0!!((#c(4Ec4J)KL!!((!->s-C)DE	!"DO,S1DL "=  [$$T3YZZ[s   <FF21F2c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   -  s     
 
 
r   c                	4   V P                   '       d   V P                  R,          pM`V P                  '       d   V P                  R,          ^,          pM3V P                  '       d   V P
                  pMV P                  WR4       R# VP                  V4       R# )r   z<Got line starting with " but not in msgid, msgstr or msgctxtNr'   )r   r   r   r   r   r   r   rA   )rS   r9   rL   rh   s   &&& r   r   .PoFileParser._process_string_continuation_line-  sh    ===b!A^^^!!"%a(A___A  /no	r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   9  s     8 8 8r   c                	   V P                  4        VR ,          P                  R4      '       d   \        VR,          4       Fo  pVP                  R4      pV^ 8  d8    \	        W#^,           R 4      pT P                  P                  TRT T34       KR  V P                  P                  VR34       Kq  	  R# VR ,          P                  R4      '       dY   VR,          P                  4       P                  R4       F,  pV P                  P                  VP                  4       4       K.  	  R# VR ,          P                  R4      '       d?   VR,          P                  4       pV'       d   V P                  P                  V4       R# R# V P                  P                  VR ,          P                  4       4       R#   \
         d     EK  i ; i)r/   :r   NNN,.)r   r2   rF   rfindrM   r@   rB   rA   r>   r?   r   rj   r   r   )rS   r9   rC   posrL   flagcomments   &&     r   _process_commentPoFileParser._process_comment9  s^   $$&8s##.tBx8nnS)!8!!$XAgh%7!8 NN))8DS>6*BCNN))8T*:; 9 "X  %%R)//4

!!$**,/ 5"X  %%2hnn&G""))'2  %%d2hnn&67 & ! !s   F::G
	G
c                    V ^8  d   QhRRRR/# )r   fileobjIO[AnyStr] | Iterable[AnyStr]r   rN   r   )r   s   "r   r   r   T  s        :  t  r   c           	        \        V4       F  w  r#VP                  4       p\        V\        4      '       g&   VP	                  V P
                  P                  4      pV'       g   KZ  VP                  R4      '       d]   VR,          P                  R4      '       d+   V P                  W#R,          P                  4       RR7       K   V P                  V4       K  V P                  W#4       K  	  V P                  4        V P                  '       g   V P                  '       g%   V P                   '       g   V P"                  '       d]   V P$                  P'                  \)        R4      4       V P*                  P'                  ^ \)        R4      .4       V P-                  4        R# R# R#   \         d(   pT P                  Y2\        T4      4        Rp?EK  Rp?ii ; i)	z
Reads from the file-like object `fileobj` and adds any po file
units found in it to the `Catalog` supplied to the constructor.
#r/   ~r   T)r   Nr.   )	enumeraterj   r   r   decoderK   charsetr2   r   r>   r   r@   r   r   r   r   r   r   r   rA   r^   r   r   )rS   r   rL   r9   excs   &&   r   parsePoFileParser.parseT  s`    &g.LF::<DdC(({{4<<#7#78s##8&&s++..vBx7HSW.XE--d3 **68 /" 	$$& |||t/A/A/ATEWEWEWMM  !24!89$$a):4)@%AB FX| & E,,T3s8DDEs   F&&G1GGc                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   t  s     B BD Br   c                	    \        V\        4      '       g   Q hV P                  '       d   \        W0P                  W4      h\        R V4       \        RV^,            RV: 24       R# )zWARNING:zWARNING: Problem on line z: N)r   r   r   rH   rK   print)rS   r9   rL   r   s   &&&&r   r   PoFileParser._invalid_pofilet  sV    $$$$$c<<>>j#)&1*Rx@Ar   )r   r   rK   r   r   r   r   r   r   r   rB   r   r   r   r   r   N)r   r   r   r   )FF)F)rV   rW   rX   rY   rZ   r   rR   r   r   r   r   r   r   r   r  r   r[   r   r   r   r   r      sJ    I$ $@ ?'2R
86 @B Br   r   Fc               4    V ^8  d   QhRRRRRRRRR	RR
RRR/# )r   r   r   localezLocale | str | Nonedomainz
str | Noner   rs   r  r   r   r   r   )r   s   "r   r   r   |  sN     9 9*99 9 	9
 9 9 9r   c                \    \        WVR7      p\        WcVR7      pVP                  V 4       V# )a  Read messages from a ``gettext`` PO (portable object) file from the given
file-like object (or an iterable of lines) and return a `Catalog`.

>>> from datetime import datetime
>>> from io import StringIO
>>> buf = StringIO('''
... #: main.py:1
... #, fuzzy, python-format
... msgid "foo %(name)s"
... msgstr "quux %(name)s"
...
... # A user comment
... #. An auto comment
... #: main.py:3
... msgid "bar"
... msgid_plural "baz"
... msgstr[0] "bar"
... msgstr[1] "baaz"
... ''')
>>> catalog = read_po(buf)
>>> catalog.revision_date = datetime(2007, 4, 1)

>>> for message in catalog:
...     if message.id:
...         print((message.id, message.string))
...         print(' ', (message.locations, sorted(list(message.flags))))
...         print(' ', (message.user_comments, message.auto_comments))
(u'foo %(name)s', u'quux %(name)s')
  ([(u'main.py', 1)], [u'fuzzy', u'python-format'])
  ([], [])
((u'bar', u'baz'), (u'bar', u'baaz'))
  ([(u'main.py', 3)], [])
  ([u'A user comment'], [u'An auto comment'])

.. versionadded:: 1.0
   Added support for explicit charset argument.

:param fileobj: the file-like object (or iterable of lines) 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
:param charset: the character set of the catalog.
:param abort_invalid: abort read if po file is invalid
)r  r  r  )r   )r   r   r  )r   r  r  r   r  r   rK   parsers   &&&&&&  r   read_por  |  s.    l VGDG'-PF
LLNr   zL(\s+|[^\s\w]*\w+[a-zA-Z]-(?=\w+[a-zA-Z])|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r     s     0 03 03 0r   c                    RV P                  RR4      P                  RR4      P                  RR4      P                  RR	4      P                  R
R4      ,          # )zEscape the given string so that it can be included in double-quoted
strings in ``PO`` files.

>>> escape('''Say:
...   "hello, world!"
... ''')
'"Say:\\n  \\"hello, world!\\"\\n"'

:param string: the string to escape
z"%s"\z\\r   z\tr!   z\rr   z\nr   z\")replace)r   s   &r   escaper    sN     FNN40"74/"74/"74/"74/	0 0r   c               (    V ^8  d   QhRRRRRRRR/# )r   r   r   prefixwidthrM   r   r   )r   s   "r   r   r     s.     :K :Kc :K3 :KC :K :Kr   c           
        V'       EdG   V^ 8  Ed?   \        V4      p. pV P                  R4       EF  p\        \        V4      4      V,           V8  d   \        P	                  V4      pVP                  4        V'       d   . p^pV'       d   \        \        VR,          4      4      ^,
          V,           p	W,           V8  d*   VP                  VP                  4       4       W,          pKg  V'       g    VP                  VP                  4       4        VP                  RP                  V4      4       K  EK	  VP                  V4       EK  	  MV P                  R4      p\        V4      ^8:  d   \        V 4      # V'       d(   VR,          '       g   VR VR;;,          R,          uu&   RRP                  V Uu. uF  qQ\        V4      ,           NK  	  up4      ,           # u upi )a]  Convert a string into a format that is appropriate for .po files.

>>> print(normalize('''Say:
...   "hello, world!"
... ''', width=None))
""
"Say:\n"
"  \"hello, world!\"\n"

>>> print(normalize('''Say:
...   "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
... ''', width=32))
""
"Say:\n"
"  \"Lorem ipsum dolor sit "
"amet, consectetur adipisicing"
" elit, \"\n"

:param string: the string to normalize
:param prefix: a string that should be prepended to every line
:param width: the maximum line width; use `None`, 0, or a negative number
              to completely disable line wrapping
Tr0   r   z""
r'   )	r   r1   r  WORD_SEPr?   reverserA   popr4   )
r   r  r  	prefixlenr6   r9   chunksbufsizelengths
   &&&       r   	normalizer!    sj   0 uK	%%d+D6$< 9,u4!- CD !$VF2J%7!81!<y!H=50JJvzz|4 ND#& !$

6::< 8!LL.   T") ,, !!$'
5zQf~ U2YY"Ib	T	DII5I54 5 55IJJJIs   ;G"
c                    V ^8  d   QhRRRR/# )r   filenamer   r   r   )r   s   "r   r   r     s      S S r   c                    RV 9  d
   RV 9  d   V # V P                  R4      '       g
   RV ,           p V P                  R4      '       g
   V R,          p V # )zEnclose filenames which include white spaces or tabs.

Do the same as gettext and enclose filenames which contain white
spaces or tabs with First Strong Isolate (U+2068) and Pop
Directional Isolate (U+2069).
r=   r   r;   r<   )r2   endswith)r#  s   &r   _enclose_filename_if_necessaryr&    sS     (t83x((h&X&&HOr   Tc               D    V ^8  d   QhRRRRRRRRR	RR
RRRRRRRRRRR/# )r   r   zSupportsWrite[bytes]rK   r   r  rM   no_locationrs   omit_headersort_outputsort_by_filer   include_previousinclude_linenor   rN   r   )r   s   "r   r   r     s     J J!JJ J 	J
 J J J J J J 
Jr   c
                    Rp
V'       d   Rp
M
V'       d   Rp
\        VVV	VVVV
VR7       FF  p\        V\        4      '       d   VP                  VP                  R4      pV P                  V4       KH  	  R# )a-  Write a ``gettext`` PO (portable object) template file for a given
message catalog to the provided file-like object.

>>> catalog = Catalog()
>>> catalog.add(u'foo %(name)s', locations=[('main.py', 1)],
...             flags=('fuzzy',))
<Message...>
>>> catalog.add((u'bar', u'baz'), locations=[('main.py', 3)])
<Message...>
>>> from io import BytesIO
>>> buf = BytesIO()
>>> write_po(buf, catalog, omit_header=True)
>>> print(buf.getvalue().decode("utf8"))
#: main.py:1
#, fuzzy, python-format
msgid "foo %(name)s"
msgstr ""
<BLANKLINE>
#: main.py:3
msgid "bar"
msgid_plural "baz"
msgstr[0] ""
msgstr[1] ""
<BLANKLINE>
<BLANKLINE>

:param fileobj: the file-like object to write to
:param catalog: the `Catalog` instance
:param width: the maximum line width for the generated output; use `None`,
              0, or a negative number to completely disable line wrapping
:param no_location: do not emit a location comment for every message
:param omit_header: do not include the ``msgid ""`` entry at the top of the
                    output
:param sort_output: whether to sort the messages in the output by msgid
:param sort_by_file: whether to sort the messages in the output by their
                     locations
:param ignore_obsolete: whether to ignore obsolete messages and not include
                        them in the output; by default they are included as
                        comments
:param include_previous: include the old msgid as a comment when
                         updating the catalog
:param include_lineno: include line number in the location comment
NrJ   rC   )r   r-  r,  r(  r)  sort_byr  backslashreplace)generate_por   r   encoder  write)r   rK   r  r(  r)  r*  r+  r   r,  r-  r/  r9   s   &&&&&&&&&&  r   write_por4    sq    p G	'%)	 dC  ;;w0BCDd	r   r   r-  r,  r(  r)  r/  r  c               <    V ^8  d   QhRRRRRRRRRRRRR	R
RRRR/	# )r   rK   r   r   rs   r-  r,  r(  r)  r/  %Literal['message', 'location'] | Noner  rM   r   zIterable[str]r   )r   s   "r   r   r   l  so     j jj j 	j
 j j j 3j j jr   c          	   #    a aa"   S'       d
   S^ 8  d   SM^Lp\        VRR7      o\        SRRR7      p	RV3R llp
RV V3R llp\        S VR7       EFc  pVP                  '       gn   V'       d   K   S P                  pS'       dI   S^ 8  dB   . pVP	                  4        F  pWP                  V4      ,          pK  	  R	P                  V4      pV R	2x  VP                   F  pV
! V4       R
j  xL
  K  	  VP                   F  pV
! VRR7       R
j  xL
  K  	  V'       g   . p \        VP                  R R7      pV Fc  w  ppVP                  \        P                  R4      p\        V4      pV'       d   V'       d	   V RVR 2pVV9  g   KR  VP!                  V4       Ke  	  V
! RP                  V4      RR7       R
j  xL
  VP"                  '       d.   RRP                  R.\        VP"                  4      O4       R	2x  VP$                  '       d   V'       d   V
! R\'        VP$                  ^ ,          SR7       2RR7       R
j  xL
  \)        VP$                  4      ^8  d4   \'        VP$                  ^,          SR7      pV
! RV 2RR7       R
j  xL
  V! V4       R
j  xL
  R	x  EKf  	  V'       gh   \        S P*                  P-                  4       VR7       F<  pVP                   F  pV
! V4       R
j  xL
  K  	  V! VRR7       R
j  xL
  R	x  K>  	  R
# R
#  EL< EL  \         d    TP                  p ELi ; i EL EL L L LT L@5i)z|Yield text strings representing a ``gettext`` PO (portable object) file.

See `write_po()` for a more detailed description.
F)r  break_long_wordsz# )r  subsequent_indentr8  r0   c              3  r   <"   SP                  V 4       F  pR V RVP                  4        R2x  K  	  R# 5i)r   r=   r   N)wraprj   )r   r  r9   comment_wrappers   && r   _format_comment$generate_po.<locals>._format_comment  s6     #((1DfXQtzz|nB// 2s   47c              3    <"   \        V P                  \        \        34      '       d   V P                  '       d!   V R \        V P                  VSR7       R2x  V R\        V P                  ^ ,          VSR7       R2x  V R\        V P                  ^,          VSR7       R2x  \        SP                  4       F0  p V P                  V,          pV RVR R\        W1SR7       R2x  K2  	  R
# V P                  '       d!   V R \        V P                  VSR7       R2x  V R\        V P                  VSR7       R2x  T R	\        V P                  ;'       g    RVSR7       R2x  R
#   \         d    Rp Li ; i5i)zmsgctxt )r  r  r   msgid msgid_plural r0   zmsgstr[dz] zmsgstr N)
r   idr   r   r   r!  r   r   r   r   )rJ   r  r   r   rK   r  s   &&  r   _format_message$generate_po.<locals>._format_message  st    gjj4-007??6Y^)_(``bccHF9WZZ]6QV#W"XXZ[[HM)GJJqM&X]*^)__abbW001 $^^C0F  Awb6X]1^0__abb 2 7??6Y^)_(``bccHF9WZZe#T"UUWXXHGIgnn.B.B6Y^$_#``bcc "  F s<   8FBFE30FAF"F3F FFF)r/  r   Nr   )r  c                x    V ^ ,          \        V ^,          \        4      ;'       d    V ^,          ;'       g    R3# )r   r'   )r   rM   )xs   &r   <lambda>generate_po.<locals>.<lambda>  s0    !A$
1Q48M8V8VRSTURV8\8\Z\1]r   key/r   rB  r=   r   z, r@  )r  |rA  z#~ ro   )r	   _sort_messagesrC  header_commentr1   r;  r4   r   r   sortedrB   	TypeErrorr  ry   sepr&  rA   r   previous_idr!  r   r   values)rK   r   r-  r,  r(  r)  r/  r  comment_widthheader_wrapperr=  rD  rJ   comment_headerr6   r9   r   locsrB   r#  rL   rC   norm_previous_idr<  s   f$$$$$$d               @r   r1  r1  l  s    " #uqyEbM!NO uW\]N0d d& "'7;;zzz$33N*557D0066E 8!%5!1#$B'',,G&w/// -,,G&ws;;; - D."7#4#4']_	
 %. &#++BFFC89(Cn"*1VAJ7H4'KK) %. 'sxx~cBBB===dii <fW]]&; <=>bAA#3&7#6#6q#9GHI   7&&'!+#,W-@-@-C5#Q *];K:L+MVYZZZ"7+++
g <j %##%
G #00*7333 1&wu===J
 Q 0;  .#--	. C
 [+ 4=s   A*M0MA)M/L+0$ML.M%M(L1 AMM1MMM>MM#,MMAMMM,M-MAMMMMM.M1MMMMMMMMMc               $    V ^8  d   QhRRRRRR/# )r   r   zIterable[Message]r/  r6  r   zlist[Message]r   )r   s   "r   r   r     s$      . 9^ cp r   c                    \        V 4      p VR8X  d   V P                  4        V # VR8X  d   V P                  R R7       V # )z
Sort the given message iterable by the given criteria.

Always returns a list.

:param messages: An iterable of Messages.
:param sort_by: Sort by which criteria? Options are `message` and `location`.
:return: list[Message]
rJ   rC   c                    V P                   # rc   )rB   )r$   s   &r   rH   _sort_messages.<locals>.<lambda>  s    AKKr   rJ  )r   r   )r   r/  s   &&r   rN  rN    sC     H~H) O 
J	/0Or   )NNFNF)r0   L   )r^  FFFFFFT)&rZ   
__future__r   ry   r(   collections.abcr   typingr   r   
babel.corer   babel.messages.catalogr   r   
babel.utilr	   r
   r   r   	_typeshedr   r+   r7   rF   	ExceptionrH   r^   r   r  r)   r  r  r!  r&  r4  r1  rN  r   r   r   <module>rg     s   	 # 	 	 $ )  3 (!'J. >)X) )( )(XEB EBP9x ::  0$:Kz"JZj "j  	j
 #j j j 6:j jZr   