
    d              $          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	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 	 ddlZn"# e$ r  G d d          Z e            ZY nw xY wdZej        dk    r	  ed           n# e$ r dZY nw xY w eed          Z e rej!        Z!n G d d          Z!	 ej"        Z#n# e$$ r dZ#Y nw xY wdZ%ej&        ej'        dej(        e)ej&        e)         f         df                  Z*ej+        rddl,Z-ddl.m/Z/ ddl.m0Z0 ddl1m2Z2 ddl3m4Z4  G d d ej5                  Z6 G d! d"e          Z7d#e)d$e)d%e)fd&Z8	 dUd'ej&        e)         d%ej(        d(         fd)Z9	 dVd*e)d+ej&        e)         d'ej&        e)         d%ej(        e)e)f         fd,Z:dWd-Z;	 dVd.e)d/ej&        e)         d0ej&        e<         d%dfd1Z=dUd2ej&        e>         d%e?fd3Z@d+e)d4e<d%ejA        fd5ZBd+e)d4e<d6ejA        d%ej'        ej(        e)e<f         e)f         fd7ZCd6ejA        d%e)fd8ZD G d9 d:e          ZE G d; d<ejF        eE          ZG G d= d>e!eE          ZH	 	 	 	 	 	 dXd+e)d4e<d?d@dAe?dBe<dCej&        ejI        e7                  dDe?dEej&        e*         dFej&        e<         d%eEfdGZJd%e?fdHZK	 	 	 	 	 	 	 	 	 	 	 	 	 dYdJe)d4e<dKd@dLe?dMe?dNe?dOej&        ejL        e)                  dPej&        ejL        e)                  dQe<dRe)dAe?dBe<dCej&        ejI        e7                  dSej&        ejM        e)ej'        e)ej(        e)e)f         f         f                  dDe?dEej&        e*         d%df"dTZNdS )Za  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                   (    e Zd Zdedej        fdZdS )	_SslDummynamereturnc                      t          d          )NzUSSL is unavailable because this Python runtime was not compiled with SSL/TLS support.)RuntimeError)selfr   s     0lib/python3.11/site-packages/werkzeug/serving.py__getattr__z_SslDummy.__getattr__'   s    2      N)__name__
__module____qualname__strtAnyr    r   r   r   r   &   s8        	C 	AE 	 	 	 	 	 	r   r   TntcoloramaFforkc                       e Zd ZdS )ForkingMixInN)r   r   r   r    r   r   r%   r%   =   s        r   r%      ssl.SSLContextzte.Literal['adhoc'])WSGIApplication)WSGIEnvironment)RSAPrivateKeyWithSerialization)Certificatec                   `    e Zd ZdZdej        e         ddfdZdefdZ	de
fdZdede
fd	ZdS )
DechunkedInputz8An input stream that handles Transfer-Encoding 'chunked'rfiler   Nc                 0    || _         d| _        d| _        d S )NFr   )_rfile_done_len)r   r.   s     r   __init__zDechunkedInput.__init__Y   s    
			r   c                     dS )NTr    r   s    r   readablezDechunkedInput.readable^   s    tr   c                    	 | j                                                             d          }t          |                                d          }n"# t
          $ r}t          d          |d }~ww xY w|dk     rt          d          |S )Nlatin1   zInvalid chunk headerr   z!Negative chunk length not allowed)r0   readlinedecodeintstrip
ValueErrorOSError)r   liner2   es       r   read_chunk_lenzDechunkedInput.read_chunk_lena   s    	9;''))00::Dtzz||R((DD 	9 	9 	9011q8	9!8 	?=>>>s   AA 
A0A++A0bufc                    d}| j         su|t          |          k     ra| j        dk    r|                                 | _        | j        dk    rd| _         | j        dk    rt	          t          |          | j                  }||z   t          |          k    r_| j                            t          |          |z
            ||d <   | xj        t          |          |z
  z  c_        t          |          }n7| j                            |          ||||z   <   | xj        |z  c_        ||z  }| j        dk    r,| j                                        }|dvrt          d          | j         s|t          |          k     a|S )Nr   T)   
   
   z!Missing chunk terminating newline)	r1   lenr2   rB   minr0   readr:   r?   )r   rC   rJ   n
terminators        r   readintozDechunkedInput.readintok   s   * "	GC "	GyA~ 2 !//11	yA~ " "
y1}  C$),,
 !8c#hh& !%!1!1#c((T/!B!BCJIISD0IIs88DD+/;+;+;A+>+>Ctax(IINIIAIDyA~ G "[1133
%<< G!"EFFFE * "	GC "	GH r   )r   r   r   __doc__r   IObytesr3   boolr6   r<   rB   	bytearrayrM   r    r   r   r-   r-   V   s        BBad5k d    
$        &I &# & & & & & &r   r-   c                   j    e Zd ZU dZded<   edefd            ZddZdd	Z	d fd
Z
	 ddedej        d         ddfdZdedej        f fdZdefdZdefdZ	 d dej        eef         dej        eef         ddfdZdedej        ddfdZdedej        ddfdZdededej        ddfdZ xZS )!WSGIRequestHandlerz3A request handler that implements WSGI dispatching.BaseWSGIServerserverr   c                     ddl m} d| S )Nr   )__version__z	Werkzeug/) rX   )r   rX   s     r   server_versionz!WSGIRequestHandler.server_version   s"    !!!!!!(;(((r   r)   c                    t          | j                  }| j        j        dnd}| j        sd| _        n(t          | j        t                    r| j        df| _        |j        s|j        rd|j         |j         }n|j        }t          |          }i ddd|d	| j
        d
t          j        d| j        j        d| j        j        ddd| j        d| j        d| j        dddt%          |          dt%          |j                  dt%          | j                  dt%          | j                  d|                                 d|                                 | j        j        d         t          | j        j        d                   | j        d}| j                                        D ]b\  }}|                                                    dd          }|                    dd          }|dvrd | }||v r||          d!| }|||<   c|                    d"d                                                                          d#k    rd$|d%<   t?          |d	                   |d	<   |j        r|j        r
|j        |d&<   	 | j                             d$'          }|tC          j"        |          |d(<   n6# tF          $ r | j        $                    d)d*           Y ntJ          $ r Y nw xY w|S )+N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.socketSERVER_SOFTWAREREQUEST_METHODSCRIPT_NAMErY   	PATH_INFOQUERY_STRINGREQUEST_URIRAW_URIREMOTE_ADDRREMOTE_PORTr   )SERVER_NAMESERVER_PORTSERVER_PROTOCOL-_z
)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   pathrV   ssl_contextclient_address
isinstancer   schemenetlocr   r.   sysstderrmultithreadmultiprocess
connectionrZ   commandr   queryaddress_stringport_integerserver_addressrequest_versionheadersitemsupperreplacegetr=   lowerr-   getpeercertsslDER_cert_to_PEM_certr>   logAttributeError)r   request_url
url_scheme	path_infoenvironkeyvalue	peer_certs           r   make_environzWSGIRequestHandler.make_environ   s   	**#{6KVVG
" 	;"0D+S11 	;#'#6":D
 ! 	)k&8 	)BK.B0@BBII#(I	**	&
F&
z&
 $*&
 3:	&

  7&
  !9&
 U&
 t&
 t2&
 dl&
 2&
 -i88&
 01BCC&
 /	::&
" +DI66#&
$ 4..00%&
& 4,,..'&
(  ;5a8t{9!<==#3-&
 &
 &
2 ,,,.. 	! 	!JC))++%%c3//CMM&"--E<< 6#cmm'> 6&s|55e55E GCLL;;/44::<<BBDD	Q 	J/3G+,$27<3H$I$IGL!  	6+"4 	6#.#5GK 	 333EEI Q-0-Ei-P-P)* 	O 	O 	OKOOG%MNNNNN 	 	 	D	 s   4J= =%K0$	K0/K0Nc                 D   	
  j                             dd                                                                          dk    r j                            d                                            x _        d d d 
d ddt          dd f 
fddfd			d 	fd}	  | j	        j
                   d S # t          t          j        f$ r!}                     |           Y d }~d S d }~wt          $ r} j	        j        r 
	rd _        	 
d d  |t%                                 n# t          $ r Y nw xY wddlm}  ||                                          } j	                            dd|            Y d }~d S d }~ww xY w)NExpectrY   z100-continues   HTTP/1.1 100 Continue

Fdatar   c                 (   
J d            

J d            
		                      d d          \  }}n# t          $ r d}}Y nw xY wt          |          }                    ||           t	                      }	D ]B\  }}                    ||           |                    |                                           Cd|v sBd         dk    s6d|cxk    rdk     s)n |d	v s#j        d
k    rd                    dd                               dd           	                                 t          | t                    s
J d            | rrhj                            t          t          |                     dd                                                     j                            d           j                            |            rj                            d           j                                         d S )Nzwrite() before start_responser   rY   zcontent-lengthra   HEADd      >   0     HTTP/1.1TzTransfer-Encodingrs   
Connectionclosezapplications must write bytes   rF   )splitr>   r<   send_responsesetsend_headeraddr   protocol_versionend_headersr{   rP   wfilewritehexrH   encodeflush)r   code_strmsgcodeheader_keysr   r   chunk_responser   headers_sentheaders_setr   status_sent
status_sets          r   r   z*WSGIRequestHandler.run_wsgi.<locals>.write   s   JJ+JJJJKK,KKKK %#(*4$/$5$5dA$>$>MHcc! 4 4 4$/cHHH48}}""4---!ee". 1 1JC$$S%000OOCIIKK0000 )K7
E ##34>
E  4	
E 
E 
E 
E +.	
E 
E 
E 
E
  :-
E -;
E &*N$$%8)DDD   w777  """dE**KK,KKKK .! .J$$ST^^ABB%7%>%>%@%@AAAJ$$W---
  &&&! .J$$W---Js   < AAc                     |r/	 r!|d                              |d                   	 d }n# d }w xY wrt          d          | |S )Nr   r   zHeaders already set)with_tracebackAssertionError)statusr   exc_infor   r   r   r   s      r   start_responsez3WSGIRequestHandler.run_wsgi.<locals>.start_response1  sw     <$# F&qk88!EEEF  $HHtHOOOO <$%:;;;J!KLs   #, 0appr(   c                 4    |           }	 |D ]} |           s d           rj                             d           t          |d          r|                                 d S d S # t          |d          r|                                 w w xY w)Nr   s   0

r   )r   r   hasattrr   )	r   application_iterr   r   r   r   r   r   r   s	      r   executez,WSGIRequestHandler.run_wsgi.<locals>.execute?  s    "s7N;;	-,    DE$KKKK# E#JJJ! 3J$$\222+W55 -$**,,,,,- -7+W55 -$**,,,,-s   9A0 0'BTr   )DebugTracebackrw   zError on request:
N)r   r(   r   N)r   r   r   r=   r   r   r   r   rP   rV   r   ConnectionErrorsockettimeoutconnection_dropped	Exceptionpassthrough_errorsclose_connectionr   debug.tbtoolsr   render_traceback_textr   )r   r   rA   r   r   r   r   r   r   r   r   r   r   s   `    @@@@@@@@r   run_wsgizWSGIRequestHandler.run_wsgi   s   <Hb))//117799^K 	?J=>>>!%!2!2!4!44w&*
=A'+>B$7	 7	$ 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	r	 	 	 	 	 	 	 	 		- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-	BGDKO$$$$$0 	0 	0 	0##Aw///////// 	B 	B 	B{-  -> -(,%  '!%J"&K+--....    655555 .##99;;CKOOG%@3%@%@AAAAAAAAA)	BsI   6C F#C??FF%EF
EFEAFFc                 H   	 t                                                       dS # t          t          j        f$ r }|                     |           Y d}~dS d}~wt          $ r>}| j        j        &t          |          r| 
                    d|           n Y d}~dS d}~ww xY w)z/Handles a request ignoring dropped connections.NzSSL error occurred: %s)superhandler   r   r   r   r   rV   ry   is_ssl_error	log_error)r   rA   	__class__s     r   r   zWSGIRequestHandler.handlef  s    	GGNN0 	' 	' 	'##A&&&&&&&&& 	 	 	{& |A 7;;;; <;;;;;	s     % B!AB!#3BB!rw   r   c                     dS )z`Called if the connection was closed by the client.  By default
        nothing happens.
        Nr    )r   rw   r   s      r   r   z%WSGIRequestHandler.connection_droppedr  s      r   r   c                 t    |                     d          r| j        S t          t                      |          S )Ndo_)
startswithr   getattrr   )r   r   r   s     r   r   zWSGIRequestHandler.__getattr__y  s5    ??5!! 	!=  uww%%%r   c                 j    t          | dd           r| j        d         S | j        sdS | j        d         S )Nr   rg   r^   r   )r   r   rz   r5   s    r   r   z!WSGIRequestHandler.address_string  sA    4D)) 	/<.." 	9"1%%r   c                     | j         d         S )Nr   )rz   r5   s    r   r   zWSGIRequestHandler.port_integer  s    "1%%r   rl   r   sizec                    	 t          | j                  }| j         d| d| j         }n# t          $ r
 | j        }Y nw xY wt          |          }|d         dk    rt          |d          }n|dk    rnz|dk    rt          |d          }nc|d         dk    rt          |d	          }nF|d
k    rt          |d          }n/|d         dk    rt          |dd          }nt          |dd          }|                     dd|||           d S )N r   1bold200304cyan3green404yellow4redmagentainfoz
"%s" %s %s)	r   rx   r   r   r   requestliner   _ansi_styler   )r   r   r   rx   r   s        r   log_requestzWSGIRequestHandler.log_request  sK   	#di((D\AADAA4+?AACC 	# 	# 	#"CCC	# 4yy7c> 	6c6**CCU] 	6U] 		6c6**CC!W^ 	6c7++CCU] 	6c8,,CC!W^ 	6c6511CCc6955CsD$77777s   (+ ??formatargsc                 $     | j         d|g|R   d S )Nrw   r   r   r   r   s      r   r   zWSGIRequestHandler.log_error  s$    &(4((((((r   c                 $     | j         d|g|R   d S )Nr   r   r   s      r   log_messagezWSGIRequestHandler.log_message  s$    '$''''''r   typemessagec           	      |    t          ||                                  d|                                  d| dg|R   d S )Nz - - [z] 
)r
   r   log_date_time_stringr   r   r   r   s       r   r   zWSGIRequestHandler.log  sd    ""$$VVD,E,E,G,GVV7VVV	
 	
 	
 	
 	
 	
 	
r   )r   r)   r   Nr   )rl   rl   )r   r   r   rN   __annotations__propertyr   rZ   r   r   r   BaseExceptionr   Optionalr   r   r   r   r<   r   Unionr   r   r   r   __classcell__r   s   @r   rT   rT      s&        ==) ) ) ) X)
L L L L\wB wB wB wBr
 
 
 
 
 
 NR "-.Z8I-J	   & & & & & & & && & & & &&c & & & & HK8 8GCH%8347383D8	8 8 8 8:) )AE )d ) ) ) )(# (ae ( ( ( ( (
 
c 
!% 
D 
 
 
 
 
 
 
 
r   rT   r   stylesr   c                 V    t           s| S ddddddd}|D ]}d||          d	|  } |  d
S )Nr          !   #   $   )r   r   r   r   r   r   z[mz[0m)_log_add_style)r   r
  codesstyles       r   r   r     sj       E  / /.e..u..r   cn)r+   r*   c                    	 ddl m} ddlm} ddlm} ddlm} ddlm	} n# t          $ r t          d          d w xY w |            }|                    dd	|
          }| d} |                    |                    |j        d          |                    |j        |           g          } |            }|                                                    |                              |                              |                                                              |                                                              t1          j        t4          j                                                t1          j        t4          j                  t;          d          z                                 |                    |j         g          d                              |!                    |"                    |           g          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certs
             r   generate_adhoc_ssl_pairrC    sD   	%%%%%%111111@@@@@@999999AAAAAAA   J
 
	
 oG##g $  D
 
 iiw8:MNNw2B77	
 G oG!!	g			W			DOO%%	&	&	t0022	3	3		"&..	/	/	--	s0C0C0CC	D	D	t,,d.B-CDDu	U	U	t22DLL4D4D3EFFQV	W	W	dFMMOOW	-	- 	 :s   ! <	base_pathhostc           	      
   |d| d| }t          |          \  }}ddlm} |  d}|  d}t          |d	          5 }|                    |                    |j        j                             ddd           n# 1 swxY w Y   t          |d	          5 }|                    |                    |j        j        |j	        j
        |                                
                     ddd           n# 1 swxY w 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%  rH  openr   public_bytesEncodingPEMprivate_bytesPrivateFormatTraditionalOpenSSLNoEncryption)	rD  rE  r  rB  r@  rH  	cert_file	pkey_filefs	            r   make_ssl_devcertrX    s   *  #"$""D""(B///JD$<<<<<<"""I"""I	i		 ?!	!!-"8"<==>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	i		 
!	&/3$2E%2%?%?%A%A   	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 is$   3A==BBAC66C:=C:c            	         ddl } ddl}t                      \  }}ddlm} |                                 \  }}|                                 \  }}|                    t          j        |           |                    t          j        |           t          j	        ||
                    |j        j                             t          j	        ||                    |j        j        |j        j        |                                                     t          j        |           t          j        |           t%          ||          }	|	S )z:Generates an adhoc SSL context for the development server.r   NrG  rJ  )tempfileatexitrC  r%  rH  mkstempregisterosremover   rN  rO  rP  rQ  rR  rS  rT  r   load_ssl_context)
rZ  r[  rB  r@  rH  cert_handlerU  pkey_handlerV  ctxs
             r   generate_adhoc_ssl_contextrd  %  s9   OOOMMM(**JD$<<<<<<%--//K%--//K
OOBIy)))
OOBIy)))H[$++M,B,FGGHHHH"+/ .A!.!;!;!=!= 	 	
 	
   H[H[
9i
0
0CJr   rU  rV  protocolc                 v    |t           j        }t          j        |          }|                    | |           |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`.
    )r   PROTOCOL_TLS_SERVER
SSLContextload_cert_chain)rU  rV  re  rc  s       r   r`  r`  C  s>      +*
.
"
"C	9---Jr   rw   c                     | 1t          j        t          t          j                    d                   } t          | t          j                  S )z?Checks if the given error (or the current one) is an SSL error.Nr   )r   castr   r~   r   r{   r   SSLError)rw   s    r   r   r   X  s8     5y#,.."344eS\***r   portc                     |                      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)r   r   AF_UNIXr   rp  AF_INET)rE  rm  s     r   select_address_familyrs  _  sM     y!! ~	 44 >r   familyc                     |t           k    r|                     dd          d         S 	 t          j        | ||t          j        t          j                  }n# t          j        $ r | |fcY S w xY w|d         d         S )zVReturn a fully qualified socket address that can be passed to
    :func:`socket.bind`.://r   r      )af_unixr   r   getaddrinfoSOCK_STREAMIPPROTO_TCPgaierror)rE  rm  rt  ress       r   get_sockaddrr~  i  s    
  'zz%##A&& $ 2F4F
 
 ?   Tzq6!9s   ,A A,+A,c                 b   | t           j        k    rdnd}t          j         | t           j                  5 }	 |                    |df           n0# t          $ r# | t           j        k    rdndcY cddd           S w xY w|                                d         cddd           S # 1 swxY w 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   rp  
SOCK_DGRAMconnectr?   getsockname)rt  rE  ss      r   get_interface_ipr  y  s#    %+fo$=S  CSD	vv0	1	1 "Q	GIItUm$$$$ 	G 	G 	G"fo5F55;FF	" " " " " " " "	G }}q!" " " " " " " " " " " " " " " " " "s4   B$AB$A;,B$:A;;B$$B(+B(c                   L    e Zd ZdZdZdZeZd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Zde	de	dej        ddfdZddeddf fdZdej        dej        ej        e	e
f         e	f         ddf fdZddZ xZS )rU   zuA WSGI server that that handles one request at a time.

    Use :func:`make_server` to create a server instance.
    FTNrE  rm  r   r(   handlerr   ry   fdr   c                    |t           }dt          |          vr| j        s| j        rd|_        || _        || _        || _        || _        t          ||          x| _
        }t          |t          |          |          }	|t          k    rO|Mt          j        t           |	          }	t"          j                            |	          rt#          j        |	           t+                                          |	|d           |	 |                                  |                                  n9# t2          $ r}
|                                  t7          |
j        t:          j                   |
j        t>          j         k    rPt7          d| dt:          j                   t:          j!        dk    r!|d	k    rt7          d
t:          j                   t;          j"        d           Y d }
~
n}d }
~
wtF          $ r |                                   w xY w|                                  tI          j%        ||tH          j&                  | _$        | j$        '                                | _(        |t          k    r| j(        d         | _        |]tS          |tT                    r
tW          | }n|dk    rtY                      }|-                    | j$        d          | _$        || _.        d S d | _.        d S )Nr   r   F)bind_and_activate)filezPort zp is in use by another program. Either identify and stop that program, or start the server with a different port.darwini  zZOn macOS, try disabling the 'AirPlay Receiver' service from System Preferences -> Sharing.r   adhocT)server_side)/rT   varsr   r   r   rE  rm  r   r   rs  address_familyr~  r<   rx  r   rk  r   r^  rx   existsunlinkr   r3   server_bindserver_activater?   server_closeprintstrerrorr~   r   errno
EADDRINUSEplatformexitr  r   fromfdrz  r  r   r{   tupler`  rd  wrap_socketry   )r   rE  rm  r   r  r   ry   r  r  r   rA   r   s              r   r3   zBaseWSGIServer.__init__  s%     	)(G
 T']]2 	2	2 $ 1	2 (2G$		"4/DT4/P/PPn%dCII~FF W$ 	* 	*VC88Nw~~n-- *	.))) 	# 	 	
 	
 	
  %	<  """$$&&&&    !!###ajsz22227e.. ! ! ! ! !Z	    |x/ DDL C!$        !!###  !-NF<NOODK"&+"9"9";";DW$ 	/+A.DI 		$+u-- ;.<' ;8::%11$+41PPDK=HD#Ds   (D. .
H8B-G**#Hr   r   r   c                 "    t          ||g|R   d S r   r	   r  s       r   r   zBaseWSGIServer.log  s     T7"T""""""r         ?poll_intervalc                     	 t                                          |           n# t          $ r Y nw xY w|                                  d S # |                                  w xY w)N)r  )r   serve_foreverKeyboardInterruptr  )r   r  r   s     r   r  zBaseWSGIServer.serve_forever  sx    	 GG!!!>>>>  	 	 	D	 Ds!   "& A 
3A 3A A"requestrz   c                 X    | j         r t                                          ||          S r   )r   r   handle_error)r   r  rz   r   s      r   r  zBaseWSGIServer.handle_error  s-     " 	ww##G^<<<r   c                 j   d}t          |dd          }|g}| j        t          k    r|                    d| j                    n| j        dnd}| j        }| j        dv r|                    d	| j         d
           | j        dk    rd}t          t          j                  }nd}t          t          j	                  }|                    d| d| d| j
                    d|v rd| d}|                    d| d| d| j
                    t          dd                    |                     dS )z<Show information about the address when starting the server.zvWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.r   r   z * Running on Nr\   r]   >   ::0.0.0.0z * Running on all addresses ()r  r  z[::1]rv  ro  []r   r   )r   r  rx  appendrE  ry   r  r   rr  rp  rm  r
   join)r   dev_warningmessagesr|   display_hostname	localhosts         r   log_startupzBaseWSGIServer.log_startup  s|   A 	 "+vu===') 	XOO8TY889999#/DVVWF#yy-- 
U L	 L L LMMM9	) I +I'7'G'G$$ 'I'7'H'H$ S S SI S S	 S STTT&& ;#:'7#:#:#: OOVVVV8HVV49VVWWWVTYYx(()))))r   )NFNN)r  r  )r   r   r   rN   r   r   LISTEN_QUEUErequest_queue_sizeallow_reuse_addressr   r<   r   r  TyperT   rQ   _TSSLContextArgr3   r   r   floatr  r  Tupler  r  r  r	  s   @r   rU   rU     s        
 KL% ;?#(37"a$ a$a$ a$ 	a$
 AF#567a$ !a$ Z0a$ JsOa$ 
a$ a$ a$ a$ a$ a$F# #c #!% #D # # # #   5  4            =u=./gagc3h6G6L.M=	= = = = = = *  *  *  *  *  *  *  *r   rU   c                       e Zd ZdZdZdZdS )ThreadedWSGIServerzA WSGI server that handles concurrent requests in separate
    threads.

    Use :func:`make_server` to create a server instance.
    TN)r   r   r   rN   r   daemon_threadsr    r   r   r  r  /  s$          KNNNr   r  c                        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 fdZ xZS )ForkingWSGIServerzA WSGI server that handles concurrent requests in separate forked
    processes.

    Use :func:`make_server` to create a server instance.
    T(   NFrE  rm  r   r(   	processesr  r   ry   r  r   c	           	          t           st          d          t                                          |||||||           || _        d S )Nz'Your platform does not support forking.)can_forkr>   r   r3   max_children)
r   rE  rm  r   r  r  r   ry   r  r   s
            r   r3   zForkingWSGIServer.__init__C  sQ      	HFGGGtS'3E{TVWWW%r   )r  NFNN)r   r   r   rN   r   r   r<   r   r  r  rT   rQ   r  r3   r  r	  s   @r   r  r  :  s          L :>#(37"& && & 	&
 & AF#567& !& Z0& JsO& 
& & & & & & & & & &r   r  r   r(   threadedr  request_handlerr   ry   r  c	           
          |r|dk    rt          d          |rt          | ||||||          S |dk    rt          | |||||||          S t          | ||||||          S )a6  Create an appropriate WSGI server instance based on the value of
    ``threaded`` and ``processes``.

    This is called from :func:`run_simple`, but can be used separately
    to have access to the server object, such as to run it in a separate
    thread.

    See :func:`run_simple` for parameter docs.
    r   z4Cannot have a multi-thread and multi-process server.r  )r>   r  r  rU   )	rE  rm  r   r  r  r  r   ry   r  s	            r   make_serverr  U  s    (  QIM QOPPP 
!$_.@+RT
 
 
 	
 1} 

 	
 	
 	
 		
 dC*<kb   r   c                  H    t           j                            d          dk    S )zqCheck if the server is running as a subprocess within the
    Werkzeug reloader.

    .. versionadded:: 0.10
    WERKZEUG_RUN_MAINtrue)r^  r   r   r    r   r   is_running_from_reloaderr    s     :>>-..&88r   autohostnameapplicationuse_reloaderuse_debugger
use_evalexextra_filesexclude_patternsreloader_intervalreloader_typestatic_filesc                    t          |t                    st          d          |rddlm}  |||          }|rddlm}  |||          }t                      sd}nt          t          j	        d                   }t          | |||
|||||	  	        }|j                            d	           t          |                                          t          j	        d<   t                      s2|                                 t!          d
t#          dd                     |rKddlm} 	  ||j        ||||	           |                                 dS # |                                 w xY w|                                 dS )a  Start a development server for a WSGI application. Various
    optional features can be enabled.

    .. warning::

        Do not use the development server when deploying to production.
        It is intended for use only during local development. It is not
        designed to be particularly efficient, stable, or secure.

    :param hostname: The host to bind to, for example ``'localhost'``.
        Can be a domain, IPv4 or IPv6 address, or file path starting
        with ``unix://`` for a Unix socket.
    :param port: The port to bind to, for example ``8080``. Using ``0``
        tells the OS to pick a random free port.
    :param application: The WSGI application to run.
    :param use_reloader: Use a reloader process to restart the server
        process when files are changed.
    :param use_debugger: Use Werkzeug's debugger, which will show
        formatted tracebacks on unhandled exceptions.
    :param use_evalex: Make the debugger interactive. A Python terminal
        can be opened for any frame in the traceback. Some protection is
        provided by requiring a PIN, but this should never be enabled
        on a publicly visible server.
    :param extra_files: The reloader will watch these files for changes
        in addition to Python modules. For example, watch a
        configuration file.
    :param exclude_patterns: The reloader will ignore changes to any
        files matching these :mod:`fnmatch` patterns. For example,
        ignore cache files.
    :param reloader_interval: How often the reloader tries to check for
        changes.
    :param reloader_type: The reloader to use. The ``'stat'`` reloader
        is built in, but may require significant CPU to watch files. The
        ``'watchdog'`` reloader is much more efficient but requires
        installing the ``watchdog`` package first.
    :param threaded: Handle concurrent requests using threads. Cannot be
        used with ``processes``.
    :param processes: Handle concurrent requests using up to this number
        of processes. Cannot be used with ``threaded``.
    :param request_handler: Use a different
        :class:`~BaseHTTPServer.BaseHTTPRequestHandler` subclass to
        handle requests.
    :param static_files: A dict mapping URL prefixes to directories to
        serve static files from using
        :class:`~werkzeug.middleware.SharedDataMiddleware`.
    :param passthrough_errors: Don't catch unhandled exceptions at the
        server level, let the serve crash instead. If ``use_debugger``
        is enabled, the debugger will still catch such errors.
    :param ssl_context: Configure TLS to serve over HTTPS. Can be an
        :class:`ssl.SSLContext` object, a ``(cert_file, key_file)``
        tuple to create a typical context, or the string ``'adhoc'`` to
        generate a temporary self-signed certificate.

    .. versionchanged:: 2.1
        Instructions are shown for dealing with an "address already in
        use" error.

    .. versionchanged:: 2.1
        Running on ``0.0.0.0`` or ``::`` shows the loopback IP in
        addition to a real IP.

    .. versionchanged:: 2.1
        The command-line interface was removed.

    .. versionchanged:: 2.0
        Running on ``0.0.0.0`` or ``::`` shows a real IP address that
        was bound as well as a warning not to run the development server
        in production.

    .. versionchanged:: 2.0
        The ``exclude_patterns`` parameter was added.

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

    .. versionchanged:: 0.10
        Improved the reloader and added support for changing the backend
        through the ``reloader_type`` parameter.

    .. versionchanged:: 0.9
        A command-line interface was added.

    .. versionchanged:: 0.8
        ``ssl_context`` can be a tuple of paths to the certificate and
        private key files.

    .. versionchanged:: 0.6
        The ``ssl_context`` parameter was added.

    .. versionchanged:: 0.5
       The ``static_files`` and ``passthrough_errors`` parameters were
       added.
    zport must be an integerr   )SharedDataMiddleware)DebuggedApplication)evalexNWERKZEUG_SERVER_FDr  Tr   zPress CTRL+C to quitr   )run_with_reloader)r  r  intervalr  )r{   r<   r(  middleware.shared_datar  debugr  r  r^  r   r  r   set_inheritabler   filenor  r
   r   	_reloaderr  r  r  )r  rm  r  r  r  r  r  r  r  r  r  r  r  r  r   ry   r  r  r  srvr  s                        r   
run_simpler    s   ` dC   31222 F@@@@@@**;EE J......))+jIII#%% 30122

 
 
C Jt$$$'*3::<<'8'8BJ#$#%% DV[!7BBCCC 000000		!'!1*+    Cs   'E E(r   )NN)r   r'   )Fr   NFNN)FFTNNr   r  Fr   NNFN)OrN   r  ior^  r   socketserverr~   typingr   r   r5  r   r   http.serverr   r   	_internalr
   r   
exceptionsr   urlsr   r   r   r   r'  r   r  r   
__import__r   r  r%   rq  rx  r   r  r  r  r  r   r  TYPE_CHECKINGtyping_extensionste_typeshed.wsgir(   r)   -cryptography.hazmat.primitives.asymmetric.rsar*   cryptography.x509r+   	RawIOBaser-   rT   r   rC  rX  rd  r<   r`  r   rQ   r   AddressFamilyrs  r~  r  rU   ThreadingMixInr  r  r  r  r  IterableDictr  r    r   r   <module>r     s     				 				      



     # # # # # #             . . . . . . " " " " " "       + + + + + + + + + + + +                  JJJJ 	 	 	        )++CCC	 7d? 
:    72v ,LL       nGG   GGG *Gagc1:c?&:;=RRS ? .""""............      .-----; ; ; ; ;R\ ; ; ;|a
 a
 a
 a
 a
/ a
 a
 a
H	s S S    ( + +	
3+W<=+ + + +^ IM)  ) ) *S/) 67jo) WS#X)  )  )  ) X   > TX  z#ABC   *+ +
9- + + + + + 3 63G    
"("6WQWS#X#$    "V1 "c " " " "$a* a* a* a* a*Z a* a* a*H    4n   & & & & &n & & &> >B$/3* *
*
* 
* 	*
 * Z'9 :;* * O,* 	

3* * * * *Z9$ 9 9 9 9 /348>BMQ$/3!b bb
b #b 	b
 b b AJsO,b jC1b b b b b Z'9 :;b *QVCagc3h6G1G)H$HIJb b  O,!b" 
#b b b b b bs6   "A' 'BBB# #B-,B-C C&%C&