
    z
g'                         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e          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)t
          d*d+           | j                            d,t
          d-d.           | j                            d/t
          d0d1           | j                            d2d3d4d5d 6           | j                            d7d8d9d:
           | j                            d;d<d=d>d?@           | j                            dAdBdCd>dD@          | _        | j                            dEdFdGd>dD@          | _        | j                            dHdIJ           | j                            dKdLdMdNdO
           d | _        d S )PN)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--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--ws-protocol*ws_protocolsz+The WebSocket protocols you wish to support)nargsr   r   r   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Daphne)	argparseArgumentParserr   parseradd_argumentintarg_proxy_hostarg_proxy_portserver)selfs    </var/www/html/env/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 	! 	
 	
 	
 	  [ 	! 	
 	
 	
     c                 d     |                                  t          j        dd                    dS )z6
        Main entrypoint for external starts.
        r   N)runsysargv)clss    r3   
entrypointzCommandLineInterface.entrypoint   s,    
 			#(122,r5   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   )r2   r<   r=   s      r3   _check_proxy_headers_passedz0CommandLineInterface._check_proxy_headers_passed   s/     	FJ
 
 
 	
r5   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"   r2   r=   s     r3   _get_forwarded_hostz(CommandLineInterface._get_forwarded_host   sP    
 " 	+,,d6IPT,UUU** 	%$$	% 	%r5   c                 l    |j         r#|                     | j        |           |j         S |j        rdS dS )rB   rC   zX-Forwarded-PortN)r&   r@   r0   r"   rD   s     r3   _get_forwarded_portz(CommandLineInterface._get_forwarded_port   sP    
 " 	+,,d6IPT,UUU** 	&%%	& 	&r5   c                 N   | j                             |          }t          j        t          j        t          j        t          j        t          j        d|j                 d           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t.          |_        t0          |_        n5|j        r|j        t0          |_        n|j        |j        st.          |_        t3          |j        |j        |j        |j        
          }t5          |j        |z             }t6                              dd                    |                     |                     |||j        |j         |j!        |j"        |j#        |j#        |j$        |rtK          |          nd|j&        |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         z*%(asctime)-15s %(levelname)-8s %(message)s)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   r    	verbosityproxy_forwarded_address_headerproxy_forwarded_port_headerproxy_forwarded_proto_headerr(   ).r,   
parse_argsloggingbasicConfigWARNINFODEBUGrZ   
access_logr8   stdoutopenpathinsertr
   r'   r   anyr   rP   r   r   r   DEFAULT_HOSTDEFAULT_PORTr   sortedloggerinfojoinserver_classrR   rS   rT   rU   rV   rX   r   r   r    rE   rG   r"   r(   r1   r7   )r2   r=   access_log_streamr'   rQ   s        r3   r7   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.:;;	tyy/C/C/CEFFF''#*,*"4&*&D(,(F&*&D ,->???*nn+/+C+C+C+N+N(,(@(@d(@(K(K!*)<)<(+ ( 
 
. 	r5   N)__name__
__module____qualname____doc__r   r	   rp   r4   classmethodr;   strr   r@   rE   rG   r7    r5   r3   r   r      s          1KLG G GR     [ 
C 
y 
 
 
 
	%	 	% 	% 	% 	%	&	 	& 	& 	& 	&R R R R Rr5   r   )r*   r_   r8   r   r   asgiref.compatibilityr   accessr   rQ   r   r1   r	   utilsr
   	getLoggerrr   rm   rj   rk   objectr   rx   r5   r3   <module>r~      s      



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