
    +h8                       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dZ ejB                  dk(  r		  e"d        e#ed      Z$e$rejJ                  Z%n
 G d d      Z%	 ejL                  Z'dZ)ejT                  ejV                  dejX                  e-ejT                  e-   f   ej\                  d   f      Z/ej`                  rddl1m2Z2 ddl1m3Z3 ddl4m5Z5 ddl6m7Z7  G d  d!ejp                        Z9 G d" d#e      Z:d6d$Z;	 d7	 	 	 d8d%Z<	 d9	 	 	 	 	 	 	 d:d&Z=d;d'Z>	 d9	 	 	 	 	 	 	 d<d(Z?d7d=d)Z@d>d*ZA	 	 	 	 	 	 	 	 d?d+ZBd@d,ZC G d- d.e      ZD G d/ d0ej                  eD      ZF G d1 d2e%eD      ZG	 	 	 	 	 	 dA	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dBd3ZHdCd4ZI	 	 	 	 	 	 	 	 	 	 	 	 	 dD	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dEd5ZJy# e$ r  G d d      Z e       ZY w xY w# e$ r dZ Y w xY w# e($ r dZ'Y w xY w)Fa  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_iric                      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     C/var/www/html/venv/lib/python3.12/site-packages/werkzeug/serving.py__getattr__z_SslDummy.__getattr__*   s    2     Nr   strreturnt.Any)__name__
__module____qualname__r    r   r   r   r   )   s    	r   r   TntcoloramaFforkc                      e Zd Zy)ForkingMixInN)r   r   r    r!   r   r   r&   r&   @   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__[   s    
	r   c                     y)NTr!   r   s    r   readablezDechunkedInput.readable`   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)r1   readlinedecodeintstrip
ValueErrorOSError)r   liner3   es       r   read_chunk_lenzDechunkedInput.read_chunk_lenc   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)	r2   lenr3   rD   minr1   readr<   rA   )r   bufrK   n
terminators        r   readintozDechunkedInput.readintom   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)r4   zt.IO[bytes]r   Noner   boolr   r>   )rL   	bytearrayr   r>   )r   r   r    __doc__r5   r8   rD   rO   r!   r   r   r/   r/   X   s    B
&r   r/   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                    ddl m} d| S )Nr   )__version__z	Werkzeug/) r[   )r   r[   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_NAMEr\   	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
   pathrY   ssl_contextclient_address
isinstancer   schemenetlocr	   r4   sysstderrmultithreadmultiprocess
connectionr]   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   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        t        j                  f$ 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Expectr\   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   r\   zcontent-lengthrd   HEADd      >   0     HTTP/1.1TzTransfer-Encodingrv   
Connectionclosezapplications must write bytes   rG   )splitr@   r>   send_responsesetsend_headeraddr   protocol_versionend_headersr~   byteswfilewritehexrI   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_response6  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selectr4   rK   rI   r   hasattr)appapplication_iterr   selector
total_sizetotal_readsr   r   r   r   r   r   s         r   executez,WSGIRequestHandler.run_wsgi.<locals>.executeD  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   )DebugTracebackrz   zError on request:
)r   r   r   rP   N)r   r*   r   rP   )r   r   r   r?   r   r   r   r   rY   r   ConnectionErrorsocketr   connection_dropped	Exceptionpassthrough_errorsclose_connectionr   debug.tbtoolsr   render_traceback_textr   )r   r   rC   r   r   r   r   r   r   r   r   r   r   s   `    @@@@@@@@r   run_wsgizWSGIRequestHandler.run_wsgi   sg   <<Hb)//1779^KJJ=>!%!2!2!44w!%
48"&59$7	 7	r	 	%	- %	-N	BDKKOO$0 	0##Aw// 	B{{--&>(,% &!%J"&K+-.  6 #99;CKKOOG':3%%@AA)	BsH   "B? ?F	C//F	;"FD54F5	E>F E>FF	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handler   r   r   r   r   rY   r|   is_ssl_error	log_error)r   rC   	__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   rz   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   rj   ra   r   )r   r   r}   r7   s    r   r   z!WSGIRequestHandler.address_string  s:    4D)<<..""""1%%r   c                     | j                   d   S )Nr   )r}   r7   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 )Nrz   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           	     h    t        || j                          d| j                          d| dg|  y )Nz - - [z] 
)r   r   log_date_time_stringr   typemessager  s       r   r   zWSGIRequestHandler.log  sB    ""$%VD,E,E,G+H7)SUV	
 	
r   )r   r   )r   r+   r   rP   r   )rz   BaseExceptionr   zWSGIEnvironment | Noner   rP   r   rS   )rp   rp   )r   	int | strr  r  r   rP   )r  r   r  r   r   rP   r  r   r  r   r  r   r   rP   )r   r   r    rU   __annotations__propertyr]   r   r   r   r   r   r   r   r   	maketransranger  ordr  r   r  r   __classcell__).0cr   s   00@r   rW   rW      s    =) )
ObQBf
 GK"-C	&&& --#EU4[#E5t3D#EFar!CM	F &+D	"8:)(
O 	Gs   B
rW   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                  |       g      d      jG                  ||jI                         |      }	|	|fS # t        $ r t        d      d w xY w)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.asymmetricr0  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.  r/  r0  r3  pkeysubjectcerts
             r   generate_adhoc_ssl_pairrY    s   	%1@9A 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	t22DLL4D3EFQV	W	dFMMOW	- 	 :E  J
	s   G   G6c           	         |d| d| }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.
    Nz*.z/CN=)rU  r   serializationz.crtz.keywbencodingr  encryption_algorithm)rY  r:  r\  openr   public_bytesEncodingPEMprivate_bytesPrivateFormatTraditionalOpenSSLNoEncryption)		base_pathhostrU  rX  rV  r\  	cert_file	pkey_filefs	            r   make_ssl_devcertrn    s   * $tD6"(B/JD$<+T"I+T"I	i	 ?!	!!-"8"8"<"<=>?	i	 
!	&//33$22EE%2%?%?%A  	

 i? ?
 is   5C%?AC1%C.1C=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^  )tempfileatexitrY  r:  r\  mkstempr   osremover   rb  rc  rd  re  rf  rg  rh  r   load_ssl_context)
rp  rq  rX  rV  r\  cert_handlerk  pkey_handlerl  ctxs
             r   generate_adhoc_ssl_contextry  J  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)rk  rl  protocolrx  s       r   ru  ru  h  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)rz   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)rj  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_unixrs  r{   abspath	partitionr   getaddrinfoSOCK_STREAMIPPROTO_TCPgaierror)rj  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connectrA   getsockname)r  rj  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 )rX   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      | _$        || _.        y d | _.        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 }
~
Ad }
~
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  zZOn macOS, try disabling the 'AirPlay Receiver' service from System Preferences -> Sharing.r   r)   T)server_side)/rW   varsr   r   r   rj  r  r   r   r  address_familyr  r>   r  r  r  r   rs  r{   existsunlinkr   r5   server_bindserver_activaterA   server_closeprintstrerrorr   r   errno
EADDRINUSEplatformexitr  r   fromfdr  r  r   r~   tupleru  ry  wrap_socketr|   )r   rj  r  r   handlerr   r|   fdr  r   rC   r   s              r   r5   zBaseWSGIServer.__init__  sX    ?(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_   !!#ajjszz277e...v &! ! !ZZ	 ||x/DDLC!$   !!#s   ) G 	K%B9J$$Kc                    t        ||g|  y 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_forever"  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_error*  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_   r`   >   ::0.0.0.0z * Running on all addresses ()r  r  z[::1]r  r  []r  r  )r  r  r  appendrj  r|   r  r   r  r  r  r   join)r   dev_warningmessagesr   display_hostname	localhosts         r   log_startupzBaseWSGIServer.log_startup2  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)rj  r   r  r>   r   r*   r  type[WSGIRequestHandler] | Noner   rR   r|   _TSSLContextArg | Noner  
int | Noner   rP   r  )g      ?)r  floatr   rP   )r  r   r}   tuple[str, int] | strr   rP   r  )r   r   r    rU   r   r   LISTEN_QUEUErequest_queue_sizeallow_reuse_addressr5   r   r  r  r  r  r   s   @r   rX   rX     s    
 KL% 48#(.2a$a$ a$ 	a$
 1a$ !a$ ,a$ a$ 
a$F# ==.C=	= *r   rX   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    rU   r   daemon_threadsr!   r   r   r  r  U  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_forkr@   r   r5   max_children)
r   rj  r  r   	processesr  r   r|   r  r   s
            r   r5   zForkingWSGIServer.__init__i  s7     FGGtS'3E{TVW%r   )(   NFNN)rj  r   r  r>   r   r*   r  r>   r  r  r   rR   r|   r  r  r  r   rP   )r   r   r    rU   r   r5   r  r  s   @r   r  r  `  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  )r@   r  r  rX   )	rj  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)rs  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}  |||      }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  r  rs  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#%012

C JJt$'*3::<'8BJJ#$#%V[!7BC0		!!'!1*+  s   :D3 3E)r   r   r(  r   r   r   r   )rU  
str | Noner   z2tuple[Certificate, RSAPrivateKeyWithSerialization])NN)ri  r   rj  r  rU  r  r   ztuple[str, str])r   r(   )rk  r   rl  r  r~  r  r   r(   )rz   zException | Noner   rR   )rj  r   r  r>   r   socket.AddressFamily)rj  r   r  r>   r  r   r   r  )r  r   r   r   )Fr   NFNN)rj  r   r  r>   r   r*   r  rR   r  r>   r  r  r   rR   r|   r  r  r  r   rX   rQ   )FFTNNr   autoFr   NNFN)"r  r   r  r>   r  r*   r  rR   r  rR   r  rR   r  t.Iterable[str] | Noner  r  r  r>   r  r   r  rR   r  r>   r  r  r  z'dict[str, str | tuple[str, str]] | Noner   rR   r|   r  r   rP   )KrU   
__future__r   r  iors  r   r   socketserverr   typingr  r   rJ  r   r   http.serverr   r   urllib.parser	   r
   	_internalr   r   
exceptionsr   urlsr   r   r<  r   r'  r   
__import__r   r  r&   r  r  r   r  OptionalUnionTupler   Literal_TSSLContextArgTYPE_CHECKING_typeshed.wsgir*   r+   -cryptography.hazmat.primitives.asymmetric.rsar,   cryptography.x509r-   	RawIOBaser/   rW   r  rY  rn  ry  ru  r   r  r  r  rX   ThreadingMixInr  r  r  r  r  r!   r   r   <module>r     s   #  	 	    
  #   . "   !  + +  77d?: 2v,,L nnG **GGaggc1::c?&:;QYYw=OOP ??.. .;R\\ ;|D
/ D
N
( ++7+^ ?C) ) $) 1;) ) X> JN)<F*+
"6""$a*Z a*H44n &n &> 7;$*.*
*
* 
* 	*
 * 5* * (* 	* *Z9 *./37;<@$*.!bb
b !b 	b
 b b (b -b b b b b 5b :b b  (!b" 
#bU  	  +C	     Gs6   ,H H+ -H9 H('H(+H65H69II