
    h'                         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                   h    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
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    F/var/www/Befach/backend/env/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    r3   
entrypointzCommandLineInterface.entrypoint   s    
 			#((12,r5   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   )r2   r<   r=   s      r3   _check_proxy_headers_passedz0CommandLineInterface._check_proxy_headers_passed   s!    J
 	
r5   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    r2   r=   s     r3   _get_forwarded_hostz(CommandLineInterface._get_forwarded_host   sD    
 "",,d6I6IPT,U***$ r5   c                     |j                   r)| j                  | j                  |       |j                   S |j                  ryy)rB   rC   zX-Forwarded-PortN)r$   r@   r0   r    rD   s     r3   _get_forwarded_portz(CommandLineInterface._get_forwarded_port   sD    
 "",,d6I6IPT,U***% r5   asgi_app_pathc                     t        |      S )z2
        Return the imported application.
        r
   )r2   rH   s     r3   load_asgi_appz"CommandLineInterface.load_asgi_app   s     m,,r5   c                    | 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       | j                  |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]                          | jZ                  j^                  rta        d       y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&   )1r,   
parse_argsloggingbasicConfigWARNINFODEBUGr]   log_fmt
access_logr8   stdoutopenpathinsertrJ   r%   r   anyr   rS   r   r   r   DEFAULT_HOSTDEFAULT_PORTr   sortedloggerinforO   joinserver_classrU   rV   rW   rX   rY   r[   r   r   rE   rG   r    r&   r1   r7   abort_startexit)r2   r=   access_log_streamr%   rT   s        r3   r7   zCommandLineInterface.run   s    {{%%d+<<<<====	
 nn <<	
 !??#%$'JJ!$(#q$A!^^q  #

 	3(()9)9:/< 				%  $$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(() ( 
, 	;;""G #r5   N)__name__
__module____qualname____doc__r   r	   rt   r4   classmethodr;   strr   r@   rE   rG   rJ   r7    r5   r3   r   r      sk     1KLHT    
C 
y 
	%	 	%	&	 	&-3 -Sr5   r   )r*   rb   r8   r   r   asgiref.compatibilityr   accessr   rT   r   r1   r	   utilsr   	getLoggerrx   rq   rn   ro   r   r~   r5   r3   <module>r      sH      
 - ; & 9  !			8	$R Rr5   