
    4hh?                        S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJrJr  SSKJrJr  \" 5         \" \5      R%                  5       R&                  S-  rS	 r " S
 S\R,                  5      rS rS r\S:X  aT  \" \R8                  5      S:  a,  \R8                  S   S:X  a  \" 5         \R:                  " S5        \R<                  " 5         gg)z%Tests to cover the Tools/i18n package    N)dedent)Path)assert_python_ok)skip_if_missingtoolsdir)temp_cwdtemp_dir	i18n_datac                 "   [         R                  " S5      nSn[         R                  " XU 5      n [         R                  " S5      nSn[         R                  " X4U 5      n [         R                  " S5      nS n[         R                  " XVU 5      n U $ )zjNormalize the POT creation timestamp, charset and
file locations to make the POT file easier to compare.

z"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    U S   R                  [        R                  S5      $ )Nr   /)replaceossep)matchs    B/opt/python-3.13.8/usr/lib/python3.13/test/test_tools/test_i18n.pyr   #normalize_POT_file.<locals>.replace'   s    Qx,,    )recompilesub)potdate_patternheadercharset_patterncharsetfileloc_patternr   s          r   normalize_POT_filer      sx     ::<=L=F
&&s
+C jj!NOO=G
&&3
/C jj)O-
&&3
/CJr   c                   ~   \ rS rSrSr\" \SS5      rS rS r	S r
SS	S
.S jrS rS r\R                  " \R"                  R%                  S5      S5      S 5       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)S' r*S( r+S) r,S* r-S+ r.S, r/S- r0S. r1S/ r2S0 r3S1r4g2)3Test_pygettext-   zTests for the pygettext.py tooli18nzpygettext.pyc                     0 nUR                  S5       HY  nU(       a  UR                  S5      (       a  M"  UR                  S5      nUR                  SS5      u  pEUR                  5       X$'   M[     U$ )z9utility: return the header of a .po file as a dictionary 
)#msgidmsgstr":   )split
startswithstrip)selfdataheaderslinekeyvals         r   
get_headerTest_pygettext.get_header2   sb    JJt$D4??+CDD::c?Dzz#q)HC99;GL % r   c                    / nSn/ nUR                  S5       H  nU(       a]  UR                  S5      (       a!  UR                  UR                  S5      5        O&UR                  SR	                  U5      5        / nSnMg  UR                  S5      (       d  M  U[        S5      S nUR                  UR                  S5      5        SnM     U(       a   UR                  SR	                  U5      5        U$ )z<utility: return all msgids in .po file as a list of strings Fr$   r(   zmsgid NT)r+   r,   appendr-   joinlen)r.   r/   msgidsreading_msgid	cur_msgidr1   s         r   
get_msgidsTest_pygettext.get_msgids=   s    	JJt$D??3''$$TZZ_5MM$))I"67 "I$)Mx((CMN+  C1 $ % dii	23r   c                 Z    SU l         U R                  [        U5      [        U5      5        g)z Check if two POT files are equalN)maxDiffassertEqualr   )r.   expectedactuals      r   assert_POT_equalTest_pygettext.assert_POT_equalU   s%    +H57I&7QRr    Targsstrictc                   Sn[        S5         [        USSS9 nUR                  U5        SSS5        [        SU R                  /UQUP76 nU(       a  U R                  UR                  S5        [        SSS9 nUR                  5       nSSS5        SSS5        U R                  W5      $ ! , (       d  f       N= f! , (       d  f       N8= f! , (       d  f       NA= f)	z0Return all msgids extracted from module_content.ztest.pyNwutf-8encoding-Xutf8r   messages.pot)	r   openwriter   scriptrA   errreadr=   )r.   module_contentrH   rI   filenamefpresr/   s           r   extract_from_str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,
B:	6C=
C	C
Cc                 $    U R                  USSS9$ )z4Return all docstrings extracted from module_content.z--docstringsFrG   )rZ   )r.   rV   s     r   extract_docstrings_from_str*Test_pygettext.extract_docstrings_from_strg   s    $$^:KTY$ZZr   c                 H   [        S5       n[        SU R                  5        [        SSS9 nUR	                  5       nSSS5        U R                  W5      nU R                  SU5        U R                  SU5        U R                  SU5        U R                  S	U5        U R                  S
U5        U R                  SU5        U R                  SU5        U R                  SU5        U R                  SU5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)zMake sure the required fields are in the header, according to:
http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry
NrO   rP   rL   rM   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   rS   rQ   rU   r4   assertIn)r.   cwdrX   r/   r   s        r   test_header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                    SSK J n  [        S5       n[        SU R                  5        [	        SSS9 nUR                  5       nSSS5        U R                  W5      nUS   nUR                  S	5      (       a  US[        S	5      *  nUR                  US
5        SSS5        g! , (       d  f       Nd= f! , (       d  f       g= f)z:Match the date format from xgettext for POT-Creation-Date r   )datetimeNrO   rP   rL   rM   ra   z\nz%Y-%m-%d %H:%M%z)
rh   r   r   rS   rQ   rU   r4   endswithr9   strptime)r.   rh   rc   rX   r/   r   creationDates          r   test_POT_Creation_Date%Test_pygettext.test_POT_Creation_Date   s     	&d^sXt{{3nw72wwy 8__T*F!"56L $$U+++Lc%j[9 l,>? ^77 ^s#   !B3B"AB3"
B0	,B33
Cc                 X   S H  n[        5          [        U R                  U S35        U R                  [        R
                  R                  S5      5        [        U R                  U S35      nU R                  SUR                  5        S S S 5        M     g ! , (       d  f       M  = f)N)z-oz	--output=test-s#   Project-Id-Version: PACKAGE VERSION)	r   r   rS   
assertTruer   pathexistsrb   out)r.   optrY   s      r   test_output_option!Test_pygettext.test_output_option   st    &C Tl;v 67&t{{se1I>DcggN	  's   A=B
B)	c                     S HL  nU R                  U5         U R                  [        SU-  5      5      nU R                  SU5        S S S 5        MN     g ! , (       d  f       M`  = f)Nz	"""doc"""z
r'''doc'''zR'doc'zu"doc"zE                def foo(bar):
                    %s
                docsubTestr^   r   rb   r.   rz   r:   s      r   test_funcdocstring!Test_pygettext.test_funcdocstring   `    BCc"99& B B ;  eV, #" C""   0A
A#	c                     U R                  [        S5      5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz5        def foo(bar):
            b"""doc"""
        rz   r^   r   assertFalser.   r:   r&   s      r   test_funcdocstring_bytes'Test_pygettext.test_funcdocstring_bytes   F    11& : 3  	VFVEu~%VFGF
   
AAc                     U R                  [        S5      5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz5        def foo(bar):
            f"""doc"""
        rz   r   r   s      r   test_funcdocstring_fstring)Test_pygettext.test_funcdocstring_fstring   r   r   c                     S HL  nU R                  U5         U R                  [        SU-  5      5      nU R                  SU5        S S S 5        MN     g ! , (       d  f       M`  = f)Nry   z@                class C:
                    %s
                rz   r{   r}   s      r   test_classdocstring"Test_pygettext.test_classdocstring   r   r   c                     U R                  [        S5      5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz0        class C:
            b"""doc"""
        rz   r   r   s      r   test_classdocstring_bytes(Test_pygettext.test_classdocstring_bytes   r   r   c                     U R                  [        S5      5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz0        class C:
            f"""doc"""
        rz   r   r   s      r   test_classdocstring_fstring*Test_pygettext.test_classdocstring_fstring   r   r   c                     S HL  nU R                  U5         U R                  [        SU-  5      5      nU R                  SU5        S S S 5        MN     g ! , (       d  f       M`  = f)Nry   z#                %s
                rz   r{   r}   s      r   test_moduledocstring#Test_pygettext.test_moduledocstring   s^    BCc"99& BB ;  eV,	 #" C""r   c                     U R                  [        S5      5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz        b"""doc"""
        rz   r   r   s      r   test_moduledocstring_bytes)Test_pygettext.test_moduledocstring_bytes   F    11& : 3  	VFVEu~%VFGFr   c                     U R                  [        S5      5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz        f"""doc"""
        rz   r   r   s      r   test_moduledocstring_fstring+Test_pygettext.test_moduledocstring_fstring   r   r   c                 J    U R                  S5      nU R                  SU5        g )Nz_("""doc""" r'str' u"ing")	docstring)r^   rb   r.   r:   s     r   
test_msgidTest_pygettext.test_msgid   s#    1102k6*r   c                     U R                  S5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz_(b"""doc""")rz   r^   r   r   s      r   test_msgid_bytesTest_pygettext.test_msgid_bytes   8    11/BVFVEu~%VFGF   
==c                     U R                  S5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz_(f"""doc""")rz   r   r   s      r   test_msgid_fstring!Test_pygettext.test_msgid_fstring   r   r   c                 \    U R                  [        S5      5      nU R                  SU5        g)z2Test docstrings for functions with annotated args z9        def foo(bar: str):
            """doc"""
        rz   Nr^   r   rb   r   s     r   !test_funcdocstring_annotated_args0Test_pygettext.test_funcdocstring_annotated_args   .    11& : 3  	eV$r   c                 \    U R                  [        S5      5      nU R                  SU5        g)z9Test docstrings for functions with annotated return type z;        def foo(bar) -> str:
            """doc"""
        rz   Nr   r   s     r   #test_funcdocstring_annotated_return2Test_pygettext.test_funcdocstring_annotated_return   r   r   c                 \    U R                  [        S5      5      nU R                  SU5        g)z5Test docstring for functions with default arg values z7        def foo(bar=()):
            """doc"""
        rz   Nr   r   s     r    test_funcdocstring_defvalue_args/Test_pygettext.test_funcdocstring_defvalue_args   r   r   c                     U R                  [        S5      5      nU R                  SU5        U R                  SU5        U R                  SU5        g)zyTest docstring extraction for multiple functions combining
annotated args, annotated return types and default arg values
z        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doc3Nr   r   s     r   !test_funcdocstring_multiple_funcs0Test_pygettext.test_funcdocstring_multiple_funcs  sL     11& 	: 	3 	 	ff%ff%ff%r   c                 \    U R                  [        S5      5      nU R                  SU5        g)zTTest docstring extraction for a class with colons occurring within
the parentheses.
z\        class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)):
            """doc"""
        rz   Nr   r   s     r   test_classdocstring_early_colon.Test_pygettext.test_classdocstring_early_colon  s0     11& : 3  	eV$r   c                 \    U R                  [        S5      5      nU R                  SU5        g )Nz"        f"{_('foo bar')}"
        foo barr   r   s     r   test_calls_in_fstrings%Test_pygettext.test_calls_in_fstrings#  .    11& : 3  	i(r   c                 \    U R                  [        S5      5      nU R                  SU5        g )Nz#        rf"{_('foo bar')}"
        r   r   r   s     r   test_calls_in_fstrings_raw)Test_pygettext.test_calls_in_fstrings_raw)  r   r   c                 \    U R                  [        S5      5      nU R                  SU5        g )Nz+        f"""{f'{_("foo bar")}'}"""
        r   r   r   s     r   test_calls_in_fstrings_nested,Test_pygettext.test_calls_in_fstrings_nested/  r   r   c                 \    U R                  [        S5      5      nU R                  SU5        g )Nz&        f"{obj._('foo bar')}"
        r   r   r   s     r    test_calls_in_fstrings_attribute/Test_pygettext.test_calls_in_fstrings_attribute5  r   r   c                 \    U R                  [        S5      5      nU R                  SU5        g )Nz*        f"{type(str)('foo bar')}"
        r   r^   r   assertNotInr   s     r   (test_calls_in_fstrings_with_call_on_call7Test_pygettext.test_calls_in_fstrings_with_call_on_call;  s0    11& : 3  	F+r   c                 \    U R                  [        S5      5      nU R                  SU5        g )Nz6        f"{_('foo {bar}').format(bar='baz')}"
        	foo {bar}r   r   s     r   "test_calls_in_fstrings_with_format1Test_pygettext.test_calls_in_fstrings_with_formatA  s.    11& : 3  	k6*r   c                     U R                  [        S5      5      nU R                  U Vs/ s H  nSU;   d  M  UPM     sn5        g s  snf )Nz%        f"{_(f'foo {bar}')}"
        r   r   r   s      r   )test_calls_in_fstrings_with_wrong_input_18Test_pygettext.test_calls_in_fstrings_with_wrong_input_1G  sG    11& : 3  	VLVE{e7K%VLMLr   c                 \    U R                  [        S5      5      nU R                  SU5        g )Nz        f"{_(1)}"
        r*   r   r   s     r   )test_calls_in_fstrings_with_wrong_input_28Test_pygettext.test_calls_in_fstrings_with_wrong_input_2M  s0    11& : 3  	F#r   c                     U R                  [        S5      5      nU R                  SU5        U R                  SU5        g )Nz%        f"{_('foo', 'bar')}"
        foobarr   r   s     r   (test_calls_in_fstring_with_multiple_args7Test_pygettext.test_calls_in_fstring_with_multiple_argsS  s@    11& : 3  	''r   c                     U R                  [        S5      5      nU R                  SU5        U R                  SU5        U R                  SU5        g )Nz)        f"{_('foo', bar='baz')}"
        r   r   bazr   r   s     r   'test_calls_in_fstring_with_keyword_args6Test_pygettext.test_calls_in_fstring_with_keyword_argsZ  sP    11& : 3  	'''r   c                     U R                  [        S5      5      nU R                  SU5        U R                  SU5        g )Nz*        f"{_(f'foo') + _('bar')}"
        r   r   )r^   r   r   rb   r   s     r   5test_calls_in_fstring_with_partially_wrong_expressionDTest_pygettext.test_calls_in_fstring_with_partially_wrong_expressionb  s>    11& : 3  	'eV$r   c                 ^    U R                  [        S5      5      nU R                  US/5        g)z@Test that function and class names are not mistakenly extracted.z        def _(x):
            pass

        def _(x="foo"):
            pass

        async def _(x):
            pass

        class _(object):
            pass
         N)rZ   r   rA   r   s     r   test_function_and_class_names,Test_pygettext.test_function_and_class_namesi  s2    &&v / (  	"&r   c                     [        5        H>  u  pnU R                  US9   UR                  SS9nU R                  XC5        SSS5        M@     g! , (       d  f       MR  = f)z9Test that the pygettext output exactly matches snapshots.)
input_filerL   rM   N)extract_from_snapshotsr|   	read_textrD   )r.   r   output_fileoutputrB   s        r   test_pygettext_output$Test_pygettext.test_pygettext_outputz  sS    /E/G+JV4&00'0B%%h7 54 0H44s   !A
A	c                    SnSnSn[        S5         [        S5       n[        USS5      nUR                  R	                  5         UR                  SU< S3S	S
9  [        USS5      nUR                  R	                  5         UR                  SU< S3S	S
9  [        USS5      nUR                  R	                  5         UR                  SU< S3S	S
9  [        SU R                  U5        [        S5      R                  S	S
9nU R                  SU S3U5        U R                  SU S3U5        U R                  X85        SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)zCMake sure the directories are inspected for source files
bpo-31920
zText to translate1zText to translate2zText to ignoreNpypkgzpymod.pyz_()rL   rM   zpkg.pyz	pymod2.pyCVSz	pymod3.pyrO   rP   zmsgid "r(   )r   r	   r   parentmkdir
write_textr   rS   r   rb   r   )	r.   text1text2text3sdirpymodpymod2pymod3r/   s	            r   test_files_listTest_pygettext.test_files_list  sD    %$ 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U)# ,^^^^^^s#   E!D!E?E!
E	E!!
E/)r@   N)5__name__
__module____qualname____firstlineno____doc__r   r   rS   r4   r=   rD   rZ   r^   rd   unittestskipIfsysplatformr,   rl   rv   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   r   r   r   r  __static_attributes__rF   r   r   r    r    -   s   )(FN3F	0S
 8:$ %[24 __S\\,,U346@6@"O-HH-HH-HH+
HH%%%&$%)))),+N$((%'"8*r   r    c               #     #    SSSSSS.n U R                  5        H  u  p[        U[        5      (       a  Uu  p[        U-  n[        U-  nO[        U-  nUR	                  S5      nUR                  5       n[        S 5         [        UR                  5      R                  U5        [        S[        R                  /UQUR                  P76   XC[        S5      R                  SS	94v   S S S 5        M     g ! , (       d  f       M  = f7f)
Nr]   )z--escaperF   )zmessages.pyz
fileloc.pyzdocstrings.py
escapes.py)r  zascii-escapes.potz.potrO   rP   rL   rM   )items
isinstancetupleDATA_DIRwith_suffix
read_bytesr   r   namewrite_bytesr   r    rS   r   )	snapshotsrW   rH   r   r   contentss         r   r   r     s     ('* $-/	I $//+h&&$,!H"[0K!H,J!H,J$008K((*d^!--h7X~'<'< .t .'__.'1171CE E	 ^ , ^s   A?DA(C6)D6
D	 Dc                  b    [        5        H!  u  pn[        U5      nUR                  USS9  M#     g )NrL   rM   )r   r   r   )_r   r   s      r   update_POT_snapshotsr    s1    "8":#F+v8 #;r   __main__r*   z--snapshot-update)r  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  r9   argvexitmainrF   r   r   <module>r,     s    + 	 	 
    7 5 5  >!!#**[82l*X&& l*^E:9 z
388}qSXXa[,??MMO r   