
    'g                       U d Z ddlm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 	 ddlZeej>                  ej@                  fZ!de"d<   dZ%ejL                  dk(  r		  e'd        e(ed      Z)e)rejT                  Z*n
 G d d      Z*	 ejV                  Z,dZ.ej^                  ej`                  de1e2ej^                  e2   f   ejf                  d   f      Z4ejj                  rddl6m7Z7 ddl6m8Z8 dd l9m:Z: dd!l;m<Z<  G d" d#ejz                        Z> G d$ d%e      Z?d8d&Z@	 d9	 	 	 d:d'ZA	 d;	 	 	 	 	 	 	 d<d(ZBd=d)ZC	 d;	 	 	 	 	 	 	 d>d*ZDd9d?d+ZEd@d,ZF	 	 	 	 	 	 	 	 dAd-ZGdBd.ZH G d/ d0e      ZI G d1 d2ej                  eI      ZK G d3 d4e*eI      ZL	 	 	 	 	 	 dC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dDd5ZMdEd6ZN	 	 	 	 	 	 	 	 	 	 	 	 	 dF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGd7ZOy# e#$ r#  G d d      Z$ e$       Zeej>                  fZ!Y w xY w# e#$ r dZ%Y w xY w# e-$ r dZ,Y w xY w)Ha  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
    )annotationsN)datetime)	timedelta)timezone)BaseHTTPRequestHandler)
HTTPServer)unquote)urlsplit   _log)_wsgi_encoding_dance)InternalServerError)
uri_to_iriztuple[type[Exception], ...]connection_dropped_errorsc                      e Zd ZddZy)	_SslDummyc                    t        d      )NzUSSL is unavailable because this Python runtime was not compiled with SSL/TLS support.)RuntimeError)selfnames     H/var/www/html/knws/venv/lib/python3.12/site-packages/werkzeug/serving.py__getattr__z_SslDummy.__getattr__1   s    2     Nr   strreturnt.Any)__name__
__module____qualname__r    r   r   r   r   0   s    	r   r   TntcoloramaFforkc                      e Zd Zy)ForkingMixInN)r   r    r!   r"   r   r   r'   r'   H   s    r   r'      ssl.SSLContextadhoc)WSGIApplication)WSGIEnvironment)RSAPrivateKeyWithSerialization)Certificatec                  0    e Zd ZdZddZddZd	dZd
dZy)DechunkedInputz8An input stream that handles Transfer-Encoding 'chunked'c                .    || _         d| _        d| _        y )NFr   )_rfile_done_len)r   rfiles     r   __init__zDechunkedInput.__init__c   s    
	r   c                     y)NTr"   r   s    r   readablezDechunkedInput.readableh   s    r   c                    	 | j                   j                         j                  d      }t        |j	                         d      }|dk  rt        d      |S # t
        $ r}t        d      |d }~ww xY w)Nlatin1   zInvalid chunk headerr   z!Negative chunk length not allowed)r2   readlinedecodeintstrip
ValueErrorOSError)r   liner4   es       r   read_chunk_lenzDechunkedInput.read_chunk_lenk   sp    	9;;'')00:Dtzz|R(D !8=>>	  	901q8	9s   AA 	A1 A,,A1c                    d}| j                   sn|t        |      k  r_| j                  dk(  r| j                         | _        | j                  dk(  rd| _         | j                  dkD  rt	        t        |      | j                        }||z   t        |      kD  rW| j
                  j                  t        |      |z
        ||d  | xj                  t        |      |z
  z  c_        t        |      }n;| j
                  j                  |      ||||z    | xj                  |z  c_        ||z  }| j                  dk(  r)| j
                  j                         }|dvrt        d      | j                   s|t        |      k  r_|S )Nr   T)   
   
   z!Missing chunk terminating newline)	r3   lenr4   rE   minr2   readr=   rB   )r   bufrL   n
terminators        r   readintozDechunkedInput.readintou   sB   **CyyA~ !//1	yyA~ "
yy1} C$)),
 !8c#h&!%!1!1#c(T/!BCJIISD0Is8D+/;;+;+;A+>Ctax(IINIAIDyyA~ "[[113
%<<!"EFFE **CH r   N)r5   zt.IO[bytes]r   Noner   boolr   r?   )rM   	bytearrayr   r?   )r   r    r!   __doc__r6   r9   rE   rP   r"   r   r   r0   r0   `   s    B
&r   r0   c            
      6   e Zd ZU dZded<   edd       ZddZddZdfdZ		 d	 	 	 	 	 ddZ
dfd	Zdd
ZddZej                  g  ed       edd      D  ci c]	  }|d|d c}}       Zde ed      <   dddZd dZd dZd!dZxZS c c}} w )"WSGIRequestHandlerz3A request handler that implements WSGI dispatching.BaseWSGIServerserverc                .    | j                   j                  S N)rZ   _server_versionr8   s    r   server_versionz!WSGIRequestHandler.server_version   s    {{***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| j)                         d| j+                         | j                  j,                  d   t        | j                  j,                  d         | j.                  d}| j0                  j3                         D ]X  \  }}d|v r|j5                         j7                  dd      }|j7                  dd      }|dvrd | }||v r
||    d!| }|||<   Z |j9                  d"d      j;                         j=                         d#k(  rd$|d%<   t?        |d	         |d	<   |j                  r|j                  r|j                  |d&<   	 | j                  jA                  d$'      }|tC        jD                  |      |d(<   |S # tF        $ r  | j                  jI                  d)d*       Y |S tJ        $ r Y |S w xY w)+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_NAME 	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
   pathrZ   ssl_contextclient_address
isinstancer   schemenetlocr	   r5   sysstderrmultithreadmultiprocess
connectionr^   commandr   queryaddress_stringport_integerserver_addressrequest_versionheadersitemsupperreplacegetr@   lowerr0   getpeercertsslDER_cert_to_PEM_certrA   logAttributeError)r   request_url
url_scheme	path_infoenvironkeyvalue	peer_certs           r   make_environzWSGIRequestHandler.make_environ   s   tyy)#{{66>VG
"""0D++S1#'#6#6":D
 !!k&8&8K../0@0@/ABI#((II&	$
F$
z$
 $**$
 3::	$

  7 7$
  !9!9$
 U$
 t$
 t22$
 dll$
 2$
 -i8$
 01B1BC$
 /		:$
" +DII6#$
$ 4..0%$
& 4,,.'$
(  ;;55a8t{{99!<=#33-$
2 ,,,,. 
	!JCcz))+%%c3/CMM&"-E<<cUm'>&s|nAeW5E GCL
	! ;;/4::<BBD	Q/3G+,$27<3H$IGL! +"4"4#.#5#5GK 	 333EI$-0-E-Ei-P)*   	OKKOOG%MN
 	  			s   6L %M8MMc                   	
  j                   j                  dd      j                         j                         dk(  r j                  j                  d        j                         x _        d d d 
d dd 
fddfd		d 	fd}	  | j                  j                         y # t        $ r} j                  |       Y d }~y 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%                         } j                  j'                  dd|        Y d }~y d }~ww xY w)NExpectrg   z100-continues   HTTP/1.1 100 Continue

Fc                   J d       
J d       މ
		 j                  d d      \  }}t        |      }j                  ||       t	               }	D ]6  \  }}j                  ||       |j                  |j                                8 d|v s<d   dk(  s4d|cxk  rdk  s)n |d	v s#j                  d
k\  rdj                  dd       j                  dd       j                          t        | t              sJ d       | rrYj                  j                  t        t        |             dd  j!                                j                  j                  d       j                  j                  |        rj                  j                  d       j                  j#                          y # t        $ r d}}Y w xY w)Nzwrite() before start_responser   rg   zcontent-lengthre   HEADd      >   0     HTTP/1.1TzTransfer-Encodingrx   
Connectionclosezapplications must write bytes   rH   )splitrA   r?   send_responsesetsend_headeraddr   protocol_versionend_headersr   byteswfilewritehexrJ   encodeflush)data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)*K,KK*"(*4$/$5$5dA$>MHc 8}""4-!e". 1JC$$S%0OOCIIK01 )K7"#34>4-#-:---;%)N$$%8)D   w7  "dE*K,KK*!JJ$$ST^AB%7%>%>%@AJJ$$W-

  &!JJ$$W-JJ] " 4$/cH4s   F; ;GGc                x    |r	 r|d   j                  |d         	 d }nrt        d      | |S # d }w xY w)Nr   r   zHeaders already set)with_tracebackAssertionError)statusr   exc_infor   r   r   r   s      r   start_responsez3WSGIRequestHandler.run_wsgi.<locals>.start_response<  sZ    $#&qk88!EE $  $H$%:;;J!KL  $Hs   5 9c                    | 
      }	 |D ]
  } |        s d       r	j                   j                  d       t        j                         }|j	                  	j
                  t        j                         d}d}|j                  d      rN	j                  j                  d      }|t        |      z  }|dz  }|r
|dk\  s|d	kD  rn|j                  d      rN|j                          t        |d
      r|j                          y y # t        j                         }|j	                  	j
                  t        j                         d}d}|j                  d      rN	j                  j                  d      }|t        |      z  }|dz  }|r
|dk\  s|d	kD  rn|j                  d      rN|j                          t        |d
      r|j                          w w xY w)Nr   s   0

r   g{Gz?)timeouti r   l    d(	 i  r   )r   r   	selectorsDefaultSelectorregisterr   
EVENT_READselectr5   rL   rJ   r   hasattr)appapplication_iterr   selector
total_sizetotal_readsr   r   r   r   r   r   s         r   executez,WSGIRequestHandler.run_wsgi.<locals>.executeJ  s   "7N;#-,  D$K ##J!JJ$$\2 %446!!$//93G3GH
 oodo3::??:6D#d)+J1$K  :#?;QUCU oodo3  +W5$**, 6) %446!!$//93G3GH
 oodo3::??:6D#d)+J1$K  :#?;QUCU oodo3  +W5$**, 6s   6D B"G#5.G#Tr   )DebugTracebackr|   zError on request:
)r   r   r   rQ   r\   )r   r+   r   rQ   )r   r   r   r@   r   r   r   r   rZ   r   r   connection_dropped	Exceptionpassthrough_errorsclose_connectionr   debug.tbtoolsr   render_traceback_textr   )r   r   rD   r   r   r   r   r   r   r   r   r   r   s   `    @@@@@@@@r   run_wsgizWSGIRequestHandler.run_wsgi   s^   <<Hb)//1779^KJJ=>!%!2!2!44w!%
48"&59$7	 7	r	 	%	- %	-N	BDKKOO$( 	0##Aw// 	B{{--&>(,% &!%J"&K+-.  6 #99;CKKOOG':3%%@AA)	BsH   "B? ?	E9CE9+"E4D%$E4%	D1.E40D11>E44E9c                   	 t         |           y# t        t        j                  f$ r}| j                  |       Y d}~yd}~wt        $ r?}| j                  j                  t        |      r| j                  d|       n Y d}~yd}~ww xY w)z/Handles a request ignoring dropped connections.NzSSL error occurred: %s)superhandleConnectionErrorsocketr   r   r   rZ   r~   is_ssl_error	log_error)r   rD   	__class__s     r   r   zWSGIRequestHandler.handle  sr    	GN0 	'##A&& 	{{&&2|A7; <	s     BAB5BBc                     y)z`Called if the connection was closed by the client.  By default
        nothing happens.
        Nr"   )r   r|   r   s      r   r   z%WSGIRequestHandler.connection_dropped  s    r   c                f    |j                  d      r| j                  S t        t               |      S )Ndo_)
startswithr   getattrr   )r   r   r   s     r   r   zWSGIRequestHandler.__getattr__  s*    ??5!==  uw%%r   c                r    t        | dd       r| j                  d   S | j                  sy| j                  d   S )Nr   rl   rb   r   )r   r   r   r8   s    r   r   z!WSGIRequestHandler.address_string  s:    4D)<<..""""1%%r   c                     | j                   d   S )Nr   )r   r8   s    r   r   zWSGIRequestHandler.port_integer  s    ""1%%r             z\x02xz\\\c                   	 t        | j                        }| j                   d| d| j                   }|j                  | j                        }t        |      }|d   dk(  rt        |d      }nb|dk(  rn\|dk(  rt        |d      }nJ|d   dk(  rt        |d	      }n5|d
k(  rt        |d      }n#|d   dk(  rt        |dd      }nt        |dd      }| j                  dd|||       y # t        $ r | j
                  }Y w xY w)N r   1bold200304cyan3green404yellow4redmagentainfoz
"%s" %s %s)r   r}   r   r   r   requestline	translate_control_char_tabler   _ansi_styler   )r   r   sizer}   r   s        r   log_requestzWSGIRequestHandler.log_request  s
   	#dii(D\\N!D64+?+?*@AC mmD4454y7c>c6*CU]U]c6*C!W^c7+CU]c8,C!W^c651Cc695CsD$7/  	#""C	#s   3C( (D ?D c                ,     | j                   d|g|  y )Nr|   r   r   formatargss      r   r   zWSGIRequestHandler.log_error  s    &(4(r   c                ,     | j                   d|g|  y )Nr  r
  r  s      r   log_messagezWSGIRequestHandler.log_message  s    '$'r   c           	         | j                         j                  dd      }t        || d| j                          d| dg|  y )N%z%%z - - [z] 
)r   r   r   log_date_time_string)r   typemessager  r   s        r   r   zWSGIRequestHandler.log  sS    ,,.66sDAfT%>%>%@$AG9BO	
 	
r   )r   r   )r   r,   r   rQ   r\   )r|   BaseExceptionr   zWSGIEnvironment | Noner   rQ   r   rT   )rr   rr   )r   	int | strr  r  r   rQ   )r  r   r  r   r   rQ   r  r   r  r   r  r   r   rQ   )r   r    r!   rV   __annotations__propertyr^   r   r   r   r   r   r   r   r   	maketransranger  ordr  r   r  r   __classcell__).0cr   s   00@r   rX   rX      s    =+ +ObQBf
 GK"-C	&&& --#EU4[#E5t3D#EFar!CM	F &+D	"8:)(
O 	Gs   B
rX   c                R    t         s| S ddddddd}|D ]  }d||    d	|  }  |  d
S )Nr      r   !   #   $   )r   r   r   r   r  r   z[mz[0m)_log_add_style)r   stylescodesstyles       r   r  r    s[     E  /e~Qug./ WGr   c           	        	 ddl m} ddlm} ddlm} ddlm} ddlm	}  |       }|j                  dd	|
      }| d} |j                  |j                  |j                  d      |j                  |j                   |       g      } |       }|j#                         j%                  |      j'                  |      j)                  |j)                               j+                  |j-                               j/                  t1        j2                  t4        j6                              j9                  t1        j2                  t4        j6                        t;        d      z         j=                  |j?                  |j@                  g      d      j=                  |jC                  |jE                  |       |jE                  d|        g      d      jG                  ||jI                         |      }	|	|fS # t        $ r t        d      d w xY w)Nr   )x509)default_backend)hashes)rsa)NameOIDz<Using ad-hoc certificates requires the cryptography library.i  i   )public_exponentkey_sizebackend*zDummy Certificateim  )daysF)criticalz*.)%cryptographyr-  cryptography.hazmat.backendsr.  cryptography.hazmat.primitivesr/  )cryptography.hazmat.primitives.asymmetricr0  cryptography.x509.oidr1  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)
cnr-  r.  r/  r0  r1  r4  pkeysubjectcerts
             r   generate_adhoc_ssl_pairrZ    s   	%@9A1 G##g $ D
 
ziiw88:MNw22B7	
G G!	g		W		DOO%	&	t002	3		"&&.	/	-	s0CC	D	t,,d.B.B-CDu	U	''b)94<<"RD	;R(ST 
 

 
dFMMOW	- 	 :K  J
	s   G3 3H	c           	        ||}t        |      \  }}ddlm} |  d}|  d}t        |d      5 }|j	                  |j                  |j                  j                               ddd       t        |d      5 }|j	                  |j                  |j                  j                  |j                  j                  |j                                      ddd       ||fS # 1 sw Y   {xY w# 1 sw Y   ||fS xY w)	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.
    N)rV  r   serializationz.crtz.keywbencodingr  encryption_algorithm)rZ  r:  r]  openr   public_bytesEncodingPEMprivate_bytesPrivateFormatTraditionalOpenSSLNoEncryption)		base_pathhostrV  rY  rW  r]  	cert_file	pkey_filefs	            r   make_ssl_devcertro  )  s    * (B/JD$<+T"I+T"I	i	 ?!	!!-"8"8"<"<=>?	i	 
!	&//33$22EE%2%?%?%A  	

 i? ?
 is   5C9AC+C(+C7c            	        ddl } ddl}t               \  }}ddlm} |j                         \  }}|j                         \  }}| j                  t        j                  |       | j                  t        j                  |       t        j                  ||j                  |j                  j                               t        j                  ||j                  |j                  j                  |j                  j                  |j!                                      t        j"                  |       t        j"                  |       t%        ||      }	|	S )z:Generates an adhoc SSL context for the development server.r   Nr\  r_  )atexittempfilerZ  r:  r]  mkstempr   osremover   rc  rd  re  rf  rg  rh  ri  r   load_ssl_context)
rq  rr  rY  rW  r]  cert_handlerl  pkey_handlerm  ctxs
             r   generate_adhoc_ssl_contextrz  U  s    (*JD$<%--/K%--/K
OOBIIy)
OOBIIy)HH[$++M,B,B,F,FGHHH"++// ..AA!.!;!;!= 	 	
 HH[HH[
9i
0CJr   c                x    |t         j                  }t        j                  |      }|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)rl  rm  protocolry  s       r   rv  rv  s  s8     **
..
"C	9-Jr   c                    | /t        j                  t        t        j                         d         } t        | t        j                        S )z?Checks if the given error (or the current one) is an SSL error.r   )tcastr   r   r   r   r   SSLError)r|   s    r   r   r     s3    }y#,,."34eS\\**r   c                    | j                  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   r  AF_INET)rk  ports     r   select_address_familyr    s>     y!~~	4>>r   c                ,   |t         k(  r1t        j                  j                  | j	                  d      d         S 	 t        j                  | ||t
        j                  t
        j                        }|d   d   S # t
        j                  $ r | |fcY S w xY w)zVReturn a fully qualified socket address that can be passed to
    :func:`socket.bind`.://r   r      )
af_unixrt  r}   abspath	partitionr   getaddrinfoSOCK_STREAMIPPROTO_TCPgaierror)rk  r  familyress       r   get_sockaddrr    s    
 wwt~~e4Q788  $ 2 2F4F4F

 q6!9 ?? Tzs   5A9 9BBc                P   | t         j                  k(  rdnd}t        j                   | t         j                        5 }	 |j                  |df       |j                         d   cddd       S # t        $ r# | t         j                  k(  rdndcY cddd       S w xY w# 1 sw Y   yxY w)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   r  
SOCK_DGRAMconnectrB   getsockname)r  rk  ss      r   get_interface_ipr    s     %+foo$= CSD	vv00	1 "Q	GIItUm$ }}q!" "  	G"foo55;F	" "	G" "s.   BA-B- BBBBB%c                       e Zd ZdZdZdZeZdZ	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
 fdZ	ddZ
dd fdZ	 	 	 	 	 	 d fdZddZ xZS )rY   zuA WSGI server that that handles one request at a time.

    Use :func:`make_server` to create a server instance.
    FTc                   |t         }dt        |      vr| j                  s| j                  rd|_        || _        || _        || _        || _        t        ||      x| _
        }t        |t        |      |      }	|t        k(  rP|Nt        j                  t         |	      }	t"        j$                  j'                  |	      rt#        j(                  |	       t*        | Y  |	|d       |"	 | j/                          | j1                          nY| j5                          tI        jJ                  ||tH        jL                        | _$        | jH                  jO                         | _(        |t        k7  r| jP                  d   | _        |RtS        |tT              r	tW        | }n|dk(  r
tY               }|j[                  | jH                  d      | _$        || _.        nd | _.        dd l/}d|j`                  jc                  d       | _2        y # t2        $ r}
| j5                          t7        |
j8                  t:        j<                         |
j>                  t>        j@                  k(  rRt7        d| dt:        j<                         t:        jB                  dk(  r |d	k(  rt7        d
t:        j<                         t;        jD                  d       Y d }
~
hd }
~
wtF        $ r | j5                           w xY w)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  zoOn macOS, try disabling the 'AirPlay Receiver' service from System Preferences -> General -> AirDrop & Handoff.r   r*   T)server_sider   z	Werkzeug/werkzeug)3rX   varsr   r   r   rk  r  r   r   r  address_familyr  r?   r  r  r  r   rt  r}   existsunlinkr   r6   server_bindserver_activaterB   server_closeprintstrerrorr   r   errno
EADDRINUSEplatformexitr  r   fromfdr  r  r   r   tuplerv  rz  wrap_socketr~   importlib.metadatametadataversionr]   )r   rk  r  r   handlerr   r~   fdr  r   rD   	importlibr   s               r   r6   zBaseWSGIServer.__init__  s|    ?(G
 T']2 1 1'1G$		"4/DT4/PPn%dCI~F W$VVC8Nww~~n-		.) 	# 	 	
 :  "$$&:  !--NF<N<NODK"&++"9"9";DW$++A.DI"+u-.<'8:%11$++41PDK6AD#D!!*9+=+=+E+Ej+Q*RSg   !!#ajjszz277e...v &! ! !ZZ	 ||x/DDLX!$   !!#s   ) H 	K)B9KK)c                    t        ||g|  y r\   r   )r   r  r  r  s       r   r   zBaseWSGIServer.log.  s    T7"T"r   c                    	 t         |   |       | j                          y # t        $ r Y w xY w# | j                          w xY w)N)poll_interval)r   serve_foreverKeyboardInterruptr  )r   r  r   s     r   r  zBaseWSGIServer.serve_forever1  sI    	 G!!>  ! 		 s   $ 	03 03 Ac                >    | j                   r t        | 	  ||      S r\   )r   r   handle_error)r   requestr   r   s      r   r  zBaseWSGIServer.handle_error9  s#     ""w#G^<<r   c                   d}t        |dd      }|g}| j                  t        k(  r|j                  d| j                          n| j
                  dnd}| j                  }| j                  dv r|j                  d	| j                   d
       | j                  dk(  rd}t        t        j                        }nd}t        t        j                        }|j                  d| d| d| j                          d|v rd| d}|j                  d| d| d| j                          t        ddj                  |             y)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`   ra   >   ::0.0.0.0z * Running on all addresses ()r  r  z[::1]r  r  []r  r  )r  r  r  appendrk  r~   r  r   r  r  r  r   join)r   dev_warningmessagesr   display_hostname	localhosts         r   log_startupzBaseWSGIServer.log_startupA  s5   A 	 "+vu==')OOnTYYK89#//7VWF#yyyy--"?		{! LM99	) +I'7'G$ 'I'7'H$.I;a		{ ST&&%&'7&8#: OOnVHC8H7I499+VWVTYYx()r   )NFNN)rk  r   r  r?   r   r+   r  type[WSGIRequestHandler] | Noner   rS   r~   _TSSLContextArg | Noner  
int | Noner   rQ   r  )g      ?)r  floatr   rQ   )r  r   r   tuple[str, int] | strr   rQ   r  )r   r    r!   rV   r   r   LISTEN_QUEUErequest_queue_sizeallow_reuse_addressr6   r   r  r  r  r  r   s   @r   rY   rY     s    
 KL% 48#(.2eTeT eT 	eT
 1eT !eT ,eT eT 
eTN# ==.C=	= *r   rY   c                      e Zd ZdZdZdZy)ThreadedWSGIServerzA WSGI server that handles concurrent requests in separate
    threads.

    Use :func:`make_server` to create a server instance.
    TN)r   r    r!   rV   r   daemon_threadsr"   r   r   r  r  d  s     KNr   r  c                  V     e Zd ZdZdZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d 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.
    Tc	           	     `    t         st        d      t        	|   |||||||       || _        y )Nz'Your platform does not support forking.)can_forkrA   r   r6   max_children)
r   rk  r  r   	processesr  r   r~   r  r   s
            r   r6   zForkingWSGIServer.__init__x  s7     FGGtS'3E{TVW%r   )(   NFNN)rk  r   r  r?   r   r+   r  r?   r  r  r   rS   r~   r  r  r  r   rQ   )r   r    r!   rV   r   r6   r  r  s   @r   r  r  o  s     L 37#(.2&& & 	&
 & 1& !& ,& & 
& &r   r  c	           
         |r|dkD  rt        d      |rt        | ||||||      S |dkD  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  )rA   r  r  rY   )	rk  r  r   threadedr  request_handlerr   r~   r  s	            r   make_serverr    s    ( IMOPP!$_.@+RT
 	
 1} 	
 		
 dC*<kb r   c                 F    t         j                  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)rt  r   r   r"   r   r   is_running_from_reloaderr    s     ::>>-.&88r   c                   t        |t              st        d      |rddlm}  |||      }|r+ddlm}  |||      }|j                  j                  |        t               sd}nt        t        j                  d         }t        | |||
|||||	      }|j                  j                  d	       t        |j!                               t        j                  d<   t               s&|j#                          t%        d
t'        dd             |r/ddlm} 	  ||j,                  ||||	       |j/                          y|j-                          y# |j/                          w xY w)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 server 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)extra_filesexclude_patternsintervalreloader_type)r   r?   r>  middleware.shared_datar  debugr  trusted_hostsr  r  rt  r   r  r   set_inheritabler   filenor  r   r  	_reloaderr  r  r  )hostnamer  applicationuse_reloaderuse_debugger
use_evalexr  r  reloader_intervalr  r  r  r  static_filesr   r~   r  r  r  srvr  s                        r   
run_simpler    s;   ` dC 122@*;E.)+jI 	!!((2#%012

C JJt$'*3::<'8BJJ#$#%V[!7BC0		!!'!1*+  s   E E )r   r   r)  r   r   r   r\   )rV  
str | Noner   z2tuple[Certificate, RSAPrivateKeyWithSerialization])NN)rj  r   rk  r  rV  r  r   ztuple[str, str])r   r)   )rl  r   rm  r  r  r  r   r)   )r|   zException | Noner   rS   )rk  r   r  r?   r   socket.AddressFamily)rk  r   r  r?   r  r  r   r  )r  r  r   r   )Fr   NFNN)rk  r   r  r?   r   r+   r  rS   r  r?   r  r  r   rS   r~   r  r  r  r   rY   rR   )FFTNNr   autoFr   NNFN)"r  r   r  r?   r  r+   r  rS   r   rS   r  rS   r  t.Iterable[str] | Noner  r	  r  r?   r  r   r  rS   r  r?   r  r  r  z'dict[str, str | tuple[str, str]] | Noner   rS   r~   r  r   rQ   )PrV   
__future__r   r  iort  r   r   socketserverr   typingr  r   rK  r   r   http.serverr   r   urllib.parser	   r
   	_internalr   r   
exceptionsr   urlsr   r   r   r   SSLEOFErrorr   r  r=  r   r(  r   
__import__r   r  r'   r  r  r   r  OptionalUnionr  r   Literal_TSSLContextArgTYPE_CHECKING_typeshed.wsgir+   r,   -cryptography.hazmat.primitives.asymmetric.rsar-   cryptography.x509r.   	RawIOBaser0   rX   r  rZ  ro  rz  rv  r   r  r  r  rY   ThreadingMixInr  r  r  r  r  r"   r   r   <module>r     s   #  	 	    
  #   . "   !  + + B 	>: " 77d?: 2v,,L nnG **GGeCC$89199W;MMN ??.. .;R\\ ;|D
/ D
N
( ..7.d ?C) ) $) 1;) ) X> JN)<F*+
"6""$e*Z e*P44n &n &> 7;$*.*
*
* 
* 	*
 * 5* * (* 	* *Z9 *./37;<@$*.!ee
e !e 	e
 e e (e -e e e e e 5e :e e  (!e" 
#ee  
B  +C!0&.. A
B"    Gs6   -"H# !I I #$I
IIII'&I'