+
    Bi?)                         R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	H
t
 ^ RIHtHt R	t]P                  R8H  t ! R R]P"                  4      t]R8X  d   ]P(                  ! 4        R# R# )
z9
Test the implementation of the PEP 540: the UTF-8 Mode.
N)support)assert_python_okassert_python_failure)	os_helper
MS_WINDOWSvxworksc                   H  a  ] tR t^t o RRRRRR/tR tRR/R	 lt]P                  ! ]	R
4      R 4       t
R tR tR tR tR tRR ltR tR tR tR t]P                  ! ]	R4      R 4       tR t]P                  ! ]	R4      ]P0                  ! 4       R 4       4       tRtV tR# )UTF8ModeTests
PYTHONUTF8 PYTHONLEGACYWINDOWSFSENCODINGPYTHONCOERCECLOCALE0c                ^    \         P                  ! \         P                  R 4      pV\        9   # )N)locale	setlocaleLC_CTYPEPOSIX_LOCALES)selflocs   & */usr/lib/python3.14/test/test_utf8_mode.pyposix_localeUTF8ModeTests.posix_locale   s#    v5}$%    failureFc                   \        V P                  3/ VB pV'       d   \        V/ VB pV^,          pM\        V/ VB pV^,          pVP	                  4       P                  R4      # )   z
)dictDEFAULT_ENVr   r   decoderstrip)r   r   argskwouts   &$*, r   
get_outputUTF8ModeTests.get_output   sa    $"")b)'44Ca&C"D/B/Ca&Czz|""6**r   zWindows has no POSIX localec           	         R p\          FK  pV P                  VR7      ;_uu_ 4        V P                  RWR7      pV P                  VR4       RRR4       KM  	  R#   + '       g   i     Kb  ; i)&import sys; print(sys.flags.utf8_mode)LC_ALL-c1N)r   subTestr$   assertEqual)r   coder   r#   s   &   r   test_posix_localeUTF8ModeTests.test_posix_locale'   sV    7 CS))oodDo=  c* *) !)))s   &AA+c                Z   R pV P                  RRRV4      pV P                  VR4       V P                  RRRV4      pV P                  VR4       V P                  RRRV4      pV P                  VR4       \        '       d+   V P                  RRRVRR7      pV P                  VR4       R	# R	# )
r'   -Xutf8r*   r+   zutf8=1utf8=0r   )r   N)r$   r-   r   r   r.   r#   s   &  r   test_xoptionUTF8ModeTests.test_xoption0   s    7oodFD$7c" oodHdD9c"oodHdD9c": //$d@C " ECS#& r   c           	     @   R pV P                  RVRR7      pV P                  VR4       V P                  RVRR7      pV P                  VR4       V P                  RRRVRR7      pV P                  VR4       \        '       d*   V P                  RRRVRRR7      pV P                  VR4       V P                  4       '       g(   V P                  R	RVRR7      pV P                  VR4       V P                  RVR
RR7      pV P	                  RVP                  4       4       R# )r'   r*   r+   r
   r   r2   r4   r3   r
   r   -ExxxT)r
   r   z-invalid PYTHONUTF8 environment variable valueN)r$   r-   r   r   assertInr    r5   s   &  r   test_env_varUTF8ModeTests.test_env_varD   s   7oodDSo9c"oodDSo9c" oodHdDSoIc": //$ds@C " ECS#&   ""//$ds/CCS#& oodDUDoIEjjl	$r   c           	        \         P                  ! R 4      p\        '       d   RpMRpV P                  RRRV4      pV P	                  W24       \        '       d,   V P                  RRRVRRR7      pV P	                  VR	4       R
# R
# )z
            import sys
            print("{}/{}".format(sys.getfilesystemencoding(),
                                 sys.getfilesystemencodeerrors()))
        zutf-8/surrogatepasszutf-8/surrogateescaper2   r3   r*   strictr+   r:   zmbcs/replaceN)textwrapdedentr   r$   r-   )r   r.   expectedr#   s   &   r   test_filesystemencoding%UTF8ModeTests.test_filesystemencodingd   s        :,H.HoodFD$7': //$d-5@C " EC S.1 r   c                   \         P                  ! R 4      pV P                  RRRVRR7      pV P                  VP	                  4       . R	O4       V P                  RRRVRR7      pV P                  VP	                  4       . R
O4       V P                  RRRVRR7      pV P                  VP	                  4       . RO4       R# )z
            import sys
            print(f"stdin: {sys.stdin.encoding}/{sys.stdin.errors}")
            print(f"stdout: {sys.stdout.encoding}/{sys.stdout.errors}")
            print(f"stderr: {sys.stderr.encoding}/{sys.stderr.errors}")
        r2   r3   r*   r   )PYTHONIOENCODINGlatin1z:namereplaceN)zstdin: utf-8/surrogateescapezstdout: utf-8/surrogateescapestderr: utf-8/backslashreplace)zstdin: iso8859-1/strictzstdout: iso8859-1/strictz"stderr: iso8859-1/backslashreplace)zstdin: utf-8/namereplacezstdout: utf-8/namereplacerJ   )rB   rC   r$   r-   
splitlinesr5   s   &  r   
test_stdioUTF8ModeTests.test_stdio{   s        oodFD$/1  3)<	= oodFD$/7  9)@	A
 oodFD$/=  ?)<	=r   c                    \         P                  ! R 4      p\        pV P                  RWRR7      pV P	                  VP                  4       R4       R# )z
            import sys
            filename = sys.argv[1]
            with open(filename) as fp:
                print(f"{fp.encoding}/{fp.errors}")
        r*   r+   r9   zutf-8/strictN)rB   rC   __file__r$   r-   lower)r   r.   filenamer#   s   &   r   test_ioUTF8ModeTests.test_io   sF        oodDsoCn5r   Nc                   \         p. pV'       d   VP                  R V: 24       V'       d   VP                  RV: 24       \        P                  ! R4      VRP	                  V4      3,          pV P                  RWdRR7      pV'       g   RpV'       g   RpV P                  VP                  4       V R	V 24       R
# )z	encoding=zerrors=z
            import sys
            from %s import open
            filename = sys.argv[1]
            with open(filename, %s) as fp:
                print(f"{fp.encoding}/{fp.errors}")
        z, r*   r+   r9   utf-8rA   /N)rO   appendrB   rC   joinr$   r-   rP   )r   moduleencodingerrorsrQ   r!   r.   r#   s   &&&&    r   _check_io_encoding UTF8ModeTests._check_io_encoding   s     KK)H<01KK'&,-    		$() oodD),  . HF
!F8&<=r   c                z    V P                  VR R7       V P                  VRR7       V P                  VR RR7       R# )rI   rZ   namereplace)r[   )rZ   r[   N)r\   )r   rY   s   &&r   check_io_encodingUTF8ModeTests.check_io_encoding   sC    :}=)1- 	  	Ir   c                (    V P                  R 4       R# )ioNra   r   s   &r   test_io_encodingUTF8ModeTests.test_io_encoding   s    t$r   c                (    V P                  R 4       R# )_pyioNre   rf   s   &r   test_pyio_encoding UTF8ModeTests.test_pyio_encoding   s    w'r   c                ,   R pV P                  RRRV4      pV P                  VR4       \         FM  pV P                  VR7      ;_uu_ 4        V P                  RRRWR7      pV P                  VR4       RRR4       KO  	  R#   + '       g   i     Kd  ; i)z[import locale; print(locale.getpreferredencoding(False), locale.getpreferredencoding(True))r2   r3   r*   zutf-8 utf-8r(   N)r$   r-   r   r,   )r   r.   r#   r   s   &   r    test_locale_getpreferredencoding.UTF8ModeTests.test_locale_getpreferredencoding   s~    loodFD$7m, CS))oodFD$oK  m4 *) !)))s   (BBztest specific to Unixc           	       a aa R P                  R4      oSP                  R4      pSP                  RR4      pRoVVV 3R lpV! RV.4       \         F2  pS P                  VR7      ;_uu_ 4        V! RV.VR7       RRR4       K4  	  \        P
                  R	8X  g#   \        P                  '       g   \        '       d   TpM9\        P
                  P                  R
4      '       d   SP                  R4      pMTp\         F2  pS P                  VR7      ;_uu_ 4        V! RV.VR7       RRR4       K4  	  R#   + '       g   i     K  ; i  + '       g   i     K]  ; i)u   hé€rU   asciisurrogateescapezYimport locale, sys; print("%s:%s" % (locale.getpreferredencoding(), ascii(sys.argv[1:])))c                    < SP                   ! R V RSS3/ VB pVP                  R4      ^,          P                  4       pSP                  V\	        V4      V4       R# )r2   r*   :N)r$   	partitionr    r-   rq   )utf8_optrD   r"   r#   r!   argr.   r   s   &&,  r   check*UTF8ModeTests.test_cmd_line.<locals>.check   sP    //$$cHRHC==%a(//1DT5?C8r   r3   r(   Ndarwinaixz
iso-8859-1r4   )
encoder   r   r,   sysplatformr   
is_androidVXWORKS
startswith)r   arg_utf8	arg_asciirx   r   c_argrw   r.   s   f     @@r   test_cmd_lineUTF8ModeTests.test_cmd_line   s   ""7+::g&JJw(9:	j	9
 	fxj! CS))fxj5 *) ! <<8#w'9'9'9WWE\\$$U++JJ|,EE CS))h4 *) ! *)) *))s   /D9E9E
Ec                    R pV P                  RRRRV4      pV P                  VR4       V P                  RRRRV4      pV P                  VR4       RpV P                  RRR	RV4      pV P                  VR4       R
# )z%import sys; print(sys.flags.optimize)r2   r3   z-Or*   r+   z-OO2z/import sys; print(sys.flags.ignore_environment)r;   N)r$   r-   r5   s   &  r   test_optim_levelUTF8ModeTests.test_optim_level   s    
 7oodFD$=c"oodFE4>c"@oodFD$=c"r   z@os.device_encoding() doesn't implement the UTF-8 Mode on Windowsc                   \         P                  P                  4       '       g   V P                  R 4       RpV P	                  \
        P                  V4       RV: R2p\         P                  RRRV.p\        P                  ! VRR7      pV P                  VP                  ^ V4       \        VRR	7      ;_uu_ 4       pVP                  4       P                  4       pR
R
R
4       V P                  XR4       R
#   + '       g   i     L$; i)zsys.stdout is not a TTYzout.txtz5import os, sys; fd = sys.stdout.fileno(); out = open(z], "w", encoding="utf-8"); print(os.isatty(fd), os.device_encoding(fd), file=out); out.close()r2   r3   r*   T)textr_   Nz
True utf-8)r}   stdoutisattyskipTest
addCleanupr   unlink
executable
subprocessrunr-   
returncodeopenreadr    )r   rQ   r.   cmdprocfpr#   s   &      r   test_device_encoding"UTF8ModeTests.test_device_encoding   s     zz  ""MM34	(((3&\ * ~~tVT48~~c-!T2 (V,,'')""$C -l+ -,s   >C99D		 )NN)__name__
__module____qualname____firstlineno__r   r   r$   unittestskipIfr   r/   r6   r>   rE   rL   rR   r\   ra   rg   rk   rn   r   r   r   requires_subprocessr   __static_attributes____classdictcell__)__classdict__s   @r   r	   r	      s     b'sK&+ + __Z!>?+ @+'($@2.=<
6>2I%(5 __Z!895 :54# __Z12   ", #2,r   r	   __main__)CPOSIX)__doc__r   r   r}   rB   r   testr   test.support.script_helperr   r   test.supportr   r   r   r~   r   TestCaser	   r   mainr   r   r   <module>r      sf      
    N . <<9$D,H%% D,N zMMO r   