o
    îó·iû'  ã                   @   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.i€Q 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_hostzÌSpecify 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_portz‚Specify 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 attributeZdaphnez--no-server-nameÚstore_const)r   r   Úconst)	ÚargparseÚArgumentParserr   ÚparserÚadd_argumentÚintÚarg_proxy_hostÚarg_proxy_portÚserver)Úself© r/   úPC:\Users\psant\Downloads\PAF backend\school\venv\Lib\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_portÚasgi_app_pathc                 C   s   t |ƒS )z2
        Return the imported application.
        Nr	   )r.   rB   r/   r/   r0   Ú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|rÄt'|ƒnd“d|j(“d|j“d| j)|d�“d| j*|d�“d|j+râdnd“d|j,“Ž| _-| j- .¡  | j-j/rút0dƒ 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_timeoutZwebsocket_handshake_timeoutÚapplication_close_timeoutZaction_loggerr   Ú	verbosityZproxy_forwarded_address_header)r8   Zproxy_forwarded_port_headerZproxy_forwarded_proto_headerzX-Forwarded-Protor#   r/   )1r(   Ú
parse_argsÚloggingÚbasicConfigÚWARNÚINFOÚDEBUGrS   Zlog_fmtZ
access_logr3   ÚstdoutÚopenÚpathÚinsertrC   r"   r   Úanyr   rK   r   r   r   ÚDEFAULT_HOSTÚDEFAULT_PORTr   ÚsortedÚloggerÚinforG   ÚjoinÚserver_classrM   rN   rO   rP   rQ   rR   r   r   r?   rA   r   r#   r-   r2   Zabort_startÚexit)r.   r8   Zaccess_log_streamr"   rL   r/   r/   r0   r2   Ò   s¤   üûù


ûÿ
ü
ÿþýüûúùø	÷€õóòñð€îì
ÿzCommandLineInterface.runN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   re   r1   Úclassmethodr6   Ústrr   r:   r?   rA   rC   r2   r/   r/   r/   r0   r      s     
	r   )r&   rU   r3   r   r   Zasgiref.compatibilityr   Úaccessr   rL   r   r-   r   Úutilsr
   Ú	getLoggerrg   rb   r_   r`   r   r/   r/   r/   r0   Ú<module>   s    
