
    i6                       S SK Jr  S SK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rS SKr " S S\
5      rSS jrSS jr      SS	 jrSS
 jr      SS jr      SS jr      SS jr      SS jr      SS jr      SS jrSS jrSS jr\R6                  R9                  \" 5       (       + SS9SS j5       rSS jrg)    )annotationsN)partial)Protocolc                  "    \ rS rSrSSS jjrSrg)RawInput   c                    g N )selfprompts     BC:\des-py\RoboSAPF\venv\Lib\site-packages\trio/_tests/test_repl.py__call__RawInput.__call__   s        r   N r   strreturnr   )__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s    44r   r   c                :   ^^ [        U 5      m/ mSSUU4S jjjnU$ )z
Pass in a list of strings.
Returns a callable that returns each string, each time its called
When there are not more strings to return, raise EOFError
c                h   > TR                  U 5         [        T5      $ ! [         a    [        S ef = fr
   )appendnextStopIterationEOFError)r   	cmds_iterpromptss    r   _raw_helper$build_raw_input.<locals>._raw_helper   s5    v	%	?" 	%$	%s   
 1r   r   )iter)cmdsr$   r"   r#   s     @@r   build_raw_inputr(      s%     T
IG% % r   c                     [        S/5      n U " 5       S:X  d   e[        R                  " [        5         U " 5         SSS5        g! , (       d  f       g= f)z"Quick test of our helper function.cmd1N)r(   pytestraisesr!   )	raw_inputs    r   test_build_raw_inputr.   '   s;    )I;&   	x	  
!	 	 s   A
Ac                .  #    [         R                  R                  5       n[        / SQ5      nUR	                  USU5        [         R                  R                  U5      I Sh  vN   U R                  5       u  pEUR                  5       / SQ:X  d   eg N/7f)z
Run some basic commands through the interpreter while capturing stdout.
Ensure that the interpreted prints the expected results.
)zx = 1zprint(f'{x=}')'hello'zdef func():z  print(x + 1)r   zfunc()zasync def afunc():z
  return 4r   zawait afunc()
import sysz"sys.stdout.write('hello stdout\n')r-   N)zx=1r0   24zhello stdout13)trio_replTrioInteractiveConsoler(   setattrrun_repl
readouterr
splitlinescapsysmonkeypatchconsoler-   out_errs         r   test_basic_interactionrB   /   s      jj//1G	
I, i8
**

g
&&&!!#IC>>QQQQ '   A!B#B$0Bc                @  #    [         R                  R                  5       n[        S/5      nU R	                  USU5        [
        R                  " [        5         [         R                  R                  U5      I S h  vN   S S S 5        g  N! , (       d  f       g = f7f)Nzraise SystemExitr-   )	r5   r6   r7   r(   r8   r+   r,   
SystemExitr9   )r>   r?   r-   s      r   "test_system_exits_quit_interpreterrF   T   st     jj//1G	
I
 i8	z	"jj!!'*** 
#	"* 
#	"s0   AB#B=B>B	BB
BBc                .  #    [         R                  R                  5       n[        / SQ5      nUR	                  USU5        [         R                  R                  U5      I S h  vN   U R                  5       u  pESU;   d   eSU;  d   eSU;   d   eg  N/7f)N)z"import signal, trio, trio.lowlevelzasync def f():zh  trio.lowlevel.spawn_system_task(    trio.to_thread.run_sync,    signal.raise_signal, signal.SIGINT,  )z  await trio.sleep_forever()z  print('should not see this')r   z	await f()z print('AFTER KeyboardInterrupt')r-   KeyboardInterruptshouldzAFTER KeyboardInterruptr5   r6   r7   r(   r8   r9   r:   r=   r>   r?   r-   r@   errs         r   test_KI_interruptsrM   `   s      jj//1G	
I i8
**

g
&&&  "HC#%%%3$+++	 'rC   c                  #    [         R                  R                  5       n[        / SQ5      nUR	                  USU5        [         R                  R                  U5      I S h  vN   U R                  5       u  pESU;   d   eg  N7f)N)r1   if sys.version_info < (3, 11):/  from exceptiongroup import BaseExceptionGroupr   z<raise BaseExceptionGroup('', [RuntimeError(), SystemExit()])!print('AFTER BaseExceptionGroup')r-   AFTER BaseExceptionGrouprJ   r<   s         r   test_system_exits_in_exc_grouprS   |   sy      jj//1G	
	I i8
**

g
&&&!!#IC &,,,	 '   A!B#B$ Bc                  #    [         R                  R                  5       n[        / SQ5      nUR	                  USU5        [         R                  R                  U5      I S h  vN   U R                  5       u  pESU;   d   eg  N7f)N)r1   rO   rP   r   zraise BaseExceptionGroup(z?  '', [BaseExceptionGroup('', [RuntimeError(), SystemExit()])])rQ   r-   rR   rJ   r<   s         r   %test_system_exits_in_nested_exc_grouprV      sy      jj//1G	

I i8
**

g
&&&!!#IC &,,,	 'rT   c                .  #    [         R                  R                  5       n[        SS/5      nUR	                  USU5        [         R                  R                  U5      I S h  vN   U R                  5       u  pESU;  d   eSU;  d   eSU;   d   eg  N/7f)Nzraise BaseExceptionprint('AFTER BaseException')r-   _threads.py_repl.pyAFTER BaseExceptionrJ   rK   s         r   test_base_exception_capturedr\      s      jj//1G "*	
I i8
**

g
&&&  "HC###S    C'''	 'rC   c                  #    [         R                  R                  5       n[        SS/5      nUR	                  USU5        [         R                  R                  U5      I S h  vN   U R                  5       u  pESU;   d   eg  N7f)Nz&raise ExceptionGroup('', [KeyError()])zprint('AFTER ExceptionGroup')r-   zAFTER ExceptionGrouprJ   r<   s         r   test_exc_group_capturedr^      s      jj//1G 5+	
I i8
**

g
&&&!!#IC!S((( 'rT   c                .  #    [         R                  R                  5       n[        / SQ5      nUR	                  USU5        [         R                  R                  U5      I S h  vN   U R                  5       u  pESU;  d   eSU;  d   eSU;   d   eg  N/7f)N)z-async def async_func_raises_base_exception():z  raise BaseExceptionr   z(await async_func_raises_base_exception()rX   r-   rY   rZ   r[   rJ   rK   s         r   *test_base_exception_capture_from_coroutiner`      s      jj//1G	

I i8
**

g
&&&  "HC###S    C'''	 'rC   c                 t    [         R                  " [        R                  SS/SS9n U R                  S:X  d   eg)zD
Basic smoke test when running via the package __main__ entrypoint.
-mr5   s   exit())inputr   N)
subprocessrunsys
executable
returncode)repls    r   test_main_entrypointrj      s1     >>3>>48	JD??ar   c                     [         R                  S:w  a  g[        R                  " S5      n U R	                  5       (       d  gU R                  5       S:H  $ )NlinuxFz /proc/sys/dev/tty/legacy_tiocstiT1)rf   platformpathlibPathexists	read_text)sysctls    r   should_try_newline_injectionrt      sD    
||w\\<=F==?? !S((r   z"the ioctl we use is disabled in CI)reasonc                    [         R                  S:w  d   eSS Kn U R                  5       u  pUS:X  a7  [        R
                  " [         R                  /[         R                  SSS/Q76   SnUR                  S5      (       d2  U[        R                  " US5      -  nUR                  S5      (       d  M2  [        UR                  5       5        Sn[        R                  " US	5        UR                  S
5      (       d2  U[        R                  " US5      -  nUR                  S
5      (       d  M2  UR                  S5      S:X  d   e[        UR                  5       5        Sn[        R                  " U[        R                  5        UR                  S
5      (       d2  U[        R                  " US5      -  nUR                  S
5      (       d  M2  SU;   d   e[        UR                  5       5        Sn[        R                  " US5        [        R                  " U[        R                  5        UR                  S
5      (       d2  U[        R                  " US5      -  nUR                  S
5      (       d  M2  SU;   d   e[        UR                  5       5        [        R                   " U5        [        R"                  " US5      S     g )Nwin32r   -urb   r5   r   s   import trio
>>> i      print("hello!")
   >>>    hello!      KeyboardInterrupts   print("hello!")   )rf   rn   ptyforkosexeclprg   endswithreadprintdecodewritecountkillsignalSIGINTclosewaitpid)r   pidpty_fdbuffers       r   test_ki_newline_injectionr      s    <<7""" ((*KC
ax
		#..HCNND$#GH Foo455"''&$'' oo455 
&--/FHHV)*oog&&"''&$'' oog&& <<	"a''' 
&--/FGGCoog&&"''&$'' oog&&  6))) 
&--/FHHV'(GGCoog&&"''&$'' oog&&  6)))	&--/HHVJJsAqr   c                   #    [         R                  " 5        IS h  vN n U R                  [        [         R                  [
        R                  SSS/[        R                  [        R                  [        R                  [
        R                  S:X  a  [        R                  OSS95      I S h  vN nUR                   IS h  vN   SnUR                    S h  vN nX#-  nUR                  SS	5      R                  S
5      (       d  M5    [        UR!                  5       5        SnUR"                  R%                  S5      I S h  vN   UR                    S h  vN nX#-  nUR                  S5      (       d  M%    SU;   d   e[        UR!                  5       5        [
        R                  S:X  ap  SnUR"                  R%                  S5      I S h  vN   UR                    S h  vN nX#-  nUR                  S5      (       d  M%    [        UR!                  5       5        SnUR"                  R%                  S5      I S h  vN   UR                    S h  vN nX#-  nUR                  S5      (       d  M%    [        UR!                  5       5        [
        R                  S:X  a  [&        R(                  O[&        R*                  n[,        R.                  " UR0                  U5        [
        R                  S:X  a$  UR"                  R%                  S	5      I S h  vN   O#UR"                  R%                  S	5      I S h  vN   SnUR                    S h  vN nX#-  nUR                  S5      (       d  M%    SU;   d   e[        UR!                  5       5        UR"                  R%                  S5      I S h  vN   SnSnUR                    S h  vN nX#-  nUR                  SS	5      R                  S5      (       a*  U(       d#  [,        R.                  " UR0                  U5        SnUR                  S5      (       d  Mu    SU;   d   eSU;   d   e[        UR!                  5       5        UR"                  R%                  S5      I S h  vN   SnSnUR                    S h  vN nX#-  nUR                  SS	5      R                  S5      (       a*  U(       d#  [,        R.                  " UR0                  U5        SnUR                  S5      (       d  Mu    SU;   d   eSU;   d   e[        UR!                  5       5        S S S 5      IS h  vN   U R2                  R5                  5         S S S 5      IS h  vN   g  GNZ GN GN GN
 GNx GN? GN-
 GN GN GN
 GN GNU GNC
 GN' GN GNf GNR
 GN6 GN GN
 GNu GN. GN
 N Nv! , IS h  vN  (       d  f       N= f Nh! , IS h  vN  (       d  f       g = f7f)Nrx   rb   r5   rw   r   )stdoutstderrstdincreationflagsr   s   
   
s   import trio
>>> ry   rz   r{   sI   import ctypes; ctypes.windll.kernel32.SetConsoleCtrlHandler(None, False)
sW   import coverage; trio.lowlevel.enable_ki_protection(coverage.pytracer.PyTracer._trace)
r}   s+   print("READY"); await trio.sleep_forever()
Fs   READY
Ts   trios/   import time; print("READY"); time.sleep(99999)
s	   Traceback)r5   open_nurserystartr   run_processrf   rg   rd   PIPESTDOUTrn   CREATE_NEW_PROCESS_GROUPr   replacer   r   r   r   send_allr   CTRL_C_EVENTr   r   r   r   cancel_scopecancel)nurseryprocr   partsignal_sentkilleds         r   test_ki_in_replr   5  s      ""g]]  tV4!!(( ooEH\\U\E\jAAbc	
 	
 ;;;F"kk d>>'51::;OPP &--/"F**%%&:;;;"kk d??7++&&&&--/" ||w&jj))a   #'++ $NFw//fmmo& F**%%k   #kk d??7++&--/"
 251H&--fmmKGGDHHk*||w& jj))%000 jj))%000F"kk d??7++'6111 &--/"**%%&UVVVFF"kk d>>'51:::FFvGGDHHk2!F??7++f$$$'6111 &--/"**%%C   FF"kk d>>'51:::FFvGGDHHk2!F??7++6)))'6111&--/"O ;T 	##%m #""	
 k <k+k 1 1k Wk
ky ;;; #"""sI  W5U6W5BW/U90WU<WV?VU?
V)V?:V?VV?VV
VV?<AV?VV?#V'V
(V+V?:V?VV?VV
VV?8B!V?V #V?=V#>V?V)V&
V)V?5A V?5V,6V?
V2V/
V2A)V??AV?V5V?V; V8
!V;$A)V?*V?;WV=W%W50W1W59W<W?VV?V?VV?V?VV?V?VV? V?#V?&V))V?,V?/V22V?5V?8V;;V?=W?W	WW	WW5W2!W$"W2.W5)r'   z	list[str]r   r   )r   None)r=   zpytest.CaptureFixture[str]r>   pytest.MonkeyPatchr   r   )r>   r   r   r   )r   bool)
__future__r   r   ro   r   rd   rf   	functoolsr   typingr   r+   
trio._replr5   r   r(   r.   rB   rF   rM   rS   rV   r\   r^   r`   rj   rt   markskipifr   r   r   r   r   <module>r      sa   " 	    
    5x 5&"R&"R#"R 
"RJ	+,&,#, 
,8-&-#- 
-.-&-#- 
-0(&(#( 
(()&)#) 
)$(&(#( 
(0 	) $&&/  1	1hw&r   