o
    0c                  $   @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
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 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 ddlmZ zddlZW n ey   G dd dZe ZY nw dZejdkrze d W n ey   dZY nw e!edZ"e"rej#Z#nG dd dZ#zej$Z%W n e&y   dZ%Y nw dZ'e( dk oe!edZ)e	j*e	j+de	j,e-e	j*e- f df  Z.e	j/rddl0Z1ddl2m3Z3 ddl2m4Z4 ddl5m6Z6 dd l7m8Z8 G d!d" d"ej9Z:G d#d$ d$eZ;d%e-d&e-d'e-fd(d)Z<	djd*e	j*e- d'e	j,d+ fd,d-Z=	dkd.e-d/e	j*e- d*e	j*e- d'e	j,e-e-f fd0d1Z>dld2d3Z?	dkd4e-d5e	j*e- d6e	j*e@ d'dfd7d8ZAdjd9e	j*eB d'eCfd:d;ZDd/e-d<e@d'ejEfd=d>ZFd/e-d<e@d?ejEd'e	j+e	j,e-e@f e-f fd@dAZGd?ejEd'e-fdBdCZHG dDdE dEeZIG dFdG dGejJeIZKG dHdI dIe#eIZL						dmd/e-d<e@dJdKdLeCdMe@dNe	j*e	jMe;  dOeCdPe	j*e. dQe	j*e@ d'eIfdRdSZNd'eCfdTdUZO							V						dndWe-d<e@dXdKdYeCdZeCd[eCd\e	j*e	jPe-  d]e	j*e	jPe-  d^e@d_e-dLeCdMe@dNe	j*e	jMe;  d`e	j*e	jQe-e	j+e-e	j,e-e-f f f  dOeCdPe	j*e. d'df"dadbZRdce	jSdde	jSd'dfdedfZTdodgdhZUeVdikr`eU  dS dS )pa  A WSGI and HTTP server for use **during development only**. This
server is convenient to use, but is not designed to be particularly
stable, secure, or efficient. Use a dedicate WSGI server and HTTP
server when deploying to production.

It provides features like interactive debugging and code reloading. Use
``run_simple`` to start the server. Put this in a ``run.py`` script:

.. code-block:: python

    from myapp import create_app
    from werkzeug import run_simple
    N)datetime)	timedelta)timezone)BaseHTTPRequestHandler)
HTTPServer   _log)_wsgi_encoding_dance)InternalServerError)
uri_to_iri)	url_parse)url_unquotec                   @   s    e Zd ZdedejfddZdS )	_SslDummynamereturnc                 C   s   t d)NzSSL support unavailable)RuntimeError)selfr    r   F/var/www/html/gps/gps/lib/python3.10/site-packages/werkzeug/serving.py__getattr__)   s   z_SslDummy.__getattr__N)__name__
__module____qualname__strtAnyr   r   r   r   r   r   (   s    r   TntcoloramaFforkc                   @   s   e Zd ZdS )ForkingMixInN)r   r   r   r   r   r   r   r    <   s    r       Windowsfromfdssl.SSLContextzte.Literal['adhoc'])WSGIApplication)WSGIEnvironment)RSAPrivateKeyWithSerialization)Certificatec                   @   sR   e Zd ZdZdejddfddZdefddZde	fd	d
Z
dede	fddZdS )DechunkedInputz8An input stream that handles Transfer-Encoding 'chunked'rfiler   Nc                 C   s   || _ d| _d| _d S )NFr   )_rfile_done_len)r   r*   r   r   r   __init__Y   s   
zDechunkedInput.__init__c                 C      dS )NTr   r   r   r   r   readable^   s   zDechunkedInput.readablec                 C   sN   z| j  d}t| d}W n ty   tdw |dk r%td|S )Nlatin1   zInvalid chunk headerr   z!Negative chunk length not allowed)r+   readlinedecodeintstrip
ValueErrorOSError)r   liner-   r   r   r   read_chunk_lena   s   zDechunkedInput.read_chunk_lenbufc                 C   s  d}| j s|t|k r| jdkr|  | _| jdkrd| _ | jdkrgtt|| j}|| t|krP| jt|| ||d < |  jt|| 8  _t|}n| j||||| < |  j|8  _||7 }| jdkry| j }|dvrytd| j s|t|k s|S )Nr   T)   
s   
   z!Missing chunk terminating newline)	r,   lenr-   r;   minr+   readr4   r9   )r   r<   rA   n
terminatorr   r   r   readintok   s*   






$zDechunkedInput.readinto)r   r   r   __doc__r   BinaryIOr.   boolr1   r6   r;   	bytearrayrD   r   r   r   r   r)   V   s    
r)   c                       sH  e Zd ZU dZded< edefddZd.dd	Zd/ddZ	d/ddZ
d/ddZ	
d0dedejd dd
fddZd/ddZd0dedeje dd
fddZdef fddZdefddZdefdd Z	!d1dejeef d"ejeef dd
fd#d$Zd%ed&ejdd
fd'd(Zd%ed&ejdd
fd)d*Zd+eded&ejdd
fd,d-Z  ZS )2WSGIRequestHandlerz3A request handler that implements WSGI dispatching.BaseWSGIServerserverr   c                 C   s   ddl m} d| S )Nr   )__version__z	Werkzeug/) rL   )r   rL   r   r   r   server_version   s   
z!WSGIRequestHandler.server_versionr&   c           	         sT  t  j}d. fdd} jjd u rdnd} jsd _nt jtr) jdf _|js9|jr9d|j |j }n|j}t	|}i d	d
d|d j
dtjd jjd jjddd|d jd jd jdddt|dt|jdt jdt jd     jjd t jjd  jd} j D ],\}}| dd }|d!d}|d"vrd#| }||v r||  d$| }|||< q|d%d  d&krd'|d(< t|d |d< |jr|jr|j|d)< z jj d'd*}|d urt!"||d+< W |S W |S  t#y    j$d,d- Y |S  t%y)   Y |S w )/Nr   c                      s   t jddd d j_d S )NzeThe 'environ['werkzeug.server.shutdown']' function is deprecated and will be removed in Werkzeug 2.1.   
stacklevelT)warningswarnrK   shutdown_signalr   r0   r   r   shutdown_server   s
   z8WSGIRequestHandler.make_environ.<locals>.shutdown_serverhttphttps)<local>r   r   /zwsgi.version)r   r   zwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_onceFzwerkzeug.server.shutdownzwerkzeug.socketSERVER_SOFTWAREREQUEST_METHODSCRIPT_NAMErM   	PATH_INFOQUERY_STRINGREQUEST_URIRAW_URIREMOTE_ADDRr   )REMOTE_PORTSERVER_NAMESERVER_PORTSERVER_PROTOCOL-_
)CONTENT_TYPECONTENT_LENGTHHTTP_,HTTP_TRANSFER_ENCODINGchunkedTzwsgi.input_terminated	HTTP_HOST)binary_formSSL_CLIENT_CERTerrorz&Cannot fetch SSL peer certificate infor   N)&r   pathrK   ssl_contextclient_address
isinstancer   schemenetlocr   r*   sysstderrmultithreadmultiprocess
connectionrN   commandr
   queryaddress_stringport_integerserver_addressrequest_versionheadersitemsupperreplacegetr7   lowerr)   getpeercertsslDER_cert_to_PEM_certr8   logAttributeError)	r   request_urlrU   
url_scheme	path_infoenvironkeyvalue	peer_certr   r0   r   make_environ   s   
	









zWSGIRequestHandler.make_environNc                    sN  j dd  dkrjd   _ d d d d dtdd f fdddfd	d
	d fdd}z	|j	j
 W d S  ttjfyk } z|  W Y d }~d S d }~w ty   j	jrv ddlm} |dd}zd u rd d |t  W n	 ty   Y nw j	dd|j Y d S w )NExpectrM   z100-continues   HTTP/1.1 100 Continue

datar   c                    sB  d usJ dd usJ dd u rz
 d d\}}W n ty0   d}}Y nw t|}|| t }D ]\}}|| | }|| q@d|v so d dkso|dk so|dv sod	_d
d d|vr{d	  d|vrd
    t| tsJ dj|  j  d S )Nzwrite() before start_responser   rM   zcontent-lengthr[   HEAD   )   i0  T
ConnectioncloserK   ServerdateDatezapplications must write bytes)splitr8   r6   send_responsesetsend_headerr   addclose_connectionversion_stringdate_time_stringend_headersrw   byteswfilewriteflush)r   code_strmsgcodeheader_keysr   r   )r   headers_sentheaders_setr   status_sent
status_setr   r   r     sF   
z*WSGIRequestHandler.run_wsgi.<locals>.writec                    sB   |rz r|d  |d W d }n	d }w rtd| |S )Nr   rO   zHeaders already set)with_tracebackAssertionError)statusr   exc_info)r   r   r   r   r   r   start_response%  s   z3WSGIRequestHandler.run_wsgi.<locals>.start_responseappr%   c              	      s\   |  }z|D ]}| qsd W t |dr!|  d S d S t |dr-|  w w )N    r   )hasattrr   )r   application_iterr   )r   r   r   r   r   r   execute3  s   



z,WSGIRequestHandler.run_wsgi.<locals>.executer   )get_current_tracebackT)ignore_system_exceptionsrr   zError on request:
%sN)r   r%   r   N)r   r   r   r7   r   r   r   r   r   rK   r   ConnectionErrorsockettimeoutconnection_dropped	Exceptionpassthrough_errorsdebug.tbtoolsr   r   r   	plaintext)r   r   er   	tracebackr   )r   r   r   r   r   r   r   r   r   run_wsgi   s<    $
zWSGIRequestHandler.run_wsgic              
   C   s   zt |  W n= ttjfy! } z| | W Y d}~n(d}~w tyD } z| jjdur9t	|r9| 
d| n W Y d}~nd}~ww | jjrO|   dS dS )z/Handles a request ignoring dropped connections.NzSSL error occurred: %s)r   handler   r   r   r   r   rK   ru   is_ssl_error	log_errorrT   initiate_shutdown)r   r   r   r   r   r   S  s   zWSGIRequestHandler.handlec                 C   s0   t  rttdtj}tt | d| j_d S )NSIGKILLT)	is_running_from_reloadergetattrsignalSIGTERMoskillgetpidrK   _BaseServer__shutdown_request)r   sigr   r   r   r   a  s   z$WSGIRequestHandler.initiate_shutdownrr   r   c                 C   r/   )z`Called if the connection was closed by the client.  By default
        nothing happens.
        Nr   )r   rr   r   r   r   r   r   i  s    z%WSGIRequestHandler.connection_droppedc                 C   s4   | j  | _| jsd| _dS |  r|   dS dS )zHandle a single HTTP request.TN)r*   r4   raw_requestliner   parse_requestr   r0   r   r   r   handle_one_requestp  s   
z%WSGIRequestHandler.handle_one_requestr   messagec                 C   sj   |  | |du r|| jv r| j| d nd}| jdkr3| j d| d| d}| j|d dS dS )z3Send the response header and log the response code.Nr   rM   zHTTP/0.9 rh   ascii)log_request	responsesr   protocol_versionr   r   encode)r   r   r   hdrr   r   r   r   x  s   

z WSGIRequestHandler.send_responsec                    s   t    S r   )superr   r7   r0   	__class__r   r   r     s   z!WSGIRequestHandler.version_stringc                 C   s*   t | dd r| jd S | jsdS | jd S )Nr   ra   rX   r   )r   r   rv   r0   r   r   r   r     s
   

z!WSGIRequestHandler.address_stringc                 C   s
   | j d S )Nr   )rv   r0   r   r   r   r     s   
zWSGIRequestHandler.port_integerrf   sizec                 C   s   zt | j}| j d| d| j }W n ty   | j}Y nw t|}trj|d dkr2t|d}n8|dkr7n3|dkrAt|d}n)|d dkrMt|d	}n|d
krWt|d}n|d dkrdt|dd}nt|dd}| 	dd||| d S )Nr   r   1bold200304cyan3green404yellow4redmagentainfoz
"%s" %s %s)
r   rt   r   r   r   requestliner   _log_add_style_ansi_styler   )r   r   r   rt   r   r   r   r   r     s,   

zWSGIRequestHandler.log_requestformatargsc                 G      | j d|g|R   d S )Nrr   r   r   r   r   r   r   r   r        zWSGIRequestHandler.log_errorc                 G   r   )Nr   r   r   r   r   r   log_message  r  zWSGIRequestHandler.log_messagetypec                 G   s0   t ||   d|   d| dg|R   d S )Nz - - [z] 
)r	   r   log_date_time_stringr   r  r   r   r   r   r   r     s   zWSGIRequestHandler.log)r   r&   rs   r   )rf   rf   )r   r   r   rE   __annotations__propertyr   rN   r   r   r   r   BaseExceptionr   Optionalr   r   r6   r   r   r   r   Unionr   r   r   r  r   __classcell__r   r   r   r   rI      sB   
 

X
\
	

		
$rI   r   stylesr   c                 G   s:   ddddddd}|D ]}d||  d	|  } q|  d
S )Nr          !   #   $   )r   r   r   r   r   r   z[mz[0mr   )r   r  codesstyler   r   r   r     s   	
r   cn)r(   r'   c           
      C   s2  z ddl m} ddlm} ddlm} ddlm} ddlm	} W n t
y+   tdw | }|jdd	|d
}| d u r=d} |||jd||j| g}| }| ||| | ttjttjtdd j||j gddj|!|"dgdd#||$ |}	|	|fS )Nr   )x509)NameOID)default_backend)hashes)rsaz<Using ad-hoc certificates requires the cryptography library.i  i   )public_exponentkey_sizebackend*zDummy Certificateim  )daysF)critical)%cryptographyr  cryptography.x509.oidr  cryptography.hazmat.backendsr  cryptography.hazmat.primitivesr  )cryptography.hazmat.primitives.asymmetricr  ImportError	TypeErrorgenerate_private_keyNameNameAttributeORGANIZATION_NAMECOMMON_NAMECertificateBuildersubject_nameissuer_name
public_keyserial_numberrandom_serial_numbernot_valid_beforedtnowr   utcnot_valid_afterr   add_extensionExtendedKeyUsageOID_SERVER_AUTHSubjectAlternativeNameDNSNamesignSHA256)
r  r  r  r  r  r  r  pkeysubjectcertr   r   r   generate_adhoc_ssl_pair  sF   

	rC  	base_pathhostc           	      C   s   |durd| d| }t |d\}}ddlm} |  d}|  d}t|d	}|||jj W d   n1 s=w   Y  t|d	}||j|jj|j	j
| d
 W d   ||fS 1 sfw   Y  ||fS )a  Creates an SSL key for development.  This should be used instead of
    the ``'adhoc'`` key which generates a new cert on each server start.
    It accepts a path for where it should store the key and cert and
    either a host or CN.  If a host is given it will use the CN
    ``*.host/CN=host``.

    For more information see :func:`run_simple`.

    .. versionadded:: 0.9

    :param base_path: the path to the certificate and key.  The extension
                      ``.crt`` is added for the certificate, ``.key`` is
                      added for the key.
    :param host: the name of the host.  This can be used as an alternative
                 for the `cn`.
    :param cn: the `CN` to use.
    Nz*.z/CN=)r  r   serializationz.crtz.keywbencodingr   encryption_algorithm)rC  r%  rG  openr   public_bytesEncodingPEMprivate_bytesPrivateFormatTraditionalOpenSSLNoEncryption)	rD  rE  r  rB  r@  rG  	cert_file	pkey_filefr   r   r   make_ssl_devcert  s*   


		rW  c            
      C   s   ddl } ddl}t \}}ddlm} |  \}}|  \}}|tj| |tj| t	||
|jj t	||j|jj|jj| d t| t| t||}	|	S )z:Generates an adhoc SSL context for the development server.r   NrF  rI  )tempfileatexitrC  r%  rG  mkstempregisterr   remover   rM  rN  rO  rP  rQ  rR  rS  r   load_ssl_context)
rX  rY  rB  r@  rG  cert_handlerT  pkey_handlerU  ctxr   r   r   generate_adhoc_ssl_context$  s*   

	

ra  rT  rU  protocolc                 C   s(   |du rt j}t |}|| | |S )a  Loads SSL context from cert/private key files and optional protocol.
    Many parameters are directly taken from the API of
    :py:class:`ssl.SSLContext`.

    :param cert_file: Path of the certificate to use.
    :param pkey_file: Path of the private key to use. If not given, the key
                      will be obtained from the certificate file.
    :param protocol: A ``PROTOCOL`` constant from the :mod:`ssl` module.
        Defaults to :data:`ssl.PROTOCOL_TLS_SERVER`.
    N)r   PROTOCOL_TLS_SERVER
SSLContextload_cert_chain)rT  rU  rb  r`  r   r   r   r]  B  s
   
r]  rr   c                 C   s(   | du rt tt d } t| tjS )z?Checks if the given error (or the current one) is an SSL error.Nr   )r   castr   rz   r   rw   r   SSLError)rr   r   r   r   r   W  s   r   portc                 C   s.   |  drtjS d| v rttdrtjS tjS )zUReturn ``AF_INET4``, ``AF_INET6``, or ``AF_UNIX`` depending on
    the host and port.zunix://:AF_INET6)
startswithr   AF_UNIXr   rj  AF_INET)rE  rh  r   r   r   select_address_family^  s
   
rn  familyc                 C   s\   |t kr| ddd S zt| ||tjtj}W n tjy'   | |f Y S w |d d S )zVReturn a fully qualified socket address that can be passed to
    :func:`socket.bind`.z://r   r      )af_unixr   r   getaddrinfoSOCK_STREAMIPPROTO_TCPgaierror)rE  rh  ro  resr   r   r   get_sockaddrh  s   rw  c              	   C   s   | t jkrdnd}t  | t j1}z	||df W n ty3   | t jkr(dnd Y W  d   S w | d W  d   S 1 sDw   Y  dS )zGet the IP address of an external interface. Used when binding to
    0.0.0.0 or ::1 to show a more useful URL.

    :meta private:
    zfd31:f903:5ab5:1::1z10.253.155.219i2  z::1	127.0.0.1Nr   )r   rj  
SOCK_DGRAMconnectr9   getsockname)ro  rE  sr   r   r   get_interface_ipx  s   
$r}  c                       s   e Zd ZdZdZdZeZ				ddede	ddde
je
je  d	ed
e
je de
je	 ddf fddZdedede
jddfddZddeddf fddZde
jde
jee	f ddf fddZ  ZS )rJ   z3Simple single-threaded, single-process WSGI server.FNrE  rh  r   r%   handlerr   ru   fdr   c           
         s  |d u rt }t||| _|d urt|| jtj}d}t|t|| j}	| jtkr:t	
t|	}	tj|	r:t|	 t |	| || _|| _d| _|| _| j d | _|d urg| j  || _| j | _|d urt|trtt| }|dkr{t }|j| jdd| _|| _d S d | _d S )Nr   Fr   adhocT)server_side) rI   rn  address_familyr   r#   rs  rw  r6   rq  r   rf  r   r   rt   existsunlinkr   r.   r   r   rT   rE  r{  rh  r   r   rw   tupler]  ra  wrap_socketru   )
r   rE  rh  r   r~  r   ru   r  	real_sockr   r   r   r   r.     s:   






zBaseWSGIServer.__init__r  r   r   c                 G   s   t ||g|R   d S r   r   r  r   r   r   r     s   zBaseWSGIServer.log      ?poll_intervalc                    sT   d| _ z!z	t j|d W n	 ty   Y nw W |   d S W |   d S |   w )NF)r  )rT   r   serve_foreverKeyboardInterruptserver_close)r   r  r   r   r   r    s   zBaseWSGIServer.serve_foreverrequestrv   c                    s   | j r t ||S r   )r   r   handle_error)r   r  rv   r   r   r   r    s   zBaseWSGIServer.handle_error)NFNN)r  )r   r   r   rE   r|   r}   LISTEN_QUEUErequest_queue_sizer   r6   r   r
  TyperI   rG   _TSSLContextArgr.   r   r   floatr  Tupler  r  r   r   r   r   rJ     s:    	5.	rJ   c                   @   s   e Zd ZdZdZdZdS )ThreadedWSGIServerz"A WSGI server that does threading.TN)r   r   r   rE   r|   daemon_threadsr   r   r   r   r    s    r  c                   @   sf   e Zd ZdZdZ					ddededd	d
edejej	e
  dedeje deje ddfddZdS )ForkingWSGIServerz A WSGI server that does forking.T(   NFrE  rh  r   r%   	processesr~  r   ru   r  r   c	           	   
   C   s.   t stdt| ||||||| || _d S )Nz'Your platform does not support forking.)can_forkr8   rJ   r.   max_children)	r   rE  rh  r   r  r~  r   ru   r  r   r   r   r.     s   
zForkingWSGIServer.__init__)r  NFNN)r   r   r   rE   r}   r   r6   r   r
  r  rI   rG   r  r.   r   r   r   r   r    s6    	
r  r   r%   threadedr  request_handlerr   ru   r  c	           	   
   C   sd   |r
|dkr
t d|rt| ||||||dS |dkr't| |||||||dS t| ||||||dS )ztCreate a new server instance that is either threaded, or forks
    or just processes one request after another.
    r   z5cannot have a multithreaded and multi process server.r  )r8   r  r  rJ   )	rE  rh  r   r  r  r  r   ru   r  r   r   r   make_server  s(   r  c                   C   s   t jddkS )zwChecks if the application is running from within the Werkzeug
    reloader subprocess.

    .. versionadded:: 0.10
    WERKZEUG_RUN_MAINtrue)r   r   r   r   r   r   r   r      s   r   autohostnameapplicationuse_reloaderuse_debugger
use_evalexextra_filesexclude_patternsreloader_intervalreloader_typestatic_filesc              
      sn  t ts	td|rddlm} | | |r#ddlm} | | dtjddffdd	d f	d
d}|rt sdkrNt	sNt
dt}t|}t|tj}|tjtjd || |d t	rt| tjd< |t | n|  |tkrtt|}tdd| t| ddlm } ||||||	d dS |  dS )a  Start a WSGI application. Optional features include a reloader,
    multithreading and fork support.

    This function has a command-line interface too::

        python -m werkzeug.serving --help

    .. versionchanged:: 2.0
        Added ``exclude_patterns`` parameter.

    .. versionadded:: 0.5
       `static_files` was added to simplify serving of static files as well
       as `passthrough_errors`.

    .. versionadded:: 0.6
       support for SSL was added.

    .. versionadded:: 0.8
       Added support for automatically loading a SSL context from certificate
       file and private key.

    .. versionadded:: 0.9
       Added command-line interface.

    .. versionadded:: 0.10
       Improved the reloader and added support for changing the backend
       through the `reloader_type` parameter.  See :ref:`reloader`
       for more information.

    .. versionchanged:: 0.15
        Bind to a Unix socket by passing a path that starts with
        ``unix://`` as the ``hostname``.

    :param hostname: The host to bind to, for example ``'localhost'``.
        If the value is a path that starts with ``unix://`` it will bind
        to a Unix socket instead of a TCP socket..
    :param port: The port for the server.  eg: ``8080``
    :param application: the WSGI application to execute
    :param use_reloader: should the server automatically restart the python
                         process if modules were changed?
    :param use_debugger: should the werkzeug debugging system be used?
    :param use_evalex: should the exception evaluation feature be enabled?
    :param extra_files: a list of files the reloader should watch
                        additionally to the modules.  For example configuration
                        files.
    :param exclude_patterns: List of :mod:`fnmatch` patterns to ignore
        when running the reloader. For example, ignore cache files that
        shouldn't reload when updated.
    :param reloader_interval: the interval for the reloader in seconds.
    :param reloader_type: the type of reloader to use.  The default is
                          auto detection.  Valid values are ``'stat'`` and
                          ``'watchdog'``. See :ref:`reloader` for more
                          information.
    :param threaded: should the process handle each request in a separate
                     thread?
    :param processes: if greater than 1 then handle each request in a new process
                      up to this maximum number of concurrent processes.
    :param request_handler: optional parameter that can be used to replace
                            the default one.  You can use this to replace it
                            with a different
                            :class:`~BaseHTTPServer.BaseHTTPRequestHandler`
                            subclass.
    :param static_files: a list or dict of paths for static files.  This works
                         exactly like :class:`SharedDataMiddleware`, it's actually
                         just wrapping the application in that middleware before
                         serving.
    :param passthrough_errors: set this to `True` to disable the error catching.
                               This means that the server will die on errors but
                               it can be useful to hook debuggers in (pdb etc.)
    :param ssl_context: an SSL context for the connection. Either an
                        :class:`ssl.SSLContext`, a tuple in the form
                        ``(cert_file, pkey_file)``, the string ``'adhoc'`` if
                        the server should automatically create one, or ``None``
                        to disable SSL (which is the default).
    zport must be an integerr   )DebuggedApplication)SharedDataMiddlewaresockr   Nc                    s   d}| j tkrtdd  d S  dkrtd| ttj}n dkr-td| ttj}n }d|v r9d| d	}tdd
d u rBdnd||  d  d S )Nzp * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.r   z' * Running on %s (Press CTRL+C to quit)z0.0.0.0warningz::ri  []z0 * Running on %s://%s:%d/ (Press CTRL+C to quit)rV   rW   r   )ro  rq  r	   r}  r   rm  rj  r{  )r  all_addresses_messagedisplay_hostname)r  ru   r   r   log_startup  s(   



zrun_simple.<locals>.log_startupc                     sf   z	t tjd } W n ttfy   d } Y nw t | d	}| d u r-|j |  d S )NWERKZEUG_SERVER_FDr  )r6   r   r   LookupErrorr8   r  r   r  )r  srv	r  r  r  r   rh  r  r  ru   r  r   r   inner  s&   
zrun_simple.<locals>.innerr   zsCannot bind to a random port with enabled reloader if the Python interpreter does not support socket opening by fd.Tr  r   zUnlinking %srun_with_reloader)r  r  intervalr  rs   )!rw   r6   r(  debugr  middleware.shared_datar  r   r   can_open_by_fdr8   rn  rw  rs  
setsockopt
SOL_SOCKETSO_REUSEADDRbindset_inheritabler   filenor   r   listenr  r   rq  r   rf  r	   r  	_reloaderr  )r  rh  r  r  r  r  r  r  r  r  r  r  r  r  r   ru   r  r  r  r  r   r|  _rwrr   r  r   
run_simple)  sP   
]


	






r  r   kwargsc                  O   s.   ddl m} tjdtdd || i | dS )zRun a process with the reloader. This is not a public API, do
    not use this function.

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1.
    r   r  zp'run_with_reloader' is a private API, it will no longer be accessible in Werkzeug 2.1. Use 'run_simple' instead.rO   rP   N)r  r  rR   rS   DeprecationWarning)r   r  r  r   r   r   r    s   r  c                  C   s   ddl } ddlm} tdd | jddd	}|jd
dddd |jddddd |jddddd |jddd | }d\}}|jrL|jd\}}}t	|pPdt
|pTd||j|j|jd dS )z:A simple command-line interface for :py:func:`run_simple`.r   Nr   )import_stringr  z:This CLI is deprecated and will be removed in version 2.1.z;Run the given WSGI application with the development server.F)descriptionallow_abbrevz-bz--bindaddressz+The hostname:port the app should listen on.)desthelpz-dz--debug
store_truez7Show the interactive debugger for unhandled exceptions.)actionr  z-rz--reloadz%Reload the process if modules change.r  z8Application to import and serve, in the form module:app.)r  NNri  rx  i  )r  rh  r  r  r  )argparseutilsr  r	   ArgumentParseradd_argument
parse_argsr  	partitionr  r6   r  reloadr  )r  r  parserr   r  rh  rg   r   r   r   main  sN   


r  __main__r   r  )r   r$   )Fr   NFNN)FFTNNr   r  Fr   NNFNrs   )WrE   ior   platformr   r   socketserverrz   typingr   rR   r   r5  r   r   http.serverr   r   	_internalr	   r
   
exceptionsr   urlsr   r   r   r   r'  r   r   r   
__import__r   r  r    rl  rq  r   r  systemr  r
  r  r  r   r  TYPE_CHECKINGtyping_extensionste_typeshed.wsgir%   r&   -cryptography.hazmat.primitives.asymmetric.rsar'   cryptography.x509r(   	RawIOBaser)   rI   r   rC  rW  ra  r6   r]  r   rG   r   AddressFamilyrn  rw  r}  rJ   ThreadingMixInr  r  r  r  r   IterableDictr  r   r  r  r   r   r   r   r   <module>   sn   



>  *
-

,


P	

%	
&
 K

/
