o
    >h'                     @   s   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eZd	Zd
ZG d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                   @   sp   e Zd ZdZdZeZdd Zedd Z	de
defd	d
ZdefddZdefddZde
fddZdd ZdS )CommandLineInterfacezB
    Acts as the main CLI entry point for running the server.
    zDjango HTTP/WebSocket serverc                 C   s  t j| jd| _| jjddtdd d | jjdddd	d d
 | jjdtddd | jjdtddd | jjddddd d
 | jjdtddd d | jjdddddg d | jjdd td!d"d | jjd#d$td%d d | jjd&d'd d( | jjd)d*d+d( | jjd,td-d.d | jjd/td0d1d | jjd2td3d4d | jjd5d6d7d8d
 | jjd9d:d;d<d=d> | jjd?d@dAd<dBd>| _| jjdCdDdEd<dBd>| _| jjdFdGdH | jjdIdJdKdLdMd
 | jjdNdKdOd8dP 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)self r0   j/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/daphne/cli.py__init__   s  

	
zCommandLineInterface.__init__c                 C   s   |   tjdd  dS )z6
        Main entrypoint for external starts.
        r   N)runsysargv)clsr0   r0   r1   
entrypoint   s   zCommandLineInterface.entrypointargumentargsc                 C   s   |j rdS t|dd)z1Raise if the `--proxy-headers` weren't specified.Nz4--proxy-headers has to be passed for this parameter.)r8   message)r   r   )r/   r8   r9   r0   r0   r1   _check_proxy_headers_passed   s   z0CommandLineInterface._check_proxy_headers_passedc                 C   *   |j r| j| j|d |j S |jrdS dS )m
        Return the default host header from which the remote hostname/ip
        will be extracted.
        r8   r9   zX-Forwarded-ForN)r   r;   r,   r   r/   r9   r0   r0   r1   _get_forwarded_host      z(CommandLineInterface._get_forwarded_hostc                 C   r<   )r=   r>   zX-Forwarded-PortN)r!   r;   r-   r   r?   r0   r0   r1   _get_forwarded_port   rA   z(CommandLineInterface._get_forwarded_portasgi_app_pathc                 C   s   t |S )z2
        Return the imported application.
        r	   )r/   rC   r0   r0   r1   load_asgi_app   s   z"CommandLineInterface.load_asgi_appc                 C   s  | j |}tjtjtjtjtjd|j |jd d}|j	r0|j	dkr(t
j}nt|j	dd}n|jdkr8t
j}t
jdd | |j}t|}t|j|jdu|j|jdu|jgsbt|_t|_n|jrn|jdu rnt|_n|jdury|jsyt|_t|j|j|j|jd	}t|j| }td
d| | j di d|d|d|j!d|j"d|j#d|j$d|j%d|j%d|j&d|rt'|ndd|j(d|jd| j)|dd| j*|dd|j+rdndd|j,| _-| j-.  | j-j/rt0d dS 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"   	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)r9   proxy_forwarded_port_headerproxy_forwarded_proto_headerzX-Forwarded-Protor#   r0   )1r)   
parse_argsloggingbasicConfigWARNINFODEBUGrV   log_fmt
access_logr4   stdoutopenpathinsertrD   r"   r   anyr   rL   r   r   r   DEFAULT_HOSTDEFAULT_PORTr   sortedloggerinforH   joinserver_classrN   rO   rP   rQ   rR   rT   r   r   r@   rB   r   r#   r.   r3   abort_startexit)r/   r9   access_log_streamr"   rM   r0   r0   r1   r3      s   




	
zCommandLineInterface.runN)__name__
__module____qualname____doc__r   r   rm   r2   classmethodr7   strr   r;   r@   rB   rD   r3   r0   r0   r0   r1   r      s     
	r   )r'   r[   r4   r   r   asgiref.compatibilityr   accessr   rM   r   r.   r   utilsr
   	getLoggerrq   rj   rg   rh   r   r0   r0   r0   r1   <module>   s    
