
    Mf'                         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y)    N)ArgumentError	Namespace)guarantee_single_callable   )AccessLogGenerator)"build_endpoint_description_strings)Server)import_by_pathz	127.0.0.1i@  c                   \    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y)CommandLineInterfacezB
    Acts as the main CLI entry point for running the server.
    zDjango HTTP/WebSocket serverc                    t        j                  | j                        | _        | j                  j	                  ddt
        dd        | j                  j	                  dddd	d 
       | j                  j	                  dt
        dd       | j                  j	                  dt
        dd       | j                  j	                  ddddd 
       | j                  j	                  dt
        ddd        | j                  j	                  dddddg        | j                  j	                  dd t
        d!d"       | j                  j	                  d#d$t
        d%d        | j                  j	                  d&d'd (       | j                  j	                  d)d*d+(       | j                  j	                  d,t
        d-d.       | j                  j	                  d/t
        d0d1       | j                  j	                  d2t
        d3d4       | j                  j	                  d5d6d7d8
       | j                  j	                  d9d:d;d<d=>       | j                  j	                  d?d@dAd<dB>      | _        | j                  j	                  dCdDdEd<dB>      | _        | j                  j	                  dFdGH       | j                  j	                  dIdJdKdLdM
       | j                  j	                  dNdKdOd8P       d | _        y )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    E/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/daphne/cli.py__init__zCommandLineInterface.__init__   sQ   --$:J:JK  (+Et 	! 	
 	  . 	! 	
 	  !V	 	! 	
 	  )S	 	! 	
 	  D 	! 	
 	  "] 	! 	
 	  !D 	! 	
 	  1 	! 	
 	  Q 	! 	
 	  \ 	! 	

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

 	  a	 	! 	
 	  h	 	! 	
 	  )t	 	! 	
 	  >	 	! 	
 	    	! 	
 #kk66"%'  7 	
 #kk66"%  7 
 	  Q 	! 	
 	  [ 	! 	
 	  ]=PR 	! 	
     c                 R     |        j                  t        j                  dd        y)z6
        Main entrypoint for external starts.
        r   N)runsysargv)clss    r2   
entrypointzCommandLineInterface.entrypoint   s    
 			#((12,r4   argumentargsc                 6    |j                   ry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!    J
 	
r4   c                     |j                   r)| j                  | j                  |       |j                   S |j                  ryy)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   sD    
 "",,d6I6IPT,U***$ r4   c                     |j                   r)| j                  | j                  |       |j                   S |j                  ryy)rA   rB   zX-Forwarded-PortN)r#   r?   r/   r   rC   s     r2   _get_forwarded_portz(CommandLineInterface._get_forwarded_port   sD    
 "",,d6I6IPT,U***% r4   c                 d   | j                   j                  |      }t        j                  t        j                  t        j
                  t        j                  t        j                  d|j                     |j                         d}|j                  r8|j                  dk(  rt        j                  }n7t        |j                  dd      }n|j                  dk\  rt        j                  }t        j                  j                  dd       t        |j                         }t#        |      }t%        |j&                  |j(                  du|j*                  |j,                  du|j.                  g      st0        |_        t2        |_        nG|j&                  r|j(                  t2        |_        n#|j(                  |j&                  st0        |_        t5        |j&                  |j(                  |j*                  |j,                  	      }t7        |j.                  |z         }t8        j;                  d
j=                  dj?                  |                   | jA                  |||jB                  |jD                  |jF                  |jH                  |jJ                  |jJ                  |jL                  |rtO        |      nd|jP                  |j                  | jS                  |      | jU                  |      |jV                  rdnd|jX                        | _-        | jZ                  j]                          y)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+<<<<====	
 nn <<	
 !??#%$'JJ!$(#q$A!^^q  #

 	3$T%5%56/< 				%  $$D0##
 %DI$DIYY499,$DIYY"499$DI6(( 00	
	 4..:;	+22499Y3GHI''#**,,**"44&*&D&D(,(F(F&*&D&D9J"#45PTnnnn+/+C+C+C+N(,(@(@d(@(K'+'9'9#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T    
C 
y 
	%	 	%	&	 	&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}      sH      
 - ; & 9  !			8	$J Jr4   