
    /Jf'                         d dl Z d dl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  ej        e          Zd	Zd
Z G d d          ZdS )    N)ArgumentError	Namespace)guarantee_single_callable   )AccessLogGenerator)"build_endpoint_description_strings)Server)import_by_pathz	127.0.0.1i@  c                   d    e Zd ZdZdZeZd Zed             Z	de
defdZdefdZdefd	Zd
 ZdS )CommandLineInterfacezB
    Acts as the main CLI entry point for running the server.
    zDjango HTTP/WebSocket serverc                    t          j        | j                  | _        | j                            ddt
          dd            | j                            dddd	d 
           | j                            dt
          dd           | j                            dt
          dd           | j                            ddddd 
           | j                            dt
          ddd            | j                            dddddg            | j                            dd t
          d!d"           | j                            d#d$t
          d%d            | j                            d&d'd (           | j                            d)d*d+(           | j                            d,t
          d-d.           | j                            d/t
          d0d1           | j                            d2t
          d3d4           | j                            d5d6d7d8
           | j                            d9d:d;d<d=>           | j                            d?d@dAd<dB>          | _        | j                            dCdDdEd<dB>          | _        | j                            dFdGH           | j                            dIdJdKdLdM
           | j                            dNdKdOd8P           d | _        d S )QN)descriptionz-pz--portzPort number to listen on)typehelpdefaultz-bz--bindhostzThe host/address to bind to)destr   r   z--websocket_timeoutzCMaximum time to allow a websocket to be connected. -1 for infinite.iQ z--websocket_connect_timeoutz@Maximum time to allow a connection to handshake. -1 for infinite   z-uz--unix-socketunix_socketz1Bind to a UNIX socket rather than a TCP host/portz--fdfile_descriptorzJBind to a file descriptor rather than a TCP host/port or named unix socket)r   r   r   r   z-ez
--endpointsocket_stringsappendz1Use raw server strings passed directly to twisted)r   actionr   r   z-vz--verbosityzHow verbose to make the outputr   z-tz--http-timeoutz>How long to wait for worker before timing out HTTP connectionsz--access-logzIWhere to write the access log (- for stdout, the default for verbosity=1))r   r   z	--log-fmtzLog format to usez*%(asctime)-15s %(levelname)-8s %(message)sz--ping-intervalzNThe number of seconds a WebSocket must be idle before a keepalive ping is sent   z--ping-timeoutzUThe number of seconds before a WebSocket is closed if no response to a keepalive ping   z--application-close-timeoutzaThe number of seconds an ASGI application has to exit after client disconnect before it is killed
   z--root-path	root_pathz+The setting for the ASGI root_path variable z--proxy-headersproxy_headerszmEnable parsing and using of X-Forwarded-For and X-Forwarded-Port headers and using that as the client addressF
store_true)r   r   r   r   z--proxy-headers-hostproxy_headers_hostzSpecify which header will be used for getting the host part. Can be omitted, requires --proxy-headers to be specified when passed. "X-Real-IP" (when passed by your webserver) is a good candidate for this.storez--proxy-headers-portproxy_headers_portzSpecify which header will be used for getting the port part. Can be omitted, requires --proxy-headers to be specified when passed.applicationz>The application to dispatch to as path.to.module:instance.path)r   z-sz--server-nameserver_namezHspecify which value should be passed to response header Server attributedaphnez--no-server-namestore_const)r   r   const)	argparseArgumentParserr   parseradd_argumentintarg_proxy_hostarg_proxy_portserver)selfs    M/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/daphne/cli.py__init__zCommandLineInterface.__init__   s   -$:JKKK  (+Et 	! 	
 	
 	
 	  . 	! 	
 	
 	
 	  !V	 	! 	
 	
 	
 	  )S	 	! 	
 	
 	
 	  D 	! 	
 	
 	
 	  "] 	! 	
 	
 	
 	  !D 	! 	
 	
 	
 	  1 	! 	
 	
 	
 	  Q 	! 	
 	
 	
 	  \ 	! 	
 	
 	

 	  $@ 	! 	
 	
 	

 	  a	 	! 	
 	
 	
 	  h	 	! 	
 	
 	
 	  )t	 	! 	
 	
 	
 	  >	 	! 	
 	
 	
 	    	! 	
 	
 	
 #k66"%'  7 	
 	
 #k66"%  7 
 
 	  Q 	! 	
 	
 	
 	  [ 	! 	
 	
 	
 	  ]=PR 	! 	
 	
 	
     c                 d     |                                  t          j        dd                    dS )z6
        Main entrypoint for external starts.
        r   N)runsysargv)clss    r2   
entrypointzCommandLineInterface.entrypoint   s,    
 			#(122,r4   argumentargsc                 6    |j         rdS t          |d          )z1Raise if the `--proxy-headers` weren't specified.Nz4--proxy-headers has to be passed for this parameter.)r;   message)r   r   )r1   r;   r<   s      r2   _check_proxy_headers_passedz0CommandLineInterface._check_proxy_headers_passed   s/     	FJ
 
 
 	
r4   c                 l    |j         r#|                     | j        |           |j         S |j        rdS dS )m
        Return the default host header from which the remote hostname/ip
        will be extracted.
        r;   r<   zX-Forwarded-ForN)r!   r?   r.   r   r1   r<   s     r2   _get_forwarded_hostz(CommandLineInterface._get_forwarded_host   sP    
 " 	+,,d6IPT,UUU** 	%$$	% 	%r4   c                 l    |j         r#|                     | j        |           |j         S |j        rdS dS )rA   rB   zX-Forwarded-PortN)r#   r?   r/   r   rC   s     r2   _get_forwarded_portz(CommandLineInterface._get_forwarded_port   sP    
 " 	+,,d6IPT,UUU** 	&%%	& 	&r4   c                 l   | j                             |          }t          j        t          j        t          j        t          j        t          j        d|j                 |j                   d}|j	        r/|j	        dk    rt          j        }n.t          |j	        dd          }n|j        dk    rt          j        }t          j                            dd           t          |j                  }t#          |          }t%          |j        |j        du|j        |j        du|j        g          st0          |_        t2          |_        n5|j        r|j        t2          |_        n|j        |j        st0          |_        t5          |j        |j        |j        |j        	          }t7          |j        |z             }t8                              d
                    d                    |                               |                      |||j!        |j"        |j#        |j$        |j%        |j%        |j&        |rtO          |          nd|j(        |j        | )                    |          | *                    |          |j+        rdnd|j,                  | _-        | j-        .                                 dS )z_
        Pass in raw argument list and it will decode them
        and run the server.
        )r   r         )levelformatN-ar   r   .)r   portr   r   zStarting server at {}z, )r<   zX-Forwarded-Proto)r$   	endpointshttp_timeoutping_intervalping_timeoutwebsocket_timeoutwebsocket_connect_timeoutwebsocket_handshake_timeoutapplication_close_timeoutaction_loggerr   	verbosityproxy_forwarded_address_headerproxy_forwarded_port_headerproxy_forwarded_proto_headerr%   )/r+   
parse_argsloggingbasicConfigWARNINFODEBUGrY   log_fmt
access_logr7   stdoutopenpathinsertr
   r$   r   anyr   rO   r   r   r   DEFAULT_HOSTDEFAULT_PORTr   sortedloggerinforK   joinserver_classrQ   rR   rS   rT   rU   rW   r   r   rD   rF   r   r%   r0   r6   )r1   r<   access_log_streamr$   rP   s        r2   r6   zCommandLineInterface.run   s    {%%d++<<==	 
 n <	
 	
 	
 	
 !? 	+#%%$'J!!$(#q$A$A!!^q   #
 	3$T%566/<< 		% $D0#
 
 	% %DI$DIIY 	%49,$DIIY"49"$DI6( 0	
 
 
	 4.:;;	+22499Y3G3GHHIII''#*,*"4&*&D(,(F&*&D9JT"#4555PTnn+/+C+C+C+N+N(,(@(@d(@(K(K'+'9C##t() ( 
 
, 	r4   N)__name__
__module____qualname____doc__r   r	   rp   r3   classmethodr:   strr   r?   rD   rF   r6    r4   r2   r   r      s          1KLH H HT     [ 
C 
y 
 
 
 
	%	 	% 	% 	% 	%	&	 	& 	& 	& 	&Q Q Q Q Qr4   r   )r)   r^   r7   r   r   asgiref.compatibilityr   accessr   rP   r   r0   r	   utilsr
   	getLoggerrr   rm   rj   rk   r   rx   r4   r2   <module>r}      s      



 - - - - - - - - ; ; ; ; ; ; & & & & & & 9 9 9 9 9 9       ! ! ! ! ! !		8	$	$J J J J J J J J J Jr4   