
    8Cf                        U d dl 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
 d dlmZ d dlmZ d dlmZmZmZmZmZmZmZ d dlZd dlmZmZ d dlmZ d d	lmZ d d
lmZ d dl m!Z! d dl"m#Z# d dl$m%Z% 	 d dl&m'Z' dZ( G d de'      Z)	 d dl+Z+da.ee   e/d<   da0ee%   e/d<    G d de#      Z1 G d de      Z2	 	 	 	 d%de3deeee3ef   eee3e3f      f      de3dee3   fdZ4d e%fd!Z5	 	 	 	 d%de3deeee3ef   eee3e3f      f      de3dee3   d e2f
d"Z6 G d# d$e      Z7y# e*$ r dZ(Y w xY w# e*$ r  e,dejZ                         Y w xY w)&    N)PyCF_ALLOW_TOP_LEVEL_AWAIT)iscoroutinenew_event_loop)InteractiveConsole)FunctionType)AnyDict
NamedTupleOptionalSequenceTupleUnion)RequestSanic)Header)Default)Stage)Colors)TransportProtocol)HTTPResponse)ClientTc                   $     e Zd Zdef fdZ xZS )SanicClientappc                     |j                  |j                  j                  d   j                        }t        |   |       y )Nr   )base_url)get_server_locationstateserver_infosettingssuper__init__)selfr   r   	__class__s      Q/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/sanic/cli/console.pyr"   zSanicClient.__init__   s=    ..		%%a(11H Gh/    )__name__
__module____qualname__r   r"   __classcell__r$   s   @r%   r   r      s    	0 	0 	0r&   r   FzDModule 'readline' not available. History navigation will be limited.)filerepl_apprepl_responsec                       e Zd Zd Zd Zd Zy)REPLProtocolc                 <    t         j                  | _        d| _        y )NT)r   IDLEstagerequest_bodyr#   s    r%   r"   zREPLProtocol.__init__4   s    ZZ
 r&   c                     |a | |_        |S N)r.   stream)r#   responses     r%   respondzREPLProtocol.respond8   s     r&   c                    K   y wr7    )r#   data
end_streams      r%   sendzREPLProtocol.send>   s	     s   N)r'   r(   r)   r"   r:   r?   r<   r&   r%   r0   r0   3   s    !r&   r0   c                   "    e Zd ZU eed<   eed<   y)Resultrequestr9   N)r'   r(   r)   r   __annotations__r   r<   r&   r%   rA   rA   B   s    r&   rA   urlheadersmethodbodyc                     t         sJ d       |xs i }t               }t        | j                         t	        |      d||t               }||j                         |_        ||_        d |_        |S )N!No Sanic app has been registered.z1.1)r-   r0   r   encoder   rG   r8   	conn_info)rD   rE   rF   rG   protocolrB   s         r%   make_requestrM   G   sq     8888mG~H

wG {{}GNGNr&   returnc                 ~   K   t         sJ d       t         j                  |        d {    t        sJ t        S 7 w)NrI   )r-   handle_requestr.   )rB   s    r%   r:   r:   _   s;     8888

!
!'
***= +s   &=;=c                 h   K   t        | |||      }t        |       d {   }t        ||      S 7 wr7   )rM   r:   rA   )rD   rE   rF   rG   rB   r9   s         r%   dorR   f   s7      36GW%%H'8$$ &s   202c                   l     e Zd Zddedee   f fdZd Zd Zd fd	Z	d Z
d Zd	 Zd
 Zd Zd Z xZS )	SanicREPLr   startc                    |a |t        t        d}d}dt        j                  t        j
                  z    dt        j                   dt        j                  t        j                  z    t        |       t        j                   dt        j                  t        j
                  z    dt        j                   dt        j                  t        j                  z    dt        j                   dt        j                  t        j
                  z    d	t        j                   d
t        j                  t        j                  z    dt        j                   g}t        rt        |      |d<   |j                  dt        j                  t        j
                  z    dt        j                   dt        j                  t        j                  z    dt        j                          n(|d= dt        j                   dt        j                   d}t        | 9  |       | j                  j                   xj"                  t$        z  c_        t'               | _        || _        t-        j.                         | _        t-        j.                         | _        t-        j4                  | j6                  d      | _        t-        j4                  | j:                  d      | _        t-        j4                  | j(                  j>                  d      | _         || _!        | jE                          d| _#        djI                  dt        j                   dt        j                   |dg|ddt        j                   dt        j                   dt        j                   dt        j                   dt        j                   dt        j                   d      | _%        y ) N)r   sanicrR    z  - r   z#: The Sanic application instance - rW   z: The Sanic module - zimport sanicrR   z;: An async function to fake a request to the application - zResult(request, response)clientz:: A client to access the Sanic app instance using httpx - zfrom httpx import Client   
zRThe HTTP client has been disabled. To enable it, install httpx:
	pip install httpx)localsT)targetdaemonzClosing the REPL.z(Welcome to the Sanic interactive consolez9The following objects are available for your convenience:z5
The async/await keywords are available for use here.zTo exit, press zCTRL+Cz, zCTRL+Dz
, or type exit()z.
)&r-   rW   rR   r   BOLDSANICENDBLUEstrHTTPX_AVAILABLEr   appendYELLOWr!   r"   compilecompilerflagsr   r   loop_start	threadingEvent_pause_event_started_eventThread_console_interact_thread_monitor_monitor_threadrun_forever_async_threadr   resumeexit_messagejoinbanner_message)r#   r   rU   locals_availableclient_availabilityvariable_descriptionsr$   s         r%   r"   zSanicREPL.__init__r   s   

 !6;;-.c&**=`agalalouozozaz`{|  AD  }E  |F  GM  GQ  GQ  FR  S6;;-.eFJJ<?TU[U`U`cicncnUnToo{  }C  }G  }G  |H  I6;;-.b<wx~  yD  yD  GM  GR  GR  yR  xS  Sl  ms  mw  mw  lx  y!

 )4S)9X&!((v{{V\\12&D~  @F  @K  @K  NT  NY  NY  @Y  Z  Zr  sy  s}  s}  r~   &a(V]]O $$$*JJ<r3  
 	 01##'AA#"$	%OO-'oo/ ) 0 0==!
  )//== 
 '--99((
 /"iiV[[M!I&**V#K '	
 I "&++fVZZL;;-vfjj\FKK=vzzlZ]_

r&   c                 Z    | j                         ry | j                  j                          y r7   )	is_pausedro   clearr5   s    r%   pausezSanicREPL.pause   s!    >>!r&   c                 8    | j                   j                          y r7   )ro   setr5   s    r%   rx   zSanicREPL.resume   s    r&   c                     |j                         dk(  r| j                          y| j                         rt        d       yt        |   |||      S )Nr_   Fz4Console is paused. Please wait for it to be resumed.)strip	_shutdownr   printr!   	runsource)r#   sourcefilenamesymbolr$   s       r%   r   zSanicREPL.runsource   sH    <<>X%NN>>HIw 6::r&   c                      t         j                  j                          fd} j                  j	                   j                  j
                   |              j                         S )Nc                     K   t        j                        } 	  |        }t        |      r
| d {   }j                  |       y 7 # t        $ r t	        j
                          d}Y 5w xY ww)NF)r   r\   r   BaseException	traceback	print_exc
set_result)funcresultcodefuturer#   s     r%   callbackz#SanicREPL.runcode.<locals>.callback   sf     dkk2Dv&#)\F f%	 *  ##%s7   A0A A	A A0	A A-*A0,A--A0)
concurrentfuturesFuturerk   call_soon_threadsafecreate_taskr   )r#   r   r   r   s   `` @r%   runcodezSanicREPL.runcode   sJ    ##**,		& 			&&tyy'<'<hjI}}r&   c                 8    | j                   j                          S r7   )ro   is_setr5   s    r%   r   zSanicREPL.is_paused   s    $$++---r&   c                     | j                   j                          | j                  | j                  | j                         | j                          y )N)bannerexitmsg)rp   r   interactr{   ry   r   r5   s    r%   rr   zSanicREPL._console   s:    !T00$:K:KLr&   c                    t        | j                  t              rFt        j                  t        j
                  z    dt        j                   }t        d| d      }|ry 	 	 | j                  j                         s?| j                  j                  j                          | j                  j                          n| j                  j                  j                         r=| j!                         r-| j#                          t%        t&        j(                  dd       nD| j                  j                  j                         s | j!                         s| j+                          t-        j.                  d       # t0        t2        f$ r Y y w xY w)NENTERz
Press z  at anytime to start the REPL.

TrX   )endflushg?)
isinstancerl   r   r   r`   ra   rb   inputrp   r   r   managerwait_for_ackrs   rU   _all_workers_ackr   rx   r   sysps1r   timesleepConnectionResetErrorBrokenPipeError)r#   enterrU   s      r%   rt   zSanicREPL._monitor   s   dkk7+{{V\\12%

|DEHUG+MNOE	**113HH$$113))//1XX%%668T^^=MKKM#''r6((99; NN,JJL

3  %o6 		s   "DE8 8F
	F
c                 b    | j                   j                  j                  j                  d       y )N__TERMINATE__)r   r   monitor_publisherr?   r5   s    r%   r   zSanicREPL._shutdown   s     **//@r&   c                 l    | j                   j                          | j                  j                          y r7   )ru   rU   rw   r5   s    r%   runzSanicREPL.run   s&    ""$  "r&   r7   )z<input>single)r'   r(   r)   r   r   r   r"   r   rx   r   r   r   rr   rt   r   r   r*   r+   s   @r%   rT   rT   q   sJ    9
E 9
(7*; 9
v"
 	;".
.A#r&   rT   )/NGETN)8concurrent.futuresr   r   rm   r   r   astr   asyncior   r   r   r   typesr   typingr   r	   r
   r   r   r   r   rW   r   r   sanic.compatr   sanic.helpersr   sanic.http.constantsr   	sanic.logr   sanic.models.protocol_typesr   sanic.response.typesr   httpxr   re   r   ImportErrorreadliner   stderrr-   rC   r.   r0   rA   rd   rM   r:   rR   rT   r<   r&   r%   <module>r      s    
    * / #  J J J     ! &  9 -O0f 0 !(5/  (,x% ,$ Z  JN		eDcNHU38_,EEFG  3-	0l  JN	%	%eDcNHU38_,EEFG% % 3-	%
 %D#" D#[  O
  	NZZs$   3D D( D%$D%(EE