o
    Ug'                     @   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                   @   sb   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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 r/   V/var/www/html/Testing_prj/Navya-Bakers/venv/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)clsr/   r/   r0   
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.)r7   message)r   r   )r.   r7   r8   r/   r/   r0   _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.
        r7   r8   zX-Forwarded-ForN)r   r:   r+   r   r.   r8   r/   r/   r0   _get_forwarded_host      z(CommandLineInterface._get_forwarded_hostc                 C   r;   )r<   r=   zX-Forwarded-PortN)r    r:   r,   r   r>   r/   r/   r0   _get_forwarded_port   r@   z(CommandLineInterface._get_forwarded_portc                 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 t|j}t|}t|j|jdu|j|jdu|jgsat|_t|_n|jrm|jdu rmt|_n|jdurx|jsxt|_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-.  dS 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!   	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)r8   proxy_forwarded_port_headerproxy_forwarded_proto_headerzX-Forwarded-Protor"   r/   )/r(   
parse_argsloggingbasicConfigWARNINFODEBUGrS   log_fmt
access_logr3   stdoutopenpathinsertr	   r!   r   anyr   rI   r   r   r   DEFAULT_HOSTDEFAULT_PORTr   sortedloggerinforE   joinserver_classrK   rL   rM   rN   rO   rQ   r   r   r?   rA   r   r"   r-   r2   )r.   r8   access_log_streamr!   rJ   r/   r/   r0   r2      s   





	zCommandLineInterface.runN)__name__
__module____qualname____doc__r   r   rj   r1   classmethodr6   strr   r:   r?   rA   r2   r/   r/   r/   r0   r
      s     
	r
   )r&   rX   r3   r   r   asgiref.compatibilityr   accessr   rJ   r   r-   r   utilsr	   	getLoggerrl   rg   rd   re   r
   r/   r/   r/   r0   <module>   s    
