
    ;bh[>                        	 d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZmZ  e         ee      j#                         j$                  dz  Zd Z G d	 d
ej*                        Zd Zd Zedk(  rR eej6                        dkD  r+ej6                  d   dk(  r e         ej8                  d         ej:                          yy)    N)dedent)Path)assert_python_ok)skip_if_missingtoolsdir)temp_cwdtemp_dir	i18n_datac                    	 t        j                  d      }d}t        j                  |||       } t        j                  d      }d}t        j                  |||       } t        j                  d      }d }t        j                  |||       } | S )Nz"POT-Creation-Date: .+?\\n"z-"POT-Creation-Date: 2000-01-01 00:00+0000\\n"z*"Content-Type: text/plain; charset=.+?\\n"z,"Content-Type: text/plain; charset=UTF-8\\n"z#:.+c                 H    | d   j                  t        j                  d      S )Nr   /)replaceossep)matchs    C/opt/python-3.12.12/usr/lib/python3.12/test/test_tools/test_i18n.pyr   z#normalize_POT_file.<locals>.replace'   s    Qx,,    )recompilesub)potdate_patternheadercharset_patterncharsetfileloc_patternr   s          r   normalize_POT_filer      s    
 ::<=L=F
&&vs
+C jj!NOO=G
&&'3
/C jj)O-
&&'3
/CJr   c                   l   e Zd Z	  eedd      Zd Zd Zd Zdddd	Z	d
 Z
d Z ej                  ej                  j!                  d      d      d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*d( Z+d) Z,d* Z-d+ Z.d, Z/d- Z0y.)/Test_pygettexti18nzpygettext.pyc                     	 i }|j                  d      D ]O  }|r|j                  d      r|j                  d      }|j                  dd      \  }}|j                         ||<   Q |S )N
)#msgidmsgstr":   )split
startswithstrip)selfdataheaderslinekeyvals         r   
get_headerzTest_pygettext.get_header2   sf    HJJt$D4??+CD::c?Dzz#q)HC99;GCL % r   c                    	 g }d}g }|j                  d      D ]  }|rW|j                  d      r!|j                  |j                  d             n%|j                  dj	                  |             g }d}\|j                  d      sn|t        d      d  }|j                  |j                  d             d} |r |j                  dj	                  |             |S )NFr"   r&   zmsgid T)r)   r*   appendr+   joinlen)r,   r-   msgidsreading_msgid	cur_msgidr/   s         r   
get_msgidszTest_pygettext.get_msgids=   s    K	JJt$D??3'$$TZZ_5MM$))I"67 "I$)Mx(CMN+  C1 $ % dii	23r   c                 \    	 d | _         | j                  t        |      t        |             y )N)maxDiffassertEqualr   )r,   expectedactuals      r   assert_POT_equalzTest_pygettext.assert_POT_equalU   s(    .+H57I&7QRr    Targsstrictc                   	 d}t        d       5  t        |dd      5 }|j                  |       d d d        t        d| j                  g|| }|r| j                  |j                  d       t        dd      5 }|j                         }d d d        d d d        | j                        S # 1 sw Y   xY w# 1 sw Y   .xY w# 1 sw Y   2xY w)Nztest.pywutf-8encoding-Xutf8r   messages.pot)	r   openwriter   scriptr=   errreadr:   )r,   module_contentrC   rD   filenamefpresr-   s           r   extract_from_strzTest_pygettext.extract_from_strZ   s    >d^hg6"( 7"8T[[J4JJC  #.nw72wwy 8  t$$ 76
 87 ^s:   CB.AC<B:C.B7	3C:C	?CCc                 ,    	 | j                  |dd      S )Nz--docstringsFrB   )rU   )r,   rQ   s     r   extract_docstrings_from_strz*Test_pygettext.extract_docstrings_from_strg   s    B$$^:KTY$ZZr   c                 <   	 t        d       5 }t        d| j                         t        dd      5 }|j	                         }d d d        | j                        }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d	|       | j                  d
|       | j                  d|       | j                  d|       | j                  d|       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrJ   rK   rG   rH   zProject-Id-VersionPOT-Creation-DatezPO-Revision-DatezLast-TranslatorzLanguage-TeamzMIME-VersionzContent-TypezContent-Transfer-EncodingzGenerated-By)r   r   rN   rL   rP   r2   assertIn)r,   cwdrS   r-   r   s        r   test_headerzTest_pygettext.test_headerk   s    	 d^sXt{{3nw72wwy 8__T*FMM.7MM-v6MM,f5MM+V4MM/62MM.&1MM.&1MM5v>MM.&1 ^77 ^s#   $DDB;DD	DDaixzbpo-29972: broken test on AIXc                 r   	 ddl m } t        d       5 }t        d| j                         t	        dd      5 }|j                         }d d d        | j                        }|d   }|j                  d      r|d t        d        }|j                  |d	       d d d        y # 1 sw Y   ZxY w# 1 sw Y   y xY w)
Nr   )datetimerJ   rK   rG   rH   rZ   z\nz%Y-%m-%d %H:%M%z)
r`   r   r   rN   rL   rP   r2   endswithr6   strptime)r,   r`   r\   rS   r-   r   creationDates          r   test_POT_Creation_Datez%Test_pygettext.test_POT_Creation_Date   s     	J%d^sXt{{3nw72wwy 8__T*F!"56L $$U++Lc%j[9 l,>? ^77 ^s#   $B-B!AB-!B*	&B--B6c                     dD ]K  }| j                  |      5  | j                  t        d|z              }| j                  d|       d d d        M y # 1 sw Y   XxY w)Nz	"""doc"""z
r'''doc'''zR'doc'zu"doc"zE                def foo(bar):
                    %s
                docsubTestrX   r   r[   r,   rg   r7   s      r   test_funcdocstringz!Test_pygettext.test_funcdocstring   `    BCc"99& B B ;  eV, #" C""   0AA	c                     | j                  t        d            }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz5        def foo(bar):
            b"""doc"""
        rg   rX   r   assertFalser,   r7   r$   s      r   test_funcdocstring_bytesz'Test_pygettext.test_funcdocstring_bytes   F    11& : 3  	VFVEu~%VFGF
   	A A c                     | j                  t        d            }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz5        def foo(bar):
            f"""doc"""
        rg   ro   rq   s      r   test_funcdocstring_fstringz)Test_pygettext.test_funcdocstring_fstring   rs   rt   c                     dD ]K  }| j                  |      5  | j                  t        d|z              }| j                  d|       d d d        M y # 1 sw Y   XxY w)Nrf   z@                class C:
                    %s
                rg   rh   rj   s      r   test_classdocstringz"Test_pygettext.test_classdocstring   rl   rm   c                     | j                  t        d            }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz0        class C:
            b"""doc"""
        rg   ro   rq   s      r   test_classdocstring_bytesz(Test_pygettext.test_classdocstring_bytes   rs   rt   c                     | j                  t        d            }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz0        class C:
            f"""doc"""
        rg   ro   rq   s      r   test_classdocstring_fstringz*Test_pygettext.test_classdocstring_fstring   rs   rt   c                     dD ]K  }| j                  |      5  | j                  t        d|z              }| j                  d|       d d d        M y # 1 sw Y   XxY w)Nrf   z#                %s
                rg   rh   rj   s      r   test_moduledocstringz#Test_pygettext.test_moduledocstring   s^    BCc"99& BB ;  eV,	 #" C""rm   c                     | j                  t        d            }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz        b"""doc"""
        rg   ro   rq   s      r   test_moduledocstring_bytesz)Test_pygettext.test_moduledocstring_bytes   F    11& : 3  	VFVEu~%VFGFrt   c                     | j                  t        d            }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz        f"""doc"""
        rg   ro   rq   s      r   test_moduledocstring_fstringz+Test_pygettext.test_moduledocstring_fstring   r   rt   c                 J    | j                  d      }| j                  d|       y )Nz_("""doc""" r'str' u"ing")	docstring)rX   r[   r,   r7   s     r   
test_msgidzTest_pygettext.test_msgid   s#    1102k6*r   c                 x    | j                  d      }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz_(b"""doc""")rg   rX   rp   rq   s      r   test_msgid_byteszTest_pygettext.test_msgid_bytes   8    11/BVFVEu~%VFGF   	77c                 x    | j                  d      }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz_(f"""doc""")rg   r   rq   s      r   test_msgid_fstringz!Test_pygettext.test_msgid_fstring   r   r   c                 ^    	 | j                  t        d            }| j                  d|       y )Nz9        def foo(bar: str):
            """doc"""
        rg   rX   r   r[   r   s     r   !test_funcdocstring_annotated_argsz0Test_pygettext.test_funcdocstring_annotated_args   s1    A11& : 3  	eV$r   c                 ^    	 | j                  t        d            }| j                  d|       y )Nz;        def foo(bar) -> str:
            """doc"""
        rg   r   r   s     r   #test_funcdocstring_annotated_returnz2Test_pygettext.test_funcdocstring_annotated_return   s1    H11& : 3  	eV$r   c                 ^    	 | j                  t        d            }| j                  d|       y )Nz7        def foo(bar=()):
            """doc"""
        rg   r   r   s     r    test_funcdocstring_defvalue_argsz/Test_pygettext.test_funcdocstring_defvalue_args   s1    D11& : 3  	eV$r   c                     	 | j                  t        d            }| j                  d|       | j                  d|       | j                  d|       y )Nz        def foo1(bar: tuple=()) -> str:
            """doc1"""

        def foo2(bar: List[1:2]) -> (lambda x: x):
            """doc2"""

        def foo3(bar: 'func'=lambda x: x) -> {1: 2}:
            """doc3"""
        doc1doc2doc3r   r   s     r   !test_funcdocstring_multiple_funcsz0Test_pygettext.test_funcdocstring_multiple_funcs   sQ    	 11& 	: 	3 	 	ff%ff%ff%r   c                 ^    	 | j                  t        d            }| j                  d|       y )Nz\        class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)):
            """doc"""
        rg   r   r   s     r   test_classdocstring_early_colonz.Test_pygettext.test_classdocstring_early_colon  s5    	 11& : 3  	eV$r   c                 \    | j                  t        d            }| j                  d|       y )Nz"        f"{_('foo bar')}"
        foo barr   r   s     r   test_calls_in_fstringsz%Test_pygettext.test_calls_in_fstrings  .    11& : 3  	i(r   c                 \    | j                  t        d            }| j                  d|       y )Nz#        rf"{_('foo bar')}"
        r   r   r   s     r   test_calls_in_fstrings_rawz)Test_pygettext.test_calls_in_fstrings_raw!  r   r   c                 \    | j                  t        d            }| j                  d|       y )Nz+        f"""{f'{_("foo bar")}'}"""
        r   r   r   s     r   test_calls_in_fstrings_nestedz,Test_pygettext.test_calls_in_fstrings_nested'  r   r   c                 \    | j                  t        d            }| j                  d|       y )Nz&        f"{obj._('foo bar')}"
        r   r   r   s     r    test_calls_in_fstrings_attributez/Test_pygettext.test_calls_in_fstrings_attribute-  r   r   c                 \    | j                  t        d            }| j                  d|       y )Nz*        f"{type(str)('foo bar')}"
        r   rX   r   assertNotInr   s     r   (test_calls_in_fstrings_with_call_on_callz7Test_pygettext.test_calls_in_fstrings_with_call_on_call3  s0    11& : 3  	F+r   c                 \    | j                  t        d            }| j                  d|       y )Nz6        f"{_('foo {bar}').format(bar='baz')}"
        	foo {bar}r   r   s     r   "test_calls_in_fstrings_with_formatz1Test_pygettext.test_calls_in_fstrings_with_format9  s.    11& : 3  	k6*r   c                     | j                  t        d            }| j                  |D cg c]	  }d|v s| c}       y c c}w )Nz%        f"{_(f'foo {bar}')}"
        r   ro   rq   s      r   )test_calls_in_fstrings_with_wrong_input_1z8Test_pygettext.test_calls_in_fstrings_with_wrong_input_1?  sG    11& : 3  	VLVE{e7K%VLMLrt   c                 \    | j                  t        d            }| j                  d|       y )Nz        f"{_(1)}"
        r(   r   r   s     r   )test_calls_in_fstrings_with_wrong_input_2z8Test_pygettext.test_calls_in_fstrings_with_wrong_input_2E  s0    11& : 3  	F#r   c                     | j                  t        d            }| j                  d|       | j                  d|       y )Nz%        f"{_('foo', 'bar')}"
        foobarr   r   s     r   (test_calls_in_fstring_with_multiple_argsz7Test_pygettext.test_calls_in_fstring_with_multiple_argsK  s@    11& : 3  	''r   c                     | j                  t        d            }| j                  d|       | j                  d|       | j                  d|       y )Nz)        f"{_('foo', bar='baz')}"
        r   r   bazr   r   s     r   'test_calls_in_fstring_with_keyword_argsz6Test_pygettext.test_calls_in_fstring_with_keyword_argsR  sP    11& : 3  	'''r   c                     | j                  t        d            }| j                  d|       | j                  d|       y )Nz*        f"{_(f'foo') + _('bar')}"
        r   r   )rX   r   r   r[   r   s     r   5test_calls_in_fstring_with_partially_wrong_expressionzDTest_pygettext.test_calls_in_fstring_with_partially_wrong_expressionZ  s>    11& : 3  	'eV$r   c                 `    	 | j                  t        d            }| j                  |dg       y )Nz        def _(x):
            pass

        def _(x="foo"):
            pass

        async def _(x):
            pass

        class _(object):
            pass
         )rU   r   r=   r   s     r   test_function_and_class_namesz,Test_pygettext.test_function_and_class_namesa  s5    N&&v / (  	"&r   c                     	 t               D ]E  \  }}}| j                  |      5  |j                  d      }| j                  ||       d d d        G y # 1 sw Y   RxY w)N)
input_filerG   rH   )extract_from_snapshotsri   	read_textr@   )r,   r   output_fileoutputr>   s        r   test_pygettext_outputz$Test_pygettext.test_pygettext_outputr  sZ    G/E/G+JV4&00'0B%%h7 54 0H44s   %AA	c                    	 d}d}d}t        d       5  t        d       5 }t        |dd      }|j                  j	                          |j                  d|dd	       t        |d
d      }|j                  j	                          |j                  d|dd	       t        |dd      }|j                  j	                          |j                  d|dd	       t        d| j                  |       t        d      j                  d	      }| j                  d| d|       | j                  d| d|       | j                  ||       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NzText to translate1zText to translate2zText to ignorepypkgzpymod.pyz_()rG   rH   zpkg.pyz	pymod2.pyCVSz	pymod3.pyrJ   rK   zmsgid "r&   )r   r	   r   parentmkdir
write_textr   rN   r   r[   r   )	r,   text1text2text3sdirpymodpymod2pymod3r-   s	            r   test_files_listzTest_pygettext.test_files_listy  sK   	 %$ d^Xd^tw
3ELL r%!_w?$+6FMM!5)1o@${3FMM!5)1o@Xt{{D9'1171CDMMGE7!,d3MMGE7!,d3UD)# ,^^^^^^s#   E'D+E
E'E$	 E''E0N)1__name__
__module____qualname__r   r   rN   r2   r:   r@   rU   rX   r]   unittestskipIfsysplatformr*   rd   rk   rr   rv   rx   rz   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   rA   r   r   r   r   -   s   )(FN3F	0S
 8:$ %[24 X__S\\,,U346@6@"-HH-HH-HH+
HH%%%&$%)))),+N$((%'"8*r   r   c               #     K   dddddd} | j                         D ]  \  }}t        |t              r|\  }}t        |z  }t        |z  }nt        |z  }|j	                  d      }|j                         }t        d       5  t        |j                        j                  |       t        dt        j                  g||j                    ||t        d      j                  d	      f d d d         y # 1 sw Y   xY ww)
NrW   )z--escaperA   )zmessages.pyz
fileloc.pyzdocstrings.py
escapes.py)r   zascii-escapes.potz.potrJ   rK   rG   rH   )items
isinstancetupleDATA_DIRwith_suffix
read_bytesr   r   namewrite_bytesr   r   rN   r   )	snapshotsrR   rC   r   r   contentss         r   r   r     s     ('* $-/	I $//+$h&$,!Hk"[0K!H,J!H,J$008K((*d^!--h7X~'<'< .t .'__.{'1171CE E	 ^ , ^s   A<D>A,C5*D5C>	:Dc                  f    t               D ]$  \  } }}t        |      }|j                  |d       & y )NrG   rH   )r   r   r   )_r   r   s      r   update_POT_snapshotsr     s3    "8":;#F+v8 #;r   __main__r(   z--snapshot-update)r   r   r   r   textwrapr   pathlibr   test.support.script_helperr   test.test_toolsr   r   test.support.os_helperr   r	   __file__resolver   r   r   TestCaser   r   r   r   r6   argvexitmainrA   r   r   <module>r      s    + 	 	 
    7 5 5  >!!#**[82d*X&& d*NE:9 z
388}qSXXa[,??HMMO r   