
    <e                        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                     dS dS )z!Test the interactive interpreter.    N)dedent)cpython_onlyhas_subprocess_supportSuppressCrashReport)kill_pythonztest module requires subprocess)stdoutstderrc           	         t           j                            t           j                            t          j                  d          }|ddg}|                    |           |                    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          %/usr/lib/python3.11/test/test_repl.py
spawn_replr"      s     ',,rws~>>	JJKT4(HOOD --tBJ//
0
0CCKH "'*~!%",/#)&	" "
 !" " "    c                     t                      }|j                            |            t          |          }|j        dk    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+   ,   sR     llGM!!FQ8999Mr#   c                   @    e Zd Zed             Zed             Zd ZdS )TestInteractiveInterpreterc                 D   d}t          |          }t                      }t                      5  |j                            |           d d d            n# 1 swxY w Y   t          |          }|                     d|           |                     |j        d           d S )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=   s    

 J''
LL "" 	& 	&GMM*%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&Q,f555alH-----s   AAAc                     d}t          |          }t                      }|j                            |           t	          |          }|                     |j        d           d S )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   s^    
. J''
LL	j!!!Qq)))))r#   c                     t          d          }t          d          }t          d|          }|                    |          d         }|                     |j        d           |                     d|           d S )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   s       

     T<00$$Z003+Q///nf-----r#   N)__name__
__module____qualname__r   r6   r9   r=    r#   r!   r-   r-   ;   sX        . . \.( * * \*@. . . . .r#   r-   c                       e Zd Zd ZdS )TestInteractiveModeSyntaxErrorsc                     t          t          d                    }|                                dd         }g d}|                     ||           d S )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   sm    ( 1 * *   !++--be4
 
 

 	.9999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      sO   ' ' 



 				            R R R R R R R R R R 2 2 2 2 2 2  ?
(
=
>
>> (_Z5F " " " " "8  E. E. E. E. E.!2 E. E. E.P: : : : :h&7 : : :$ zHMOOOOO r#   