
    8Cfw"                         d dl Z d dlZd dlZd dlmZ d dlm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 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mZ d dlmZ d dl m!Z!  G d d      Z"y)    N)	Namespace)partial)indent)ListUnion)Sanic)get_logo)Group)SanicArgumentParserSanicHelpFormatter)	SanicREPL)make_inspector_parser)InspectorClient)_defaultis_atty)error_logger)	AppLoaderc                   t    e Zd Z ed ed       dd      ZddZd Zdd	Zd
 Z	de
fdZd ZdefdZd Zy)SanicCLI
Ta  

To start running a Sanic application, provide a path to the module, where
app is a Sanic() instance in the global scope:

    $ sanic path.to.server:app

If the Sanic instance variable is called 'app', you can leave off the last
part, and only provide a path to the module where the instance is:

    $ sanic path.to.server

Or, a path to a callable that returns a Sanic() instance:

    $ sanic path.to.factory:create_app

Or, a path to a directory to run as a simple HTTP server:

    $ sanic ./path/to/static
 )prefixNc                 x   t        j                         j                  t        d| j                  fd      | _        d| j
                  j                  _        d| j
                  j                  _        t        j                  j                  dd      dk7  | _        t               | _        g | _        d	| _        y )
Nsanicc                 0    t        | dkD  rdnddd       S )N`   $         )max_help_positionindent_incrementwidth)r   )progr"   s    M/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/sanic/cli/app.py<lambda>z#SanicCLI.__init__.<locals>.<lambda>5   s!    );(-
"!"	*     )r#   descriptionformatter_classzRequired
========
  PositionalzOptional
========
  GeneralSANIC_RELOADER_PROCESS trueF)shutilget_terminal_sizecolumnsr   DESCRIPTIONparser_positionalstitle
_optionalsosenvirongetmain_processr   argsgroups
inspecting)selfr"   s    @r$   __init__zSanicCLI.__init__0   s    ((*22)((	
 *L  &'F$JJNN3R8FB 	  ){	#%r&   c                    t        t        j                        dkD  rMt        j                  d   dk(  r7d| _        t	        d      | j
                  _        t        | j
                         y t        j                  D ]H  }|j                  | j
                        }|j                          | j                  j                  |       J y )N   inspectT)lensysargvr:   r	   r0   r'   r   r
   	_registrycreateattachr9   append)r;   groupinstances      r$   rE   zSanicCLI.attachE   s    sxx=1!	!9"DO&.tnDKK#!$++.__ 	)E||DKK0HOOKKx(	)r&   c                    | j                   r| j                          y d}|s<t        t        j                        dk(  xr t        j                  d   dk(  }|rdgnd }n	|dgk(  rdg}|ss| j
                  j                  |      \  }}|rR|j                  rF|D ]A  }|j                  d      s| j
                  j                  |j                  d      d	          C | j
                  j                  |      | _        | j                          t        | j                  j                  | j                  j                  | j                  j                   | j                        }	 | j#                  |      }| j%                         }| j                  j&                  r| j)                  |       | j                  j*                  D ]  }	 |j,                  di |d
|	i  | j                  j.                  rt0        j2                  }
nt5        t0        j6                  |      }
 |
|       y # t8        $ r"}t;        j<                  d|        Y d }~y d }~ww xY w)NF   z-vz	--versionr8   --=r   version)
app_loaderzFailed to run app:  )r:   
_inspectorr@   rA   rB   r0   parse_known_argsfactory
startswithadd_argumentsplit
parse_argsr8   	_precheckr   targetsimple_get_app_build_run_kwargsrepl_replhttppreparesingler   serve_singler   serve
ValueErrorr   	exception)r;   rX   legacy_versionparsedunknownargrP   appkwargshttp_versionrd   es               r$   runzSanicCLI.runQ   s   ??OO ]a/HCHHRLD4HN*8+dJD6!%J"kk::
:KOFG6>>" DC~~d+0031BCD KK**
*;	IIdii//1A1A499

	--
+C++-F yy~~

3 $		 <;f;l;<yy**
C#J  	>""%8#<==	>s   "!H& &	I/IIc                 z   t         j                  dd  }| j                  j                  |      \  | _        }|rV|D ]Q  }|j                  d      s	 |j                  d      \  }}|j                  d      }t        | j                  ||       S i | j                  j                  }|j                  d      }|j                  d      }|j                  d      }	|j                  d      }
|j                  d      xs d}|j                  d      }|j                  dd       }|dk(  r|r|d   }t        |      dkD  r|dd  |d<    t        |||	|
|      j                  |fi | y # t        $ rJ |j                  d      rdnd}|j                  dd	      j                  d      j                  dd
      }Y Bw xY w)NrJ   rL   rM   rN   -z--no-FTr*   _hostportsecurerawactioninfoapi_key
positionalz<custom>r   r>   r8   )rA   rB   r0   rS   r8   rU   rW   lstripre   replacesetattr__dict__popr@   r   do)r;   r8   ri   rj   keyvaluerl   rs   rt   ru   rv   rw   ry   rz   s                 r$   rR   zSanicCLI._inspector{   s   xx|![[99t9D	7 3>>$'	%(YYs^
U!jjo DIIsE23 (DII&&'zz&!zz&!H%jjH%/**Y'ZZd3
ZJ]F:"!+ABv<dFC9<<VNvN+ & ),)@dKK4#VC[$WS#. s   %E''AF:9F:rk   c                      t               r|j                   fd       }y  j                  j                  du rt	        j
                  d       y y )Nc                    K   t        | j                  j                        j                          | j	                          d {    y 7 wN)r   r8   r^   ro   _startup)rk   r;   s    r$   
start_replz"SanicCLI._repl.<locals>.start_repl   s1     #tyy~~.224lln$$s   AAAATzPCan't start REPL in non-interactive mode. You can only run with --repl in a TTY.)r   main_process_readyr8   r^   r   error)r;   rk   r   s   `  r$   r_   zSanicCLI._repl   sJ    9##% $% YY^^t#9 $r&   c                 *   | j                   rt        | j                  j                        t        | j                  j                        k7  sn| j                  j
                  r| j                  j                  sB| j                  j                  r| j                  j
                  sm| j                  j                  sV| j                  j                  t        j                         d}t        j                  |       t        j                  d       y y y y y )NzTLS certificates must be specified by either of:
  --cert certdir/fullchain.pem --key certdir/privkey.pem
  --tls certdir  (equivalent to the above)r>   )r7   boolr8   certr   tlstlshostr0   print_usagerA   stderrr   r   exit)r;   messages     r$   rY   zSanicCLI._precheck   s     D$77yy}}		yy  IIMMIINNKK##CJJ/= 
 w'HHQK # " ! r&   rP   c                 Z   	 |j                         }|S # t        $ r}|j                  j                  |j                        r[t        j                  d|j                   d       t        j                  d|j                          t        j                  d       n|Y d }~S d }~ww xY w)NzNo module named za found.
  Example File: project/sanic_server.py -> app
  Example Module: project.sanic_server.appz2
The error below might have caused the above one:
r>   )
loadImportErrormodule_namerU   namer   r   msgrA   r   )r;   rP   rk   rn   s       r$   r\   zSanicCLI._get_app   s    	//#C 
  	%%008""&qvvh /A A
 ""Juug   
	s    	B*BB%%B*c                    | j                   D ]  }|j                  | j                          g }| j                  j                  r|j	                  d        | j                  j
                  | j                  j                  D|j	                  t        | j                  j
                  | j                  j                               | j                  j                  r|| j                  j                  z  }|sd }nt        |      dk(  r
|d   |d   }| j                  j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                   | j                  j"                  || j                  j$                  | j                  j&                  xs d| j                  j(                  | j                  j*                  | j                  j,                  d}dD ]  }t/        | j                  |d      sd||<   ! | j                  j0                  r't3        d d	D              rt4        | j                  _        | j                  j8                  rd|d
<   | j                  j8                  |d<   |S )N)r   r   r>   r   )
access_logcoffeedebugfastrs   motdnoisy_exceptionsrt   sslunix	verbosityworkersauto_tlssingle_process)auto_reloaddevFTc              3   @   K   | ]  }|t         j                  v  y wr   )rA   rB   ).0rj   s     r$   	<genexpr>z-SanicCLI._build_run_kwargs.<locals>.<genexpr>   s      !
$'Csxx!
s   )z--replz	--no-replr   
reload_dir)r9   ra   r8   r   rF   r   r   dictr   r@   r   r   r   r   rs   r   r   rt   r   r   r   r   rb   getattrr   allr   r^   path)r;   rG   r   rl   	maybe_args        r$   r]   zSanicCLI._build_run_kwargs   s   [[ 	%EMM$))$	%,.99JJt99>>%)BJJtTYY]]CD99==499== CCX]s1v1a&C ))..ii&&YY__IINNIINNIINN $		 : :IINNIINN,,1yy((		**"ii..
" 0 	)Ityy)U3$(y!	) 99==S !
+B!
 
 &DIIN99>>$(F=!#'99>>F< r&   )returnNr   )__name__
__module____qualname__r   r	   r/   r<   rE   ro   rR   r   r_   rY   r   r\   r]   rQ   r&   r$   r   r      sc    	$  	* -K2 *
)(TO@ ,9 &.r&   r   )#r4   r,   rA   argparser   	functoolsr   textwrapr   typingr   r   	sanic.appr   sanic.application.logor	   sanic.cli.argumentsr
   sanic.cli.baser   r   sanic.cli.consoler   sanic.cli.inspectorr   sanic.cli.inspector_clientr   sanic.helpersr   r   	sanic.logr   sanic.worker.loaderr   r   rQ   r&   r$   <module>r      sD    	  
      + % B ' 5 6 + " )j jr&   