a
    é´«j³›  ã                   @  s€  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mZ z"ddlZe ej!ej"fZ#de$d< W n2 e%�y6   G dd„ dƒZ&e&ƒ Ze ej!fZ#Y n0 dZ'ej(dk�rnze)dƒ W n e%�yl   dZ'Y n0 e*edƒZ+e+�r†ej,Z,nG dd„ dƒZ,z
ej-Z.W n e/�y¶   dZ.Y n0 dZ0ej1ej2de3e4ej1e4 f ej5d f  Z6ej7�rddl8m9Z9 dd l8m:Z: dd!l;m<Z< dd"l=m>Z> G d#d$„ d$ej?ƒZ@G d%d&„ d&eƒZAd'd'd'd(œd)d*„ZBdad+d,d-œd.d/„ZCdbd'd+d+d0d1œd2d3„ZDdd4œd5d6„ZEdcd'd+d7dd8œd9d:„ZFddd;d<d=œd>d?„ZGd'd@dAdBœdCdD„ZHd'd@dAdEdFœdGdH„ZIdAd'dIœdJdK„ZJG dLdM„ dMeƒZKG dNdO„ dOejLeKƒZMG dPdQ„ dQe,eKƒZNded'd@dRd<d@dSd<dTd7dMdUœ
dVdW„ZOd<d4œdXdY„ZPdfd'd@dRd<d<d<d[d[d@d'd<d@dSd\d<dTd]d^œd_d`„ZQdS )gaØ  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)Úparse_set_header)Ú
uri_to_iriztuple[type[Exception], ...]Úconnection_dropped_errorsc                   @  s   e Zd Zdddœdd„ZdS )Ú	_SslDummyÚstrút.Any©ÚnameÚreturnc                 C  s   t dƒ‚d S )NzUSSL is unavailable because this Python runtime was not compiled with SSL/TLS support.)ÚRuntimeError©Úselfr   © r   úO/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/werkzeug/serving.pyÚ__getattr__2   s    ÿz_SslDummy.__getattr__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   1   s   r   TÚntÚcoloramaFÚforkc                   @  s   e Zd ZdS )ÚForkingMixInN)r   r   r    r   r   r   r   r$   I   s   r$   é€   zssl.SSLContextÚadhoc)ÚWSGIApplication)ÚWSGIEnvironment)ÚRSAPrivateKeyWithSerialization)ÚCertificatec                   @  sL   e Zd ZdZdddœdd„Zddœd	d
„Zddœdd„Zdddœdd„ZdS )ÚDechunkedInputz8An input stream that handles Transfer-Encoding 'chunked'zt.IO[bytes]ÚNone)Úrfiler   c                 C  s   || _ d| _d| _d S )NFr   )Ú_rfileÚ_doneÚ_len)r   r-   r   r   r   Ú__init__d   s    zDechunkedInput.__init__Úbool©r   c                 C  s   dS )NTr   ©r   r   r   r   Úreadablei   s    zDechunkedInput.readableÚintc              
   C  sf   z"| j  ¡  d¡}t| ¡ dƒ}W n. tyP } ztdƒ|‚W Y d }~n
d }~0 0 |dk rbtdƒ‚|S )NÚlatin1é   zInvalid chunk headerr   z!Negative chunk length not allowed)r.   ÚreadlineÚdecoder6   ÚstripÚ
ValueErrorÚOSError)r   Úliner0   Úer   r   r   Úread_chunk_lenl   s     zDechunkedInput.read_chunk_lenÚ	bytearray)Úbufr   c                 C  sø   d}| j sô|t|ƒk rô| jdkr*|  ¡ | _| jdkr:d| _ | jdkrÎtt|ƒ| jƒ}|| t|ƒkr | j t|ƒ| ¡||d …< |  jt|ƒ| 8  _t|ƒ}n.| j |¡|||| …< |  j|8  _||7 }| jdkr| j ¡ }|dvrtdƒ‚q|S )Nr   T)ó   
ó   
ó   z!Missing chunk terminating newline)	r/   Úlenr0   r@   Úminr.   Úreadr9   r=   )r   rB   rH   ÚnÚ
terminatorr   r   r   Úreadintov   s(    







zDechunkedInput.readintoN)r   r   r    Ú__doc__r1   r5   r@   rK   r   r   r   r   r+   a   s
   
r+   c                      s   e Zd ZU dZded< eddœdd„ƒZddœd	d
„Zddœdd„Zddœ‡ fdd„Z	d3ddddœdd„Z
dddœ‡ fdd„Zddœdd„Zddœdd„Ze dd „ g ed!ƒ¢ed"d#ƒ¢D ƒ¡Zd$eed%ƒ< d4d'd'dd(œd)d*„Zdddd+œd,d-„Zdddd+œd.d/„Zddddd0œd1d2„Z‡  ZS )5ÚWSGIRequestHandlerz3A request handler that implements WSGI dispatching.ÚBaseWSGIServerÚserverr   r3   c                 C  s   | j jS ©N)rO   Ú_server_versionr4   r   r   r   Úserver_version¤   s    z!WSGIRequestHandler.server_versionr(   c                 C  s  t | jƒ}| jjd u rdnd}| js,d| _nt| jtƒrD| jdf| _|jsd|jrdd|j› |j› �}n|j}t	|ƒ}d|| j
tj| jj| jjd| j| j| jdt|ƒt|jƒt| jƒt| jƒ|  ¡ |  ¡ | jjd t| jjd	 ƒ| jd
œ}| j ¡ D ]h\}}d|v �rqð| ¡  dd¡}| dd¡}|dv�rPd|› �}||v �rP|| › d|› �}|||< qðdt| d¡ƒv �r†d|d< t|d ƒ|d< |j�r |j�r |j|d< z*| jjdd�}|d u�rÈt  !|¡|d< W n4 t"�yì   | j #dd¡ Y n t$�yþ   Y n0 |S )NÚhttpÚhttps)ú<local>r   r   ú/)r
   r   FÚ r
   )zwsgi.versionzwsgi.url_schemeú
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_oncezwerkzeug.socketÚSERVER_SOFTWAREÚREQUEST_METHODZSCRIPT_NAMEZ	PATH_INFOÚQUERY_STRINGZREQUEST_URIZRAW_URIÚREMOTE_ADDRZREMOTE_PORTZSERVER_NAMEZSERVER_PORTZSERVER_PROTOCOLÚ_ú-z
)ÚCONTENT_TYPEÚCONTENT_LENGTHZHTTP_ú,ÚchunkedZHTTP_TRANSFER_ENCODINGTzwsgi.input_terminatedrX   Z	HTTP_HOST)Úbinary_formZSSL_CLIENT_CERTÚerrorz&Cannot fetch SSL peer certificate info)%r	   ÚpathrO   Ússl_contextÚclient_addressÚ
isinstancer   ÚschemeÚnetlocr   r-   ÚsysÚstderrÚmultithreadÚmultiprocessÚ
connectionrR   Úcommandr   ÚqueryÚaddress_stringÚport_integerÚserver_addressÚrequest_versionÚheadersÚitemsÚupperÚreplacer   Úgetr+   ÚgetpeercertÚsslÚDER_cert_to_PEM_certr<   ÚlogÚAttributeError)r   Úrequest_urlÚ
url_schemeZ	path_infoÚenvironÚkeyÚvalueZ	peer_certr   r   r   Úmake_environ¨   sn    

ê






zWSGIRequestHandler.make_environr,   c                   s†  ˆj  dd¡ ¡  ¡ dkr&ˆj d¡ ˆ ¡  ˆ_‰d ‰d ‰d ‰d ‰d‰ dddœ‡ ‡‡‡‡‡‡fd	d
„‰d‡‡‡‡fdd„	‰dddœ‡ ‡‡‡‡‡fdd„}z|ˆjj	ƒ W nÖ t
yÚ } zˆ |ˆ¡ W Y d }~n°d }~0  t�y€ } zŽˆjjrô‚ ˆd u�r
ˆ �r
dˆ_z ˆd u �rd ‰d ‰|tƒ ƒ W n t�y>   Y n0 ddlm} ||ƒ ¡ }ˆj dd|› �¡ W Y d }~n
d }~0 0 d S )NZExpectrW   z100-continues   HTTP/1.1 100 Continue

FÚbytesr,   )Údatar   c                   s~  ˆd usJ dƒ‚ˆd us J dƒ‚ˆd u �rˆ‰ˆ‰zˆ  d d¡\}}W n tyb   ˆd }}Y n0 t|ƒ}ˆ ||¡ tƒ }ˆD ]"\}}ˆ ||¡ | | ¡ ¡ q‚d|v sòˆd dksòd|  krÎdk sòn |d	v sòˆjd
kròd‰ ˆ dd¡ ˆ dd¡ ˆ 	¡  t
| tƒ�sJ dƒ‚| �rpˆ �rRˆj tt| ƒƒdd …  ¡ ¡ ˆj d¡ ˆj | ¡ ˆ �rpˆj d¡ ˆj ¡  d S )Nzwrite() before start_responser
   rW   zcontent-lengthrZ   ÚHEADéd   éÈ   >   i0  éÌ   úHTTP/1.1TzTransfer-Encodingrb   Ú
ConnectionÚclosezapplications must write bytesé   rD   )Úsplitr<   r6   Zsend_responseÚsetZsend_headerÚaddÚlowerÚprotocol_versionZend_headersrh   r†   ÚwfileÚwriteÚhexrF   ÚencodeÚflush)r‡   Zcode_strÚmsgÚcodeÚheader_keysrƒ   r„   )Úchunk_responser‚   Úheaders_sentÚheaders_setr   Ústatus_sentÚ
status_setr   r   r–     sP    

þ
ýüüûù	 z*WSGIRequestHandler.run_wsgi.<locals>.writec                   sD   |r,zˆ r|d   |d ¡‚W d }q8d }0 nˆr8tdƒ‚| ‰|‰ˆS )Nr
   r�   zHeaders already set)Úwith_tracebackÚAssertionError)Ústatusrv   Úexc_info)rž   rŸ   r¡   r–   r   r   Ústart_response=  s    z3WSGIRequestHandler.run_wsgi.<locals>.start_responser'   )Úappr   c              
     sJ  | ˆˆƒ}z°|D ]}ˆ|ƒ qˆs*ˆdƒ ˆ r:ˆj  d¡ W t ¡ }| ˆjtj¡ d}d}|jdd�r ˆj 	d¡}|t
|ƒ7 }|d7 }|r |dks |d	kr\q q\| ¡  t|d
ƒrº| ¡  nŠt ¡ }| ˆjtj¡ d}d}|jdd��r(ˆj 	d¡}|t
|ƒ7 }|d7 }|�r(|dk�s(|d	krÜ�q(qÜ| ¡  t|d
ƒ�rD| ¡  0 d S )Nó    s   0

r   g{®Gáz„?)Útimeouti€–˜ r
   l    d(	 iè  rŽ   )r•   r–   Ú	selectorsÚDefaultSelectorÚregisterro   Ú
EVENT_READÚselectr-   rH   rF   rŽ   Úhasattr)r§   Zapplication_iterr‡   ÚselectorÚ
total_sizeZtotal_reads)r�   r‚   rž   r   r¦   r–   r   r   ÚexecuteK  sD    



ëz,WSGIRequestHandler.run_wsgi.<locals>.executeTr
   )ÚDebugTracebackrd   zError on request:
)N)rv   rz   r“   r;   r•   r–   r…   r‚   rO   r§   r   Úconnection_droppedÚ	ExceptionÚpassthrough_errorsZclose_connectionr   Zdebug.tbtoolsr³   Zrender_traceback_textr~   )r   r²   r?   r³   rš   r   )	r�   r‚   rž   rŸ   r   r¦   r    r¡   r–   r   Úrun_wsgiù   s<     9' 
zWSGIRequestHandler.run_wsgic              
     sŽ   zt ƒ  ¡  W nz ttjfyB } z|  |¡ W Y d}~nPd}~0  tyˆ } z0| jjdurrt	|ƒrr|  
d|¡ n‚ W Y d}~n
d}~0 0 dS )z/Handles a request ignoring dropped connections.NzSSL error occurred: %s)ÚsuperÚhandleÚConnectionErrorÚsocketr©   r´   rµ   rO   rf   Úis_ssl_errorÚ	log_error)r   r?   ©Ú	__class__r   r   r¹   Œ  s    zWSGIRequestHandler.handleNÚBaseExceptionzWSGIEnvironment | None)rd   r‚   r   c                 C  s   dS )z`Called if the connection was closed by the client.  By default
        nothing happens.
        Nr   )r   rd   r‚   r   r   r   r´   ˜  s    z%WSGIRequestHandler.connection_droppedr   r   c                   s   |  d¡r| jS ttƒ |ƒS )NZdo_)Ú
startswithr·   Úgetattrr¸   r   r¾   r   r   r   Ÿ  s    
zWSGIRequestHandler.__getattr__c                 C  s*   t | dd ƒr| jd S | js dS | jd S )Nr‚   r\   rU   r   )rÂ   r‚   rg   r4   r   r   r   rr   §  s
    
z!WSGIRequestHandler.address_stringr6   c                 C  s
   | j d S )Nr
   )rg   r4   r   r   r   rs   °  s    zWSGIRequestHandler.port_integerc                 C  s   i | ]}|d |d›�“qS )z\xÚ02xr   )Ú.0Úcr   r   r   Ú
<dictcomp>µ  r¨   zWSGIRequestHandler.<dictcomp>é    é   é    z\\ú\r^   z	int | str)r›   Úsizer   c                 C  sò   z&t | jƒ}| j› d|› d| j› �}W n ty>   | j}Y n0 | | j¡}t|ƒ}|d dkrlt	|dƒ}np|dkrvnf|dkrŠt	|dƒ}nR|d dkr¢t	|d	ƒ}n:|d
kr¶t	|dƒ}n&|d dkrÐt	|ddƒ}nt	|ddƒ}|  
dd|||¡ d S )Nú r   Ú1ÚboldZ200Z304ÚcyanÚ3ÚgreenZ404ÚyellowÚ4ÚredÚmagentaÚinfoz
"%s" %s %s)r   re   rp   ru   r   ZrequestlineÚ	translateÚ_control_char_tabler   Ú_ansi_styler~   )r   r›   rË   re   rš   r   r   r   Úlog_request¹  s*    
zWSGIRequestHandler.log_request)ÚformatÚargsr   c                 G  s   | j d|g|¢R Ž  d S )Nrd   ©r~   ©r   rÛ   rÜ   r   r   r   r½   Ö  s    zWSGIRequestHandler.log_errorc                 G  s   | j d|g|¢R Ž  d S )NrÖ   rÝ   rÞ   r   r   r   Úlog_messageÙ  s    zWSGIRequestHandler.log_message©ÚtypeÚmessagerÜ   r   c                 G  s<   |   ¡  dd¡}t||› d|  ¡ › d|› d�g|¢R Ž  d S )Nú%z%%z - - [z] Ú
)rr   ry   r   Zlog_date_time_string)r   rá   râ   rÜ   rr   r   r   r   r~   Ü  s    þýzWSGIRequestHandler.log)N)r^   r^   )r   r   r    rL   Ú__annotations__ÚpropertyrR   r…   r·   r¹   r´   r   rr   rs   r   Ú	maketransÚrangerØ   ÚordrÚ   r½   rß   r~   Ú__classcell__r   r   r¾   r   rM   Ÿ   s*   
Q  ÿ	ÿrM   r   )r„   Ústylesr   c                 G  sB   t s| S dddddddœ}|D ]}d|| › d	| › �} q| › d
�S )Nr
   é   rÇ   é!   é#   é$   )rÎ   rÔ   rÑ   rÒ   rÕ   rÏ   z[Úmz[0m)Ú_log_add_style)r„   rë   ÚcodesÚstyler   r   r   rÙ   æ  s    ú	rÙ   z
str | Nonez2tuple[Certificate, RSAPrivateKeyWithSerialization])Úcnr   c           
      C  sF  z@ddl m} ddlm} ddlm} ddlm} ddlm	} W n t
y\   tdƒd ‚Y n0 |ƒ }|jdd	|d
�}| d u r€d} | | |jd¡| |j| ¡g¡}|ƒ }| ¡  |¡ |¡ | ¡ ¡ | ¡ ¡ t tj¡¡ t tj¡tdd� ¡j| |j g¡dd�j| !| "| ¡| "d| › �¡g¡dd� #|| $¡ |¡}	|	|fS )Nr   )Úx509)Údefault_backend)Úhashes)Úrsa)ÚNameOIDz<Using ad-hoc certificates requires the cryptography library.i  i   )Zpublic_exponentZkey_sizeÚbackendÚ*zDummy Certificateim  )ÚdaysF)Úcriticalz*.)%Zcryptographyrõ   Zcryptography.hazmat.backendsrö   Úcryptography.hazmat.primitivesr÷   Z)cryptography.hazmat.primitives.asymmetricrø   Zcryptography.x509.oidrù   ÚImportErrorÚ	TypeErrorZgenerate_private_keyÚNameZNameAttributeZORGANIZATION_NAMEZCOMMON_NAMEZCertificateBuilderZsubject_nameZissuer_nameZ
public_keyZserial_numberZrandom_serial_numberZnot_valid_beforeÚdtÚnowr   ÚutcZnot_valid_afterr   Úadd_extensionZExtendedKeyUsageZOID_SERVER_AUTHZSubjectAlternativeNameZDNSNameÚsignÚSHA256)
rô   rõ   rö   r÷   rø   rù   rú   ÚpkeyÚsubjectÚcertr   r   r   Úgenerate_adhoc_ssl_pairù  s\    ÿþÿþÿÿþýü
ûúù	ö
ôÿr  ztuple[str, str])Ú	base_pathÚhostrô   r   c           	      C  sÌ   |dur|}t |d�\}}ddlm} | › d�}| › d�}t|dƒ�$}| | |jj¡¡ W d  ƒ n1 sn0    Y  t|dƒ�2}| |j|jj|j	j
| ¡ d�¡ W d  ƒ n1 sº0    Y  ||fS )	aÂ  Creates an SSL key for development.  This should be used instead of
    the ``'adhoc'`` key which generates a new cert on each server start.
    It accepts a path for where it should store the key and cert and
    either a host or CN.  If a host is given it will use the CN
    ``*.host/CN=host``.

    For more information see :func:`run_simple`.

    .. versionadded:: 0.9

    :param base_path: the path to the certificate and key.  The extension
                      ``.crt`` is added for the certificate, ``.key`` is
                      added for the key.
    :param host: the name of the host.  This can be used as an alternative
                 for the `cn`.
    :param cn: the `CN` to use.
    N)rô   r   ©Úserializationz.crtz.keyÚwb©ÚencodingrÛ   Zencryption_algorithm)r  rþ   r  Úopenr–   Úpublic_bytesÚEncodingÚPEMÚprivate_bytesÚPrivateFormatÚTraditionalOpenSSLÚNoEncryption)	r  r  rô   r
  r  r  Ú	cert_fileÚ	pkey_fileÚfr   r   r   Úmake_ssl_devcert*  s"    

2ýÿ"r  r3   c            
      C  s¶   ddl } ddl}tƒ \}}ddlm} | ¡ \}}| ¡ \}}|  tj|¡ |  tj|¡ t 	|| 
|jj¡¡ t 	||j|jj|jj| ¡ d�¡ t |¡ t |¡ t||ƒ}	|	S )z:Generates an adhoc SSL context for the development server.r   Nr  r  )ÚatexitÚtempfiler  rþ   r  Úmkstempr¬   ÚosÚremover–   r  r  r  r  r  r  r  rŽ   Úload_ssl_context)
r  r   r
  r  r  Zcert_handler  Zpkey_handler  Úctxr   r   r   Úgenerate_adhoc_ssl_contextV  s*    
ýþ	


r&  ú
int | None)r  r  Úprotocolr   c                 C  s(   |du rt j}t  |¡}| | |¡ |S )aã  Loads SSL context from cert/private key files and optional protocol.
    Many parameters are directly taken from the API of
    :py:class:`ssl.SSLContext`.

    :param cert_file: Path of the certificate to use.
    :param pkey_file: Path of the private key to use. If not given, the key
                      will be obtained from the certificate file.
    :param protocol: A ``PROTOCOL`` constant from the :mod:`ssl` module.
        Defaults to :data:`ssl.PROTOCOL_TLS_SERVER`.
    N)r|   ÚPROTOCOL_TLS_SERVERÚ
SSLContextÚload_cert_chain)r  r  r(  r%  r   r   r   r$  t  s
    
r$  zException | Noner2   )rd   r   c                 C  s(   | du rt  tt ¡ d ¡} t| tjƒS )z?Checks if the given error (or the current one) is an SSL error.Nr
   )ÚtÚcastrµ   rk   r¥   rh   r|   ÚSSLError)rd   r   r   r   r¼   ‰  s    r¼   r6   zsocket.AddressFamily)r  Úportr   c                 C  s.   |   d¡rtjS d| v r(ttdƒr(tjS tjS )zUReturn ``AF_INET4``, ``AF_INET6``, or ``AF_UNIX`` depending on
    the host and port.zunix://ú:ÚAF_INET6)rÁ   r»   ÚAF_UNIXr¯   r1  ÚAF_INET)r  r/  r   r   r   Úselect_address_family�  s
    
r4  útuple[str, int] | str)r  r/  Úfamilyr   c                 C  sb   |t krtj |  d¡d ¡S zt | ||tjtj¡}W n tj	yT   | |f Y S 0 |d d S )zVReturn a fully qualified socket address that can be passed to
    :func:`socket.bind`.ú://r�   r   é   )
Úaf_unixr"  re   ÚabspathÚ	partitionr»   ÚgetaddrinfoÚSOCK_STREAMÚIPPROTO_TCPÚgaierror)r  r/  r6  Úresr   r   r   Úget_sockaddrš  s    ÿrA  )r6  r   c              	   C  s–   | t jkrdnd}t   | t j¡�b}z| |df¡ W n2 tyf   | t jkrPdnd Y W  d  ƒ S 0 | ¡ d W  d  ƒ S 1 sˆ0    Y  dS )zˆGet 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»   r1  Ú
SOCK_DGRAMÚconnectr=   Úgetsockname)r6  r  Úsr   r   r   Úget_interface_ip«  s    &rG  c                
      s”   e Zd ZdZdZdZeZdZd ddddd	d
dddœ‡ fdd„Z	dddddœdd„Z
d!dddœ‡ fdd„Zddddœ‡ fdd„Zddœdd„Z‡  ZS )"rN   zuA WSGI server that that handles one request at a time.

    Use :func:`make_server` to create a server instance.
    FTNr   r6   r'   útype[WSGIRequestHandler] | Noner2   ú_TSSLContextArg | Noner'  r,   )r  r/  r§   Úhandlerr¶   rf   Úfdr   c              
     s   |d u rt }dt|ƒvr*| js$| jr*d|_|| _|| _|| _|| _t	||ƒ | _
}t|t|ƒ|ƒ}	|tkr”|d u r”t t|	¡}	tj |	¡r”t |	¡ tƒ j|	|dd� |d u �rtz|  ¡  |  ¡  W n¬ t�yT }
 zv|  ¡  t|
jtjd� |
jtj k�r6td|› d�tjd� tj!dk�r6|d	k�r6td
tjd� t "d¡ W Y d }
~
n&d }
~
0  t#�yp   |  ¡  ‚ Y n0 n&|  ¡  t$ %||t$j&¡| _$| j$ '¡ | _(|tk�r°| j(d | _|d u�rút)|t*ƒ�rÐt+|Ž }n|dk�ràt,ƒ }|j-| j$dd�| _$|| _.nd | _.dd l/}d|j0 1d¡› �| _2d S )Nr”   rŒ   F)Úbind_and_activate)ÚfilezPort zp is in use by another program. Either identify and stop that program, or start the server with a different port.Údarwiniˆ  zPOn macOS, try searching for and disabling 'AirPlay Receiver' in System Settings.r
   r&   T)Úserver_sider   z	Werkzeug/Zwerkzeug)3rM   Úvarsrm   rn   r”   r  r/  r§   r¶   r4  Úaddress_familyrA  r6   r9  r,  r-  r   r"  re   ÚexistsÚunlinkr¸   r1   Úserver_bindÚserver_activater=   Úserver_closeÚprintÚstrerrorrk   rl   ÚerrnoÚ
EADDRINUSEÚplatformÚexitrÀ   r»   Úfromfdr=  rE  rt   rh   Útupler$  r&  Úwrap_socketrf   Úimportlib.metadataÚmetadataÚversionrQ   )r   r  r/  r§   rJ  r¶   rf   rK  rQ  rt   r?   Ú	importlibr¾   r   r   r1   È  sv    
ÿÿ
ý

üý




zBaseWSGIServer.__init__r   rà   c                 G  s   t ||g|¢R Ž  d S rP   r   )r   rá   râ   rÜ   r   r   r   r~   /  s    zBaseWSGIServer.logç      à?Úfloat)Úpoll_intervalr   c                   sB   z2zt ƒ j|d� W n ty&   Y n0 W |  ¡  n
|  ¡  0 d S )N)rf  )r¸   Úserve_foreverÚKeyboardInterruptrV  )r   rf  r¾   r   r   rg  2  s
    zBaseWSGIServer.serve_foreverr5  )Úrequestrg   r   c                   s   | j r‚ tƒ  ||¡S rP   )r¶   r¸   Úhandle_error)r   ri  rg   r¾   r   r   rj  :  s    zBaseWSGIServer.handle_errorr3   c                 C  sö   d}t |ddƒ}|g}| jtkr4| d| j› �¡ n®| jdu rBdnd}| j}| jdv r°| d	| j› d
�¡ | jdkr„d}ttjƒ}nd}ttj	ƒ}| d|› d|› d| j
› �¡ d|v rÄd|› d�}| d|› d|› d| j
› �¡ tdd |¡ƒ dS )z<Show information about the address when starting the server.zvWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.rÎ   rÔ   z * Running on NrS   rT   >   ú0.0.0.0z::z * Running on all addresses (ú)rk  rB  z[::1]r7  r0  ú[ú]rÖ   rä   )rÙ   rQ  r9  Úappendr  rf   rG  r»   r3  r1  r/  r   Újoin)r   Zdev_warningÚmessagesri   Zdisplay_hostnameÚ	localhostr   r   r   Úlog_startupB  s(    ÿ



zBaseWSGIServer.log_startup)NFNN)rd  )r   r   r    rL   rm   rn   ÚLISTEN_QUEUEÚrequest_queue_sizeÚallow_reuse_addressr1   r~   rg  rj  rs  rê   r   r   r¾   r   rN   ½  s       ø"grN   c                   @  s   e Zd ZdZdZdZdS )ÚThreadedWSGIServerz†A WSGI server that handles concurrent requests in separate
    threads.

    Use :func:`make_server` to create a server instance.
    TN)r   r   r    rL   rm   Údaemon_threadsr   r   r   r   rw  e  s   rw  c                      s<   e Zd ZdZdZdddddd	d
ddddœ	‡ fdd„Z‡  ZS )ÚForkingWSGIServerz�A WSGI server that handles concurrent requests in separate forked
    processes.

    Use :func:`make_server` to create a server instance.
    Té(   NFr   r6   r'   rH  r2   rI  r'  r,   )	r  r/  r§   Ú	processesrJ  r¶   rf   rK  r   c	           	   	     s.   t stdƒ‚tƒ  |||||||¡ || _d S )Nz'Your platform does not support forking.)Úcan_forkr<   r¸   r1   Úmax_children)	r   r  r/  r§   r{  rJ  r¶   rf   rK  r¾   r   r   r1   y  s    zForkingWSGIServer.__init__)rz  NFNN)r   r   r    rL   rn   r1   rê   r   r   r¾   r   ry  p  s        ÷ry  r'   rH  rI  )
r  r/  r§   Úthreadedr{  Úrequest_handlerr¶   rf   rK  r   c	           	   
   C  sd   |r|dkrt dƒ‚|r.t| ||||||d�S |dkrNt| |||||||d�S t| ||||||d�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.©rK  )r<   rw  ry  rN   )	r  r/  r§   r~  r{  r  r¶   rf   rK  r   r   r   Úmake_server‹  s(    ÿøÿr�  c                   C  s   t j d¡dkS )zqCheck if the server is running as a subprocess within the
    Werkzeug reloader.

    .. versionadded:: 0.10
    ZWERKZEUG_RUN_MAINÚtrue)r"  r‚   rz   r   r   r   r   Úis_running_from_reloader¸  s    rƒ  Úautozt.Iterable[str] | Nonez'dict[str, str | tuple[str, str]] | Noner,   )Úhostnamer/  ÚapplicationÚuse_reloaderÚuse_debuggerÚ
use_evalexÚextra_filesÚexclude_patternsÚreloader_intervalÚreloader_typer~  r{  r  Ústatic_filesr¶   rf   r   c                 C  s  t |tƒstdƒ‚|r,ddlm} |||ƒ}|rTddlm} |||d�}|j | ¡ t	ƒ s`d}ntt
jd ƒ}t| |||
|||||d�	}|j d	¡ t| ¡ ƒt
jd< t	ƒ sÄ| ¡  td
tddƒƒ |�rddlm} z ||j||||	d� W | ¡  n
| ¡  0 n| ¡  dS )a  Start a development server for a WSGI application. Various
    optional features can be enabled.

    .. warning::

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

    :param hostname: The host to bind to, for example ``'localhost'``.
        Can be a domain, IPv4 or IPv6 address, or file path starting
        with ``unix://`` for a Unix socket.
    :param port: The port to bind to, for example ``8080``. Using ``0``
        tells the OS to pick a random free port.
    :param application: The WSGI application to run.
    :param use_reloader: Use a reloader process to restart the server
        process when files are changed.
    :param use_debugger: Use Werkzeug's debugger, which will show
        formatted tracebacks on unhandled exceptions.
    :param use_evalex: Make the debugger interactive. A Python terminal
        can be opened for any frame in the traceback. Some protection is
        provided by requiring a PIN, but this should never be enabled
        on a publicly visible server.
    :param extra_files: The reloader will watch these files for changes
        in addition to Python modules. For example, watch a
        configuration file.
    :param exclude_patterns: The reloader will ignore changes to any
        files matching these :mod:`fnmatch` patterns. For example,
        ignore cache files.
    :param reloader_interval: How often the reloader tries to check for
        changes.
    :param reloader_type: The reloader to use. The ``'stat'`` reloader
        is built in, but may require significant CPU to watch files. The
        ``'watchdog'`` reloader is much more efficient but requires
        installing the ``watchdog`` package first.
    :param threaded: Handle concurrent requests using threads. Cannot be
        used with ``processes``.
    :param processes: Handle concurrent requests using up to this number
        of processes. Cannot be used with ``threaded``.
    :param request_handler: Use a different
        :class:`~BaseHTTPServer.BaseHTTPRequestHandler` subclass to
        handle requests.
    :param static_files: A dict mapping URL prefixes to directories to
        serve static files from using
        :class:`~werkzeug.middleware.SharedDataMiddleware`.
    :param passthrough_errors: Don't catch unhandled exceptions at the
        server level, let the 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)ZevalexNZWERKZEUG_SERVER_FDr€  TrÖ   zPress CTRL+C to quitrÒ   )Úrun_with_reloader)rŠ  r‹  Úintervalr�  )rh   r6   r   Zmiddleware.shared_datar�  Údebugr�  Útrusted_hostsro  rƒ  r"  r‚   r�  r»   Úset_inheritabler   Úfilenors  r   rÙ   Z	_reloaderr‘  rg  rV  )r…  r/  r†  r‡  rˆ  r‰  rŠ  r‹  rŒ  r�  r~  r{  r  rŽ  r¶   rf   r�  r�  rK  Zsrvr‘  r   r   r   Ú
run_simpleÁ  sP    p

÷ûr—  )N)NN)NN)N)Fr
   NFNN)FFTNNr
   r„  Fr
   NNFN)RrL   Ú
__future__r   rY  Úior"  rª   r»   Úsocketserverrk   Útypingr,  r   r  r   r   Zhttp.serverr   r   Úurllib.parser   r	   Ú	_internalr   r   Ú
exceptionsr   rS   r   Úurlsr   r|   rº   r©   ÚSSLEOFErrorr   rå   rÿ   r   rñ   r   Ú
__import__r¯   r|  r$   r2  r9  r   rt  ÚOptionalÚUnionr^  r   ÚLiteralZ_TSSLContextArgÚTYPE_CHECKINGZ_typeshed.wsgir'   r(   Z-cryptography.hazmat.primitives.asymmetric.rsar)   Zcryptography.x509r*   Ú	RawIOBaser+   rM   rÙ   r  r  r&  r$  r¼   r4  rA  rG  rN   ÚThreadingMixInrw  ry  r�  rƒ  r—  r   r   r   r   Ú<module>   sÀ   ý



"ÿ>  I ÿ2 ÿ, ÿ
 )      ÷"-             ð