
    2Bf              $       *   d Z ddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
Z
ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ 	 ddlZdZej>                  dk(  r		  e d        e!ed      Z"e"rejF                  Z#n
 G d d      Z#	 ejH                  Z%dZ' ejP                         dk(   xr	  e!ed      Z)e	jT                  e	jV                  de	jX                  e-e	jT                  e-   f   df      Z.e	j^                  rddl0Z1ddl2m3Z3 ddl2m4Z4 ddl5m6Z6 dd l7m8Z8  G d! d"ejr                        Z: G d# d$e      Z;d%e-d&e-d'e-fd(Z<	 d[d)e	jT                  e-   d'e	jX                  d*   fd+Z=	 d\d,e-d-e	jT                  e-   d)e	jT                  e-   d'e	jX                  e-e-f   fd.Z>d]d/Z?	 d\d0e-d1e	jT                  e-   d2e	jT                  e@   d'dfd3ZAd[d4e	jT                  eB   d'eCfd5ZDd-e-d6e@d'ej                  fd7ZFd-e-d6e@d8ej                  d'e	jV                  e	jX                  e-e@f   e-f   fd9ZGd8ej                  d'e-fd:ZH G d; d<e      ZI G d= d>ej                  eI      ZK G d? d@e#eI      ZL	 	 	 	 	 	 d^d-e-d6e@dAdBdCeCdDe@dEe	jT                  e	j                  e;      dFeCdGe	jT                  e.   dHe	jT                  e@   d'eIfdIZNd'eCfdJZO	 	 	 	 	 	 	 	 	 	 	 	 	 d_dKe-d6e@dLdBdMeCdNeCdOeCdPe	jT                  e	j                  e-      dQe	jT                  e	j                  e-      dRe@dSe-dCeCdDe@dEe	jT                  e	j                  e;      dTe	jT                  e	j                  e-e	jV                  e-e	jX                  e-e-f   f   f      dFeCdGe	jT                  e.   d'df"dUZRdVe	j                  dWe	j                  d'dfdXZTd`dYZUeVdZk(  r eU        yy# 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 Zw xY w)aa  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                   0    e Zd Zdedej
                  fdZy)	_SslDummynamereturnc                     t        d      )NzSSL support unavailable)RuntimeError)selfr   s     P/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/werkzeug/serving.py__getattr__z_SslDummy.__getattr__)   s    899    N)__name__
__module____qualname__strtAnyr    r   r   r   r   (   s    	:C 	:AEE 	:r   r   TntcoloramaFforkc                       e Zd Zy)ForkingMixInN)r   r   r   r    r   r   r%   r%   <   s    r   r%      Windowsfromfdssl.SSLContextzte.Literal['adhoc'])WSGIApplication)WSGIEnvironment)RSAPrivateKeyWithSerialization)Certificatec                   \    e Zd ZdZdej
                  ddfdZdefdZde	fdZ
dede	fd	Zy)
DechunkedInputz8An input stream that handles Transfer-Encoding 'chunked'rfiler   Nc                 .    || _         d| _        d| _        y )NFr   )_rfile_done_len)r   r0   s     r   __init__zDechunkedInput.__init__Y   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      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   s      r   read_chunk_lenzDechunkedInput.read_chunk_lena   sm    	2;;'')00:Dtzz|R(D !8=>>	  	2011	2s   AA A,bufc                     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)   
s   
   z!Missing chunk terminating newline)	r3   lenr4   rC   minr2   readr<   rA   )r   rD   rJ   n
terminators        r   readintozDechunkedInput.readintok   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   )r   r   r   __doc__r   BinaryIOr5   boolr8   r>   rC   	bytearrayrM   r    r   r   r/   r/   V   sG    Bajj T 
$  &I &# &r   r/   c                       e Zd ZU dZded<   edefd       ZddZdd	Z	dd
Z
ddZ	 d dedej                  d   ddfdZddZd dedej                  e   ddfdZde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j0                  ddfdZdedej0                  ddfdZdededej0                  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/) rW   )r   rW   s     r   server_versionz!WSGIRequestHandler.server_version   s    !;-((r   r+   c                     t         j                        }d, fd} 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|d j                  d j                   d j"                  dddt%        |      dt%        |j&                        dt%         j                        dt%         j                        d j)                          j+                          j                  j,                  d   t         j                  j,                  d          j.                  d} j0                  j3                         D ]S  \  }}|j5                         j7                  dd      }|j7                  dd      }|d vrd!| }||v r
||    d"| }|||<   U |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)-Nc                  V    t        j                  dd       d j                  _        y )NzeThe 'environ['werkzeug.server.shutdown']' function is deprecated and will be removed in Werkzeug 2.1.   
stacklevelT)warningswarnrU   shutdown_signalr7   s   r   shutdown_serverz8WSGIRequestHandler.make_environ.<locals>.shutdown_server   s&    MMC
 +/DKK'r   httphttps)<local>r   r   /zwsgi.version)r   r   zwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_onceFzwerkzeug.server.shutdownzwerkzeug.socketSERVER_SOFTWAREREQUEST_METHODSCRIPT_NAMErX   	PATH_INFOQUERY_STRINGREQUEST_URIRAW_URIREMOTE_ADDRr   )REMOTE_PORTSERVER_NAMESERVER_PORTSERVER_PROTOCOL-_
)CONTENT_TYPECONTENT_LENGTHHTTP_,HTTP_TRANSFER_ENCODINGchunkedTzwsgi.input_terminated	HTTP_HOST)binary_formSSL_CLIENT_CERTerrorz&Cannot fetch SSL peer certificate infor   N)&r   pathrU   ssl_contextclient_address
isinstancer   schemenetlocr   r0   sysstderrmultithreadmultiprocess
connectionrY   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_urlrb   
url_scheme	path_infoenvironkeyvalue	peer_certs	   `        r   make_environzWSGIRequestHandler.make_environ   s   		*	/  ${{66>VG
"""0D++S1#'#6#6":D
 !!k&8&8K../0@0@/ABI#((I	*	&
F&
z&
 $**&
 3::	&

  7 7&
  !9!9&
 U&
 '&
 t&
 t22&
 dll&
 2&
 -i8&
 01B1BC&
  /		:!&
$ +DII6%&
& 4..0'&
(  ,,.;;55a8t{{99!<=#33/&
4 ,,,,. 	!JC))+%%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;MMNc                    	
  j                   j                  dd      j                         j                         dk(  r j                  j                  d        j                         x _        d 
d d 	d dt        dd f 	
fdd
fd	dfd	}	  | j                  j                         y # t        t        j                  f$ r} j                  |       Y d }~y d }~wt        $ rw  j                  j                   r d
dlm}  |d      }	 	d 
d  |t'                      n# t        $ r Y nw xY w j                  j)                  dd|j*                         Y y w xY w)NExpectrX   z100-continues   HTTP/1.1 100 Continue

datar   c                    J d       	J d       		 j                  d d      \  }}t        |      }
j                  ||       t	               }D ]8  \  }}
j                  ||       |j                         }|j                  |       : d|v s*d   dk(  s"|dk  s|dv sd	
_        
j                  d
d       d|vr 
j                  d
j                                d|vr 
j                  d
j                                
j                          t        | t              sJ d       
j                  j                  |        
j                  j!                          y # t        $ r d}}Y Gw xY w)Nzwrite() before start_responser   rX   zcontent-lengthrh   HEAD   )   i0  T
ConnectioncloserU   ServerdateDatezapplications must write bytes)splitr@   r>   send_responsesetsend_headerr   addclose_connectionversion_stringdate_time_stringend_headersr   byteswfilewriteflush)r   code_strmsgcodeheader_keysr   r   r   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". )JC$$S%0))+COOC()
 %3/0F:czz),0D)$$\7;;.$$Xt/B/B/DE,$$VT-B-B-DE  "dE*K,KK*JJT"JJ3 " 4$/cH4s   E( (E98E9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       t        |d      r|j                          y y # t        |d      r|j                          w w xY w)Nr   r   )hasattrr   )appapplication_iterr   r   r   r   r   s      r   executez,WSGIRequestHandler.run_wsgi.<locals>.execute3  sn    "7N;-,  D$K ##J+W5$**, 67+W5$**, 6s   A A"r   )get_current_tracebackT)ignore_system_exceptionsr   zError on request:
%sN)r   r*   r   N)r   r   r   r?   r   r   r   r   r   rU   r   ConnectionErrorsockettimeoutconnection_dropped	Exceptionpassthrough_errorsdebug.tbtoolsr   r   r   	plaintext)r   r   er   	tracebackr   r   r   r   r   r   r   s   `    @@@@@@@r   run_wsgizWSGIRequestHandler.run_wsgi   sP   <<Hb)//1779^KJJ=>!%!2!2!44w&*
=A'+>B"	 "	$ "	 "	H	 			- 		-	SDKKOO$0 	0##Aw// 	S{{--<-tLI &!%J"&K+-. KKOOG%<i>Q>QR	SsB   $C E4C112E4$D;:E4;	EE4E*E43E4c                 x   	 t        j                  |        | j                  j                  r| j                          yy# t        t        j                  f$ r}| j                  |       Y d}~Wd}~wt        $ r?}| j                  j                  t        |      r| j                  d|       n Y d}~d}~ww xY w)z/Handles a request ignoring dropped connections.NzSSL error occurred: %s)r   handler   r   r   r   r   rU   r   is_ssl_error	log_errorra   initiate_shutdown)r   r   s     r   r   zWSGIRequestHandler.handleS  s    	"))$/ ;;&&""$ '  0 	'##A&& 	{{&&2|A7; <	s!   ? B9A..B9:5B44B9c                     t               rGt        t        dt        j                        }t	        j
                  t	        j                         |       d| j                  _        y )NSIGKILLT)	is_running_from_reloadergetattrsignalSIGTERMoskillgetpidrU   _BaseServer__shutdown_request)r   sigs     r   r   z$WSGIRequestHandler.initiate_shutdowna  s:    #%&)V^^<CGGBIIK%481r   r   r   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_droppedi  s    r   c                     | j                   j                         | _        | j                  sd| _        y| j	                         r| j                          yy)zHandle a single HTTP request.TN)r0   r<   raw_requestliner   parse_requestr   r7   s    r   handle_one_requestz%WSGIRequestHandler.handle_one_requestp  sB    #zz224##$(D!!MMO "r   r   messagec                    | j                  |       |"|| j                  v r| j                  |   d   nd}| j                  dk7  r@| j                   d| d| d}| j                  j                  |j                  d             yy)z3Send the response header and log the response code.Nr   rX   zHTTP/0.9 ru   ascii)log_request	responsesr   protocol_versionr   r   encode)r   r   r   hdrs       r   r   z WSGIRequestHandler.send_responsex  s    ?151GdnnT*1-RG:-**+1TF!G9DACJJSZZ01 .r   c                 <    t         |          j                         S r   )superr   r?   )r   	__class__s    r   r   z!WSGIRequestHandler.version_string  s    w%'--//r   c                 r    t        | dd       r| j                  d   S | j                  sy| j                  d   S )Nr   rn   re   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   sizec                    	 t        | j                        }| j                   d| d| j                   }t        |      }t        rw|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)Nr   r   1bold200304cyan3green404yellow4redmagentainfoz
"%s" %s %s)
r   r   r   r   r   requestliner   _log_add_style_ansi_styler   )r   r   r  r   r   s        r   r   zWSGIRequestHandler.log_request  s    	#dii(D\\N!D64+?+?*@AC
 4yAw#~!#v.!#v.aC!#w/!#x0aC!#vu5!#vy9sD$7-  	#""C	#s   3C C+*C+formatargsc                 ,     | j                   d|g|  y )Nr   r   r   r  r  s      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   typec           	      h    t        || j                          d| j                          d| dg|  y )Nz - - [z] 
)r
   r   log_date_time_stringr   r  r   r  s       r   r   zWSGIRequestHandler.log  sB    ""$%VD,E,E,G+H7)SUV	
 	
r   )r   r+   r   r   )rs   rs   )r   r   r   rN   __annotations__propertyr   rY   r   r   r   r   BaseExceptionr   Optionalr   r   r>   r   r   r   r   Unionr   r   r   r  r   __classcell__r   s   @r   rS   rS      sV   =) ) )
VpZSx%9 NR"-.ZZ8I-J	2# 2

3 24 20 0& &&c & HK8GGCH%83477383D8	8<) )AEE )d )(# (aee ( (
 
c 
!%% 
D 
r   rS   r   stylesr   c                 B    ddddddd}|D ]  }d||    d	|  }  |  d
S )Nr          !   #   $   )r  r  r
  r  r  r  z[mz[0mr    )r   r'  codesstyles       r   r  r    sQ    E  /e~Qug./ WG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	}  |       }|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                  d      g      d      jG                  ||jI                         |      }	|	|fS # t        $ r t        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)%cryptographyr3  cryptography.x509.oidr4  cryptography.hazmat.backendsr5  cryptography.hazmat.primitivesr6  )cryptography.hazmat.primitives.asymmetricr7  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)
r1  r3  r4  r5  r6  r7  r:  pkeysubjectcerts
             r   generate_adhoc_ssl_pairr_    s   X%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4E3FGRW	X	dFMMOW	- 	 :A  XVWWXs   G   G5	base_pathhostc           	          |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=)r1  r   serializationz.crtz.keywbencodingr  encryption_algorithm)r_  rA  rd  openr   public_bytesEncodingPEMprivate_bytesPrivateFormatTraditionalOpenSSLNoEncryption)	r`  ra  r1  r^  r\  rd  	cert_file	pkey_filefs	            r   make_ssl_devcertrt    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   Nrc  rf  )tempfileatexitr_  rA  rd  mkstempregisterr   remover   rj  rk  rl  rm  rn  ro  rp  r   load_ssl_context)
rv  rw  r^  r\  rd  cert_handlerq  pkey_handlerr  ctxs
             r   generate_adhoc_ssl_contextr  $  s    (*JD$<%--/K%--/K
OOBIIy)
OOBIIy)HH[$++M,B,B,F,FGHHH"++// ..AA!.!;!;!= 	 	
 HH[HH[
9i
0CJr   rq  rr  protocolc                 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)rq  rr  r  r~  s       r   r{  r{  B  s8     **
..
"C	9-Jr   r   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   )r   castr   r   r   r   r   SSLError)r   s    r   r   r   W  s3    }y#,,."34eS\\**r   portc                     | 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)
startswithr   AF_UNIXr   r  AF_INET)ra  r  s     r   select_address_familyr  ^  s>     y!~~	4>>r   familyc                     |t         k(  r| j                  d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`.z://r   r      )af_unixr   r   getaddrinfoSOCK_STREAMIPPROTO_TCPgaierror)ra  r  r  ress       r   get_sockaddrr  h  s}    
 zz%#A&&  $ 2 2F4F4F

 q6!9 ?? Tzs   5A A76A7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  ra  ss      r   get_interface_ipr  x  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                   N    e Zd ZdZdZdZeZ	 	 	 	 ddede	ddde
j                  e
j                  e      d	ed
e
j                  e   de
j                  e	   ddf fd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e	f   ddf fdZ xZS )rT   z3Simple single-threaded, single-process WSGI server.FNra  r  r   r*   handlerr   r   fdr   c                 t   |t         }t        ||      | _        |1t        j                  || j                  t        j
                        }d}t        |t        |      | j                        }	| j                  t        k(  rNt        j                  t        |	      }	t        j                  j                  |	      rt        j                  |	       t         
| E  |	|       || _        || _        d| _        || _        | j                  j-                         d   | _        |@| j                  j1                          | _        | j                  j-                         | _        |Qt5        |t6              rt9        | }|dk(  r
t;               }|j=                  | j                  d      | _        || _        y d | _        y )Nr   Fr   adhocT)server_side) rS   r  address_familyr   r(   r  r  r>   r  r   r  r   r   r   existsunlinkr   r5   r   r   ra   ra  r  r  r   r   r   tupler{  r  wrap_socketr   )r   ra  r  r   r  r   r   r  	real_sockr   r   s             r   r5   zBaseWSGIServer.__init__  sh    ?(G3D$?>b$*=*=v?Q?QRID%dCIt7J7JK ')VVC8Nww~~n-		.)1"4$	KK++-a0	 >KK#DK"&++"9"9";D"+u-.<g%8:%11$++41PDK=HD#Dr   r  r   r  c                     t        ||g|  y r   r	   r  s       r   r   zBaseWSGIServer.log  s    T7"T"r   poll_intervalc                     d| _         	 t        | 	  |       | j	                          y # t        $ r Y w xY w# | j	                          w xY w)NF)r  )ra   r   serve_foreverKeyboardInterruptserver_close)r   r  r   s     r   r  zBaseWSGIServer.serve_forever  sQ    $	 G!!>  ! 		 s   + 	7: 7: Arequestr   c                 >    | j                   r t        | 	  ||      S r   )r   r   handle_error)r   r  r   r   s      r   r  zBaseWSGIServer.handle_error  s!    ""w#G^<<r   )NFNN)g      ?)r   r   r   rN   r   r   LISTEN_QUEUErequest_queue_sizer   r>   r   r#  TyperS   rP   _TSSLContextArgr5   r   r   floatr  Tupler  r%  r&  s   @r   rT   rT     s   =KL% ;?#(37"3$3$ 3$ 	3$
 AFF#5673$ !3$ ZZ03$ JJsO3$ 
3$j# #c #!%% #D # 5  4  =AEE =17738;L =QU = =r   rT   c                       e Zd ZdZdZdZy)ThreadedWSGIServerz"A WSGI server that does threading.TN)r   r   r   rN   r   daemon_threadsr    r   r   r  r    s    ,KNr   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dZy)ForkingWSGIServerz A WSGI server that does forking.TNra  r  r   r*   	processesr  r   r   r  r   c	           
      l    t         st        d      t        j                  | |||||||       || _        y )Nz'Your platform does not support forking.)can_forkr@   rT   r5   max_children)	r   ra  r  r   r  r  r   r   r  s	            r   r5   zForkingWSGIServer.__init__  s=     FGG$c7,>R	
 &r   )(   NFNN)r   r   r   rN   r   r   r>   r   r#  r  rS   rP   r  r5   r    r   r   r  r    s    *L :>#(37"&& & 	&
 & AFF#567& !& ZZ0& JJsO& 
&r   r  r   r*   threadedr  request_handlerr   r   r  c	           
          |r|dkD  rt        d      |rt        | ||||||      S |dkD  rt        | |||||||      S t        | ||||||      S )ztCreate a new server instance that is either threaded, or forks
    or just processes one request after another.
    r   z5cannot have a multithreaded and multi process server.r  )r@   r  r  rT   )	ra  r  r   r  r  r  r   r   r  s	            r   make_serverr    s     IMPQQ	!$_.@+RT
 	
 
Q 	
 		
 $_.@+RT
 	
r   c                  F    t         j                  j                  d      dk(  S )zwChecks if the application is running from within the Werkzeug
    reloader subprocess.

    .. versionadded:: 0.10
    WERKZEUG_RUN_MAINtrue)r   r   r   r    r   r   r   r      s     ::>>-.&88r   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}  ||      dt        j                  ddf fdd 
f	d	}|rft               sGd
k(  rt        st        d      t               }t         |      }t        j                  |t        j                        }|j                  t        j                  t        j                   d       |j#                  |       |j%                  d       t        rHt'        |j)                               t*        j,                  d<   |j/                  t0                |       nU|j3                          |t4        k(  r<t7        j8                  t&        |      }t;        dd|       t+        j<                  |       ddlm }  ||||||	       y |        y)a  Start a WSGI application. Optional features include a reloader,
    multithreading and fork support.

    This function has a command-line interface too::

        python -m werkzeug.serving --help

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

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

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

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

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

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

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

    :param hostname: The host to bind to, for example ``'localhost'``.
        If the value is a path that starts with ``unix://`` it will bind
        to a Unix socket instead of a TCP socket..
    :param port: The port for the server.  eg: ``8080``
    :param application: the WSGI application to execute
    :param use_reloader: should the server automatically restart the python
                         process if modules were changed?
    :param use_debugger: should the werkzeug debugging system be used?
    :param use_evalex: should the exception evaluation feature be enabled?
    :param extra_files: a list of files the reloader should watch
                        additionally to the modules.  For example configuration
                        files.
    :param exclude_patterns: List of :mod:`fnmatch` patterns to ignore
        when running the reloader. For example, ignore cache files that
        shouldn't reload when updated.
    :param reloader_interval: the interval for the reloader in seconds.
    :param reloader_type: the type of reloader to use.  The default is
                          auto detection.  Valid values are ``'stat'`` and
                          ``'watchdog'``. See :ref:`reloader` for more
                          information.
    :param threaded: should the process handle each request in a separate
                     thread?
    :param processes: if greater than 1 then handle each request in a new process
                      up to this maximum number of concurrent processes.
    :param request_handler: optional parameter that can be used to replace
                            the default one.  You can use this to replace it
                            with a different
                            :class:`~BaseHTTPServer.BaseHTTPRequestHandler`
                            subclass.
    :param static_files: a list or dict of paths for static files.  This works
                         exactly like :class:`SharedDataMiddleware`, it's actually
                         just wrapping the application in that middleware before
                         serving.
    :param passthrough_errors: set this to `True` to disable the error catching.
                               This means that the server will die on errors but
                               it can be useful to hook debuggers in (pdb etc.)
    :param ssl_context: an SSL context for the connection. Either an
                        :class:`ssl.SSLContext`, a tuple in the form
                        ``(cert_file, pkey_file)``, the string ``'adhoc'`` if
                        the server should automatically create one, or ``None``
                        to disable SSL (which is the default).
    zport must be an integerr   )DebuggedApplication)SharedDataMiddlewaresockr   Nc                 X   d}| j                   t        k(  rt        dd       y dk(  r&t        d|       t        t        j
                        }n-dk(  r&t        d|       t        t        j                        }n}d|v rd| d	}t        dd
dnd|| j                         d          y )Nzp * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.r  z' * Running on %s (Press CTRL+C to quit)z0.0.0.0warningz::r  []z0 * Running on %s://%s:%d/ (Press CTRL+C to quit)rc   rd   r   )r  r  r
   r  r   r  r  r  )r  all_addresses_messagedisplay_hostnamer  r   s      r   log_startupzrun_simple.<locals>.log_startup  s    ( 	 ;;'!BHM9$Y 56#3FNN#C T!Y 56#3FOO#D #+ &&%&'7&8#: B%-7   "1%r   c                     	 	 t        t        j                  d         } t        
	| 	      }|  |j                         |j                          y # t        t        f$ r d } Y Lw xY w)NWERKZEUG_SERVER_FDr  )r>   r   r   LookupErrorr@   r  r   r  )r  srvr  r  r  r   r  r  r  r   r  s     r   innerzrun_simple.<locals>.inner  s}    	"%bjj1E&F"GB 

 :

# Z( 	B	s   A A,+A,r   zsCannot bind to a random port with enabled reloader if the Python interpreter does not support socket opening by fd.Tr  r  zUnlinking %srun_with_reloader)r  r  intervalr  r   )!r   r>   rD  debugr  middleware.shared_datar  r   r   can_open_by_fdr@   r  r  r  
setsockopt
SOL_SOCKETSO_REUSEADDRbindset_inheritabler   filenor   r   listenr  r   r  r   r  r
   r  	_reloaderr  )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r  r  r   r  _rwrr  s   ```       ``` ``       @r   
run_simpler  )  s}   z dC 122.)+zB@*;E&-- D < (  ()qy 8  38TBN)(D.INnf.@.@AALL**F,?,?CFF>"d# 36qxxz?

/0&A	!W,%&VVC%@N@IIn-8#-&'	
 	r   r  kwargsc                  X    ddl m} t        j                  dt        d        || i | y)zRun a process with the reloader. This is not a public API, do
    not use this function.

    .. deprecated:: 2.0
        Will be removed in Werkzeug 2.1.
    r   r  zp'run_with_reloader' is a private API, it will no longer be accessible in Werkzeug 2.1. Use 'run_simple' instead.r\   r]   N)r  r  r_   r`   DeprecationWarning)r  r  r  s      r   r  r    s0     5MME 	 	$&r   c                     ddl } ddlm} t        dd       | j	                  dd	      }|j                  d
ddd       |j                  dddd       |j                  dddd       |j                  dd       |j                         }d\  }}|j                  r|j                  j                  d      \  }}}t        |xs dt        |xs d       ||j                        |j                  |j                         y)z:A simple command-line interface for :py:func:`run_simple`.r   Nr   )import_stringr  z:This CLI is deprecated and will be removed in version 2.1.z;Run the given WSGI application with the development server.F)descriptionallow_abbrevz-bz--bindaddressz+The hostname:port the app should listen on.)desthelpz-dz--debug
store_truez7Show the interactive debugger for unhandled exceptions.)actionr  z-rz--reloadz%Reload the process if modules change.r  z8Application to import and serve, in the form module:app.)r  NNr  r  i  )r  r  r  r  r  )argparseutilsr  r
   ArgumentParseradd_argument
parse_argsr  	partitionr  r>   r  reloadr  )r  r  parserr  r  r  rt   s          r   mainr    s   $PQ$$Q % F :	   F	   4	   V   DNHd|| LL2237!T([!$"2"23[[ZZr   __main__r   r  )r   r)   )Fr   NFNN)FFTNNr   autoFr   NNFNr   )WrN   ior   platformr   r   socketserverr   typingr   r_   r   rQ  r   r   http.serverr   r   	_internalr
   r   
exceptionsr   urlsr   r   r   r   rC  r   r  r   
__import__r   r  r%   r  r  r   r  systemr  r#  r$  r  r   r  TYPE_CHECKINGtyping_extensionste_typeshed.wsgir*   r+   -cryptography.hazmat.primitives.asymmetric.rsar,   cryptography.x509r-   	RawIOBaser/   rS   r  r_  rt  r  r>   r{  r   rP   r   AddressFamilyr  r  r  rT   ThreadingMixInr  r  r  r  r   IterableDictr  r   r  r  r   r    r   r   <module>r%     sl   
 	     
   #   . "  + +    77d?: 2v,,L nnG $X__&)33Q8Q**GGaggc1::c?&:;=RRS ??".. .;R\\ ;|e
/ e
P	s S S " )	

3)WW<=)Z IM) ) **S/) 67jjo) WWS#X) X> TX zz#ABC*+

9- + + 3 63G3G 
"("6"6WWQWWS#X#$ "V11 "c "$M=Z M=`44n &n &: >B$/3"

"

"
 
"
 	"

 "
 ZZ'9 :;"
 "
 O,"
 	


3"
 "
J9$ 9 /348>BMQ$/3!GG
G #G 	G
 G G AJJsO,G jjC1G G G G G ZZ'9 :;G **QVVCaggc3h6G1G)H$HIJG G  O,!G" 
#GTQUU aee  (,^ zF a   : : +C    Gs6   *O  O9 +P O65O69PPPP