
    daf                     :   d Z 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m	Z	m
Z
 ddlmZ e	s ej                  d      ej                  ej                  ddZd	 Z G d
 dej$                        Z G d dej$                        Zedk(  r ej,                          yy)z!Test the interactive interpreter.    N)dedent)cpython_onlyhas_subprocess_supportSuppressCrashReport)kill_pythonztest module requires subprocess)stdoutstderrc           	         t         j                  j                  t         j                  j                  t        j
                        d      }|ddg}|j                  |       |j                  dt        t         j                              }d|d<   t        j                  |ft        j
                  dt        j                  | |d|S )	zRun the Python REPL with the given arguments.

    kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
    object.
    z<stdin>z-Ez-ienvvt100TERMT)
executabletextstdinr   r	   )ospathjoindirnamesysr   extend
setdefaultdictenviron
subprocessPopenPIPE)r   r	   argskwstdin_fnamecmd_liner   s          )/root/Python-3.12.4/Lib/test/test_repl.py
spawn_replr"      s     '',,rwws~~>	JKT4(HOOD --tBJJ/
0CCKH "'*~~!%",//#)&	"
 !" "    c                     t               }|j                  j                  |        t        |      }|j                  dk7  rt        d      |S )zSpawn a new Python interpreter, pass the given
    input source code from the stdin and return the
    result back. If the interpreter exits non-zero, it
    raises a ValueError.r   zProcess didn't exit properly.)r"   r   writer   
returncode
ValueError)sourceprocessoutputs      r!   run_on_interactive_moder+   ,   sF     lGMM!FQ899Mr#   c                   2    e Zd Zed        Zed        Zd Zy)TestInteractiveInterpreterc                    d}t        |      }t               }t               5  |j                  j	                  |       d d d        t        |      }| j                  d|       | j                  |j                  d       y # 1 sw Y   CxY w)Nz
            import sys, _testcapi
            1/0
            print('After the exception.')
            _testcapi.set_nomemory(0)
            sys.exit(0)
        zAfter the exception.)   x   )r   r"   r   r   r%   r   assertInr&   self
user_inputpr*   s       r!   test_no_memoryz)TestInteractiveInterpreter.test_no_memory=   sq    

 J'
L " 	&GGMM*%	&Q,f5allH-	& 	&s   B  B	c                     d}t        |      }t               }|j                  j                  |       t	        |      }| j                  |j                  d       y )Na          x = """<?xml version="1.0" encoding="iso-8859-1"?>
        <test>
            <Users>
                <fun25>
                    <limits>
                        <total>0KiB</total>
                        <kbps>0</kbps>
                        <rps>1.3</rps>
                        <connections>0</connections>
                    </limits>
                    <usages>
                        <total>16738211KiB</total>
                        <kbps>237.15</kbps>
                        <rps>1.3</rps>
                        <connections>0</connections>
                    </usages>
                    <time_to_refresh>never</time_to_refresh>
                    <limit_exceeded_URL>none</limit_exceeded_URL>
                </fun25>
            </Users>
        </test>"""
        r   )r   r"   r   r%   r   assertEqualr&   r2   s       r!   test_multiline_string_parsingz8TestInteractiveInterpreter.test_multiline_string_parsingR   sI    
. J'
L	j!Qq)r#   c                     t        d      }t        d      }t        d|      }|j                  |      d   }| j                  |j                  d       | j                  d|       y )NzY
            import os
            print("before close")
            os.close(0)
        zl
            from test.support import suppress_msvcrt_asserts
            suppress_msvcrt_asserts()
        z-cr   zbefore close)r   r"   communicater8   r&   r1   )r3   r4   prepare_replr)   r*   s        r!   test_close_stdinz+TestInteractiveInterpreter.test_close_stdins   si      

    T<0$$Z03++Q/nf-r#   N)__name__
__module____qualname__r   r6   r9   r=    r#   r!   r-   r-   ;   s.    . .( * *@.r#   r-   c                       e Zd Zd Zy)TestInteractiveModeSyntaxErrorsc                 ~    t        t        d            }|j                         dd }g d}| j                  ||       y )NzJ        def f():
            print(0)
            return yield 42
        )z    return yield 42z           ^^^^^zSyntaxError: invalid syntax)r+   r   
splitlinesr8   )r3   r*   traceback_linesexpected_liness       r!   *test_interactive_syntax_error_correct_linezJTestInteractiveModeSyntaxErrors.test_interactive_syntax_error_correct_line   sH    ( 1 *  !++-b4

 	.9r#   N)r>   r?   r@   rJ   rA   r#   r!   rC   rC      s    :r#   rC   __main__)__doc__r   r   unittestr   textwrapr   test.supportr   r   r   test.support.script_helperr   SkipTestr   STDOUTr"   r+   TestCaser-   rC   r>   mainrA   r#   r!   <module>rU      s    ' 
 	    R R 2 
(

=
>> (__Z5F5F "8E.!2!2 E.P:h&7&7 :$ zHMMO r#   