U
    ÌZj:–  ã                   @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddl	m	Z
 ddl	mZ ddl	mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ zddlZW n( ek
rô   G dd„ dƒZeƒ ZY nX dZejdk�r.zedƒ W n ek
�r,   dZY nX eedƒZ e �rFej!Z!nG dd„ dƒZ!z
ej"Z#W n e$k
�rx   dZ#Y nX dZ%ej&ej'dej(e)ej&e) f df  Z*ej+�räddl,Z-ddl.m/Z/ ddl.m0Z0 ddl1m2Z2 ddl3m4Z4 G dd „ d ej5ƒZ6G d!d"„ d"eƒZ7e)e)e)d#œd$d%„Z8dRej&e) ej(d& d'œd(d)„Z9dSe)ej&e) ej&e) ej(e)e)f d*œd+d,„Z:dd-œd.d/„Z;dTe)ej&e) ej&e< dd0œd1d2„Z=dUej&e> e?d3œd4d5„Z@e)e<ejAd6œd7d8„ZBe)e<ejAej'ej(e)e<f e)f d9œd:d;„ZCejAe)d<œd=d>„ZDG d?d@„ d@eƒZEG dAdB„ dBejFeEƒZGG dCdD„ dDe!eEƒZHdVe)e<dEe?e<ej&ejIe7  e?ej&e* ej&e< eEdFœ
dGdH„ZJe?d-œdIdJ„ZKe)e<ejdKœdLdM„ZLdWe)e<dEe?e?e?ej&ejMe)  ej&ejMe)  e<e)e?e<ej&ejIe7  ej&ejNe)ej'e)ej(e)e)f f f  e?ej&e* ddOœdPdQ„ZOdS )XaØ  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                   @   s   e Zd Zeejdœdd„ZdS )Ú	_SslDummy©Ú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   úS/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/werkzeug/serving.pyÚ__getattr__'   s    ÿz_SslDummy.__getattr__N)Ú__name__Ú
__module__Ú__qualname__ÚstrÚtÚAnyr   r   r   r   r   r   &   s   r   TÚntZcoloramaFÚforkc                   @   s   e Zd ZdS )ÚForkingMixInN)r   r   r   r   r   r   r   r!   =   s   r!   é€   zssl.SSLContextzte.Literal['adhoc'])ÚWSGIApplication)ÚWSGIEnvironment)ÚRSAPrivateKeyWithSerialization)ÚCertificatec                   @   sR   e Zd ZdZeje ddœdd„Zedœdd„Z	e
dœd	d
„Zee
dœdd„ZdS )ÚDechunkedInputz8An input stream that handles Transfer-Encoding 'chunked'N)Úrfiler   c                 C   s   || _ d| _d| _d S )NFr   )Ú_rfileÚ_doneÚ_len)r   r(   r   r   r   Ú__init__Y   s    zDechunkedInput.__init__©r   c                 C   s   dS )NTr   ©r   r   r   r   Úreadable^   s    zDechunkedInput.readablec              
   C   sd   z"| j  ¡  d¡}t| ¡ dƒ}W n, tk
rN } ztdƒ|‚W 5 d }~X Y nX |dk r`tdƒ‚|S )NÚlatin1é   zInvalid chunk headerr   z!Negative chunk length not allowed)r)   ÚreadlineÚdecodeÚintÚstripÚ
ValueErrorÚOSError)r   Úliner+   Úer   r   r   Úread_chunk_lena   s    zDechunkedInput.read_chunk_len)Ú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krtdƒ‚q|S )Nr   T)ó   
ó   
ó   z!Missing chunk terminating newline)	r*   Úlenr+   r:   Úminr)   Úreadr2   r7   )r   r;   rA   ÚnÚ
terminatorr   r   r   Úreadintok   s(    







zDechunkedInput.readinto)r   r   r   Ú__doc__r   ÚIOÚbytesr,   Úboolr/   r4   r:   Ú	bytearrayrD   r   r   r   r   r'   V   s
   
r'   c                       s  e Zd ZU dZded< eedœdd„ƒZddœdd	„Zd
dœdd„Z	d
dœ‡ fdd„Z
d%eejd d
dœdd„Zeejdœ‡ fdd„Zedœdd„Zedœdd„Zd&ejeef ejeef d
dœdd„Zeejd
dœdd„Zeejd
dœd d!„Zeeejd
d"œd#d$„Z‡  ZS )'ÚWSGIRequestHandlerz3A request handler that implements WSGI dispatching.ÚBaseWSGIServerÚserverr-   c                 C   s   ddl m} d|› �S )Nr   )Ú__version__z	Werkzeug/)Ú rM   )r   rM   r   r   r   Úserver_version™   s    z!WSGIRequestHandler.server_versionr$   c                 C   s  t | jƒ}| jjd k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 ]\\}}| ¡  dd¡}| dd¡}|dk�rDd|› �}||k�rD|| › d|› �}|||< qð| dd¡ ¡  ¡ dk�r€d|d< t|d ƒ|d< |j�rš|j�rš|j|d< z*| jj dd�}|d k	�rÂt! "|¡|d< W n8 t#k
�rè   | j $dd¡ Y n t%k
�rü   Y nX |S )NÚhttpÚhttps)ú<local>r   r   ú/)r   r   FrN   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_INFOZQUERY_STRINGZREQUEST_URIZRAW_URIÚREMOTE_ADDRZREMOTE_PORTZSERVER_NAMEZSERVER_PORTZSERVER_PROTOCOLú-Ú_z
)ZCONTENT_TYPEZCONTENT_LENGTHZHTTP_ú,ZHTTP_TRANSFER_ENCODINGÚchunkedTzwsgi.input_terminatedrT   Z	HTTP_HOST)Úbinary_formZSSL_CLIENT_CERTÚerrorz&Cannot fetch SSL peer certificate info)&r   ÚpathrL   Ússl_contextÚclient_addressÚ
isinstancer   ÚschemeÚnetlocr   r(   ÚsysÚstderrÚmultithreadÚmultiprocessÚ
connectionrO   Úcommandr
   ÚqueryÚaddress_stringÚport_integerÚserver_addressÚrequest_versionÚheadersÚitemsÚupperÚreplaceÚgetr5   Úlowerr'   ÚgetpeercertÚsslÚDER_cert_to_PEM_certr6   ÚlogÚAttributeError)r   Úrequest_urlÚ
url_schemeZ	path_infoÚenvironÚkeyÚvalueZ	peer_certr   r   r   Úmake_environŸ   sn    

ê




ÿ
zWSGIRequestHandler.make_environNc                    sŠ  ˆj  dd¡ ¡  ¡ dkr&ˆj d¡ ˆ ¡  ˆ_‰d ‰d ‰d ‰d ‰d‰ td dœ‡ ‡‡‡‡‡‡fdd„‰d‡‡‡‡fd	d
„	‰dd dœ‡ ‡‡‡‡‡fdd„}z|ˆj	j
ƒ W nÚ ttjfk
rÞ } zˆ |ˆ¡ W 5 d }~X Y n¨ tk
�r„ } zˆˆj	jrú‚ ˆd k	�rˆ �rdˆ_z ˆd k�r$d ‰d ‰|tƒ ƒ W n tk
�rF   Y nX ddlm} ||ƒ ¡ }ˆj	 dd|› �¡ W 5 d }~X Y nX d S )NZExpectrN   z100-continues   HTTP/1.1 100 Continue

F)Údatar   c                    s€  ˆd k	st dƒ‚ˆd k	s t dƒ‚ˆd k�rˆ‰ˆ‰zˆ d d¡\}}W n tk
rd   ˆd }}Y nX t|ƒ}ˆ ||¡ tƒ }ˆD ]"\}}ˆ ||¡ | | ¡ ¡ q„d|ksôˆd dksôd|  krÐdk sôn |d	ksôˆj	d
krôd‰ ˆ dd¡ ˆ dd¡ ˆ 
¡  t| tƒ�st dƒ‚| �rrˆ �rTˆj tt| ƒƒdd …  ¡ ¡ ˆj d¡ ˆj | ¡ ˆ �rrˆj d¡ ˆj ¡  d S )Nzwrite() before start_responser   rN   zcontent-lengthrV   ÚHEADéd   éÈ   >   é0  éÌ   úHTTP/1.1TzTransfer-Encodingr[   Ú
ConnectionÚclosezapplications must write bytesé   r=   )ÚAssertionErrorÚsplitr6   r4   Zsend_responseÚsetZsend_headerÚaddrt   Úprotocol_versionZend_headersra   rG   ÚwfileÚwriteÚhexr?   ÚencodeÚflush)r€   Zcode_strÚmsgÚcodeÚheader_keysr}   r~   )Úchunk_responser|   Úheaders_sentÚheaders_setr   Ústatus_sentÚ
status_setr   r   r�   ú   sR    

þ
ý üüûù	 z*WSGIRequestHandler.run_wsgi.<locals>.writec                    s@   |r(zˆ r|d   |d ¡‚W 5 d }X nˆr4tdƒ‚| ‰|‰ˆS )Nr   r‰   zHeaders already set)Úwith_tracebackrŠ   )Ústatusro   Úexc_info)r˜   r™   r›   r�   r   r   Ústart_response3  s    z3WSGIRequestHandler.run_wsgi.<locals>.start_responser#   )Úappr   c              	      sV   | ˆˆƒ}z2|D ]}ˆ|ƒ qˆs*ˆdƒ ˆ r:ˆj d¡ W 5 t |dƒrP| ¡  X d S )Nrˆ   ó    s   0

)Úhasattrrˆ   r�   r�   )r    Zapplication_iterr€   )r—   r|   r˜   r   rŸ   r�   r   r   ÚexecuteA  s    


z,WSGIRequestHandler.run_wsgi.<locals>.executeTr   )ÚDebugTracebackr]   zError on request:
)N)ro   rs   rt   r5   r�   r�   r   r|   rG   rL   r    ÚConnectionErrorÚsocketÚtimeoutÚconnection_droppedÚ	ExceptionÚpassthrough_errorsZclose_connectionr   Zdebug.tbtoolsr¤   Zrender_traceback_textrx   )r   r£   r9   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 nv ttjfk
r@ } z|  |¡ W 5 d}~X Y nF tk
r„ } z(| jjdk	rrt	|ƒrr|  
d|¡ n‚ W 5 d}~X Y nX dS )z/Handles a request ignoring dropped connections.NzSSL error occurred: %s)ÚsuperÚhandler¥   r¦   r§   r¨   r©   rL   r_   Úis_ssl_errorÚ	log_error)r   r9   ©Ú	__class__r   r   r­   h  s    zWSGIRequestHandler.handle)r]   r|   r   c                 C   s   dS )z`Called if the connection was closed by the client.  By default
        nothing happens.
        Nr   )r   r]   r|   r   r   r   r¨   t  s    z%WSGIRequestHandler.connection_droppedr   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|   rW   rR   r   )r³   r|   r`   r.   r   r   r   rk   ƒ  s
    
z!WSGIRequestHandler.address_stringc                 C   s
   | j d S )Nr   )r`   r.   r   r   r   rl   Œ  s    zWSGIRequestHandler.port_integerrX   )r•   Úsizer   c                 C   sè   z&t | jƒ}| j› d|› d| j› �}W n tk
r@   | j}Y nX t|ƒ}|d dkrbt|dƒ}np|dkrlnf|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   r^   ri   rn   ry   Zrequestliner   Ú_ansi_stylerx   )r   r•   r´   r^   r”   r   r   r   Úlog_request�  s(    
zWSGIRequestHandler.log_request)ÚformatÚargsr   c                 G   s   | j d|f|žŽ  d S )Nr]   ©rx   ©r   rÂ   rÃ   r   r   r   r¯   ¬  s    zWSGIRequestHandler.log_errorc                 G   s   | j d|f|žŽ  d S )Nr¿   rÄ   rÅ   r   r   r   Úlog_message¯  s    zWSGIRequestHandler.log_message©ÚtypeÚmessagerÃ   r   c                 G   s.   t ||  ¡ › d|  ¡ › d|› d�f|žŽ  d S )Nz - - [z] Ú
)r	   rk   Zlog_date_time_string©r   rÈ   rÉ   rÃ   r   r   r   rx   ²  s    þýzWSGIRequestHandler.log)N)rX   rX   )r   r   r   rE   Ú__annotations__Úpropertyr   rO   r   r«   r­   ÚBaseExceptionr   ÚOptionalr¨   r   r   rk   r4   rl   ÚUnionrÁ   r¯   rÆ   rx   Ú__classcell__r   r   r°   r   rJ   ”   s4   
Py ÿ þ	   ÿ þrJ   )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¸   z[Úmz[0m)Ú_log_add_style)r~   rÒ   ÚcodesÚstyler   r   r   rÀ   º  s    ú	rÀ   )r&   r%   )Úcnr   c           
      C   s:  z@ddl m} ddlm} ddlm} ddlm} ddlm	} W n t
k
r^   tdƒd ‚Y nX |ƒ }|jdd	|d
�}| d kr‚d} | | |jd¡| |j| ¡g¡}|ƒ }| ¡  |¡ |¡ | ¡ ¡ | ¡ ¡ t tj¡¡ t tj¡tdd� ¡j| |j g¡dd�j| !| "| ¡g¡dd� #|| $¡ |¡}	|	|fS )Nr   )Úx509)ÚNameOID)Údefault_backend)Úhashes)Úrsaz<Using ad-hoc certificates requires the cryptography library.i  i   )Zpublic_exponentZkey_sizeÚbackendÚ*zDummy Certificateim  )ÚdaysF)Úcritical)%ZcryptographyrÝ   Zcryptography.x509.oidrÞ   Zcryptography.hazmat.backendsrß   Úcryptography.hazmat.primitivesrà   Z)cryptography.hazmat.primitives.asymmetricrá   Ú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Í  sf    ÿþ  ÿþÿÿþýü
ûú ù ø	  ÷ÿró   )Ú	base_pathÚhostrÜ   r   c           	   	   C   s°   |dk	rd|› d|› �}t |d�\}}ddlm} | › d�}| › d�}t|d	ƒ�}| | |jj¡¡ W 5 Q R X t|d	ƒ�(}| |j|jj|j	j
| ¡ d
�¡ W 5 Q R X ||fS )aÂ  Creates an SSL key for development.  This should be used instead of
    the ``'adhoc'`` key which generates a new cert on each server start.
    It accepts a path for where it should store the key and cert and
    either a host or CN.  If a host is given it will use the CN
    ``*.host/CN=host``.

    For more information see :func:`run_simple`.

    .. versionadded:: 0.9

    :param base_path: the path to the certificate and key.  The extension
                      ``.crt`` is added for the certificate, ``.key`` is
                      added for the key.
    :param host: the name of the host.  This can be used as an alternative
                 for the `cn`.
    :param cn: the `CN` to use.
    Nz*.z/CN=)rÜ   r   ©Úserializationz.crtz.keyÚwb©ÚencodingrÂ   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"    

ýÿr  r-   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ù   )ÚtempfileÚatexitró   ræ   r÷   ÚmkstempÚregisterÚ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_context'  s*    
ýþ	


r  )r  r  Úprotocolr   c                 C   s(   |dk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)rv   ÚPROTOCOL_TLS_SERVERÚ
SSLContextÚload_cert_chain)r  r  r  r  r   r   r   r  E  s
    
r  )r]   r   c                 C   s(   | dkrt  tt ¡ d ¡} t| tjƒS )z?Checks if the given error (or the current one) is an SSL error.Nr   )r   Úcastr©   rd   rž   ra   rv   ÚSSLError)r]   r   r   r   r®   Z  s    r®   )rõ   Úportr   c                 C   s.   |   d¡rtjS d| k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)rõ   r  r   r   r   Úselect_address_familya  s
    
r  )rõ   r  Úfamilyr   c                 C   s^   |t kr|  dd¡d S zt | ||tjtj¡}W n tjk
rP   | |f Y S X |d d S )zVReturn a fully qualified socket address that can be passed to
    :func:`socket.bind`.ú://r   r   é   )Úaf_unixr‹   r¦   ÚgetaddrinfoÚSOCK_STREAMÚIPPROTO_TCPÚgaierror)rõ   r  r  Úresr   r   r   Úget_sockaddrk  s        ÿr%  )r  r   c              
   C   sŠ   | t jkrdnd}t   | t j¡�`}z| |df¡ W n2 tk
rf   | t jkrRdnd Y W  5 Q R £ S X | ¡ d W  5 Q R £ S Q R X 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.1r   N)r¦   r  Ú
SOCK_DGRAMÚconnectr7   Úgetsockname)r  rõ   Úsr   r   r   Úget_interface_ip{  s    $r+  c                
       sÀ   e Zd ZdZdZdZeZdee	de
je
je  ee
je e
je	 ddœ‡ fdd„Zeee
jddœd	d
„Zdeddœ‡ fdd„Ze
je
je
jee	f ef ddœ‡ fdd„Zddœdd„Z‡  ZS )rK   zuA WSGI server that that handles one request at a time.

    Use :func:`make_server` to create a server instance.
    FNr#   )rõ   r  r    Úhandlerrª   r_   Úfdr   c           
         sl  |d krt }dt|ƒkr*| js$| jr*d|_|| _|| _|| _|| _t	||ƒ | _
}t|t|ƒ|ƒ}	|tkr”|d kr”t t|	¡}	tj |	¡r”t |	¡ tƒ j|	|dd� |d kräz|  ¡  |  ¡  W n tk
rà   |  ¡  ‚ Y nX nt ||tj¡| _| j ¡ | _|tk�r| jd | _|d k	�rbt |t!ƒ�r8t"|Ž }n|dk�rHt#ƒ }|j$| jdd�| _|| _%nd | _%d S )	NrŽ   r†   F)Úbind_and_activater   ZadhocT)Úserver_side)&rJ   Úvarsrf   rg   rŽ   rõ   r  r    rª   r  Úaddress_familyr%  r4   r  r   r  r   r  r^   ÚexistsÚunlinkr¬   r,   Úserver_bindÚserver_activaterÎ   Úserver_closer¦   Úfromfdr!  r)  rm   ra   Útupler  r  Úwrap_socketr_   )
r   rõ   r  r    r,  rª   r_   r-  r1  rm   r°   r   r   r,   —  sT    
ÿÿ
ý




zBaseWSGIServer.__init__rÇ   c                 G   s   t ||f|žŽ  d S ©Nr   rË   r   r   r   rx   à  s    zBaseWSGIServer.logç      à?)Úpoll_intervalr   c                    s<   z,ztƒ j|d� W n tk
r(   Y nX W 5 |   ¡  X d S )N)r<  )r6  r¬   Úserve_foreverÚKeyboardInterrupt)r   r<  r°   r   r   r=  ã  s
    
zBaseWSGIServer.serve_forever)Úrequestr`   r   c                    s   | j r‚ tƒ  ||¡S r:  )rª   r¬   Úhandle_error)r   r?  r`   r°   r   r   r@  ë  s    zBaseWSGIServer.handle_errorr-   c                 C   sö   d}t |ddƒ}|g}| jtkr4| d| j› �¡ n®| jdkrBdnd}| j}| jdkr°| d	| j› d
�¡ | jdkr„d}ttjƒ}nd}ttj	ƒ}| d|› d|› d| j
› �¡ d|k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 NrP   rQ   >   ú::ú0.0.0.0z * Running on all addresses (ú)rB  r&  z[::1]r  r  ú[ú]r¿   rÊ   )rÀ   r1  r  Úappendrõ   r_   r+  r¦   r  r  r  r	   Újoin)r   Zdev_warningÚmessagesrb   Zdisplay_hostnameÚ	localhostr   r   r   Úlog_startupó  s(    ÿ



zBaseWSGIServer.log_startup)NFNN)r;  )r   r   r   rE   rf   rg   ÚLISTEN_QUEUEÚrequest_queue_sizer   r4   r   rÏ   ÚTyperJ   rH   Ú_TSSLContextArgr,   r   rx   Úfloatr=  rÐ   ÚTupler@  rJ  rÑ   r   r   r°   r   rK   �  s2       ø÷I	 þrK   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   rE   rf   Údaemon_threadsr   r   r   r   rQ    s   rQ  c                       sT   e Zd ZdZdZd
eedeejej	e
  eeje eje 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#   )	rõ   r  r    Ú	processesr,  rª   r_   r-  r   c	           	   	      s.   t stdƒ‚tƒ  |||||||¡ || _d S )Nz'Your platform does not support forking.)Úcan_forkr6   r¬   r,   Úmax_children)	r   rõ   r  r    rU  r,  rª   r_   r-  r°   r   r   r,   *  s    zForkingWSGIServer.__init__)rT  NFNN)r   r   r   rE   rg   r   r4   r   rÏ   rM  rJ   rH   rN  r,   rÑ   r   r   r°   r   rS  !  s$        ÷örS  r#   )
rõ   r  r    ÚthreadedrU  Úrequest_handlerrª   r_   r-  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.©r-  )r6   rQ  rS  rK   )	rõ   r  r    rX  rU  rY  rª   r_   r-  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|   rs   r   r   r   r   Úis_running_from_reloaderi  s    r]  )Úhostnamer  r   c              
   C   s  t | |ƒ}t| ||ƒ}t |tj¡}| tjtjd¡ | d¡ |tkrjt	 
t|¡}tj |¡rjt |¡ z| |¡ W n~ tk
rö } z`t|jtjd� |jtjkrÜtd|› d�tjd� tjdkrÜ|dkrÜtdtjd� t d¡ W 5 d	}~X Y nX | t¡ |S )
aå  Prepare a socket for use by the WSGI server and reloader.

    The socket is marked inheritable so that it can be kept across
    reloads instead of breaking connections.

    Catch errors during bind and show simpler error messages. For
    "address already in use", show instructions for resolving the issue,
    with special instructions for macOS.

    This is called from :func:`run_simple`, but can be used separately
    to control server creation with :func:`make_server`.
    r   T)Ú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.N)r  r%  r¦   r!  Ú
setsockoptÚ
SOL_SOCKETÚSO_REUSEADDRÚset_inheritabler  r   r  r   r  r^   r2  r3  Úbindr7   ÚprintÚstrerrorrd   re   ÚerrnoZ
EADDRINUSEÚplatformÚexitÚlistenrK  )r^  r  r1  rm   r*  r9   r   r   r   Úprepare_socketr  s4    



üý
rl  Úauto)r^  r  ÚapplicationÚuse_reloaderÚuse_debuggerÚ
use_evalexÚextra_filesÚexclude_patternsÚreloader_intervalÚreloader_typerX  rU  rY  Ústatic_filesrª   r_   r   c                 C   sð   t |tƒstdƒ‚|r,ddlm} |||ƒ}|rHddlm} |||d�}tƒ sxt| |ƒ}| 	¡ }| 
¡  t|ƒtjd< nttjd ƒ}t| |||
|||||d�	}tƒ s¾| ¡  tdtd	d
ƒƒ |räddlm} ||j||||	d� 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 serve crash instead. If ``use_debugger``
        is enabled, the debugger will still catch such errors.
    :param ssl_context: Configure TLS to serve over HTTPS. Can be an
        :class:`ssl.SSLContext` object, a ``(cert_file, key_file)``
        tuple to create a typical context, or the string ``'adhoc'`` to
        generate a temporary self-signed certificate.

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

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

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

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

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

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

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

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

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

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

    .. versionchanged:: 0.5
       The ``static_files`` and ``passthrough_errors`` parameters were
       added.
    zport must be an integerr   )ÚSharedDataMiddleware)ÚDebuggedApplication)ZevalexZWERKZEUG_SERVER_FDrZ  r¿   zPress CTRL+C to quitr»   )Úrun_with_reloader)rr  rs  Úintervalru  N)ra   r4   rè   Zmiddleware.shared_datarw  Údebugrx  r]  rl  ÚfilenoÚdetachr   r  r|   r[  rJ  r	   rÀ   Z	_reloaderry  r=  )r^  r  rn  ro  rp  rq  rr  rs  rt  ru  rX  rU  rY  rv  rª   r_   rw  rx  r*  r-  Zsrvry  r   r   r   Ú
run_simple¨  sL    p


÷ûr~  )N)NN)NN)N)Fr   NFNN)FFTNNr   rm  Fr   NNFN)PrE   rh  Úior  r¦   Úsocketserverrd   Útypingr   r   rê   r   r   Zhttp.serverr   r   Ú	_internalr	   r
   Ú
exceptionsr   Úurlsr   r   r   rv   rç   r   rÙ   r   Ú
__import__r¢   rV  r!   r  r  ry   rK  rÏ   rÐ   rP  r   rN  ÚTYPE_CHECKINGÚtyping_extensionsÚteZ_typeshed.wsgir#   r$   Z-cryptography.hazmat.primitives.asymmetric.rsar%   Zcryptography.x509r&   Ú	RawIOBaser'   rJ   rÀ   ró   r  r  r4   r  r©   rH   r®   ÚAddressFamilyr  r%  r+  rK   ÚThreadingMixInrQ  rS  rM  r[  r]  rl  ÚIterableÚDictr~  r   r   r   r   Ú<module>   s  



ÿ>  ( ÿþ/   ÿ  þ,   ÿ  þ  þ 
      ÷ö-	:             ð&ï