HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/ext/tornado/__pycache__/wsgi.cpython-310.pyc
o

�N�g�4�@sHdZddlmZmZmZddlZddlmZddlm	m
Z
ddlmZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZmZerTddlmZnddlZeeuredd
�Zdd�Zndd
�Zdd�ZGdd�dej�Ze�Z e �!d�Gdd�dej"�Z#Gdd�de$�Z%Gdd�de$�Z&Gdd�de$�Z'ej(Z)dS)a�WSGI support for the Tornado web framework.

WSGI is the Python standard for web servers, and allows for interoperability
between Tornado and other Python web frameworks and servers.  This module
provides WSGI support in two ways:

* `WSGIAdapter` converts a `tornado.web.Application` to the WSGI application
  interface.  This is useful for running a Tornado app on another
  HTTP server, such as Google App Engine.  See the `WSGIAdapter` class
  documentation for limitations that apply.
* `WSGIContainer` lets you run other WSGI applications and frameworks on the
  Tornado HTTP server.  For example, with this class you can mix Django
  and Tornado handlers in a single server.
�)�absolute_import�division�print_functionN)�BytesIO)�Future)�escape)�httputil)�
access_log)�web��
native_str)�unicode_type�PY3cC�t|t�sJ�|�d�S�N�latin1)�
isinstance�bytes�decode��s�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/ext/tornado/wsgi.py�to_wsgi_str:�
rcCrr)r�str�encoderrrr�
from_wsgi_str>rrcC�t|t�sJ�|S�N)rrrrrrrB�cCrr)rrrrrrrFr c@seZdZdZdd�ZdS)�WSGIApplicationz�A WSGI equivalent of `tornado.web.Application`.

    .. deprecated:: 4.0

       Use a regular `.Application` and wrap it in `WSGIAdapter` instead.
    cCst|�||�Sr)�WSGIAdapter)�self�environ�start_responserrr�__call__RszWSGIApplication.__call__N)�__name__�
__module__�__qualname__�__doc__r&rrrrr!Ksr!c@s8eZdZdd�Zdd�Zddd�Zd
dd	�Zd
d�ZdS)�_WSGIConnectioncCs.||_||_||_g|_d|_d|_d|_dS)NF)�methodr%�context�
_write_buffer�	_finished�_expected_content_remaining�_error)r#r,r%r-rrr�__init__]s
z_WSGIConnection.__init__cCsdSrr)r#�callbackrrr�set_close_callbackfsz"_WSGIConnection.set_close_callbackNcCs�|jdkr	d|_nd|vrt|d�|_nd|_|�d|j|jfdd�|��D��|dur7|�||�tS|dur>|�tS)N�HEADr�Content-Lengthz%s %scSs g|]\}}t|�t|�f�qSrr��.0�k�vrrr�
<listcomp>ts z1_WSGIConnection.write_headers.<locals>.<listcomp>)	r,r0�intr%�code�reason�get_all�write�
_dummy_future)r#�
start_line�headers�chunkr3rrr�
write_headersks
��z_WSGIConnection.write_headerscCsV|jdur|jt|�8_|jdkrt�d�|_|j�|j�|�|dur)|�tS)Nrz,Tried to write more data than Content-Length)r0�lenr�HTTPOutputErrorr1r.�appendrA)r#rDr3rrrr@{s

�z_WSGIConnection.writecCs6|jdur|jdkrt�d|j�|_|j�d|_dS)Nrz0Tried to write %d bytes less than Content-LengthT)r0rrGr1r/�r#rrr�finish�s

��
z_WSGIConnection.finish)NNr)r'r(r)r2r4rEr@rJrrrrr+\s	

r+c@seZdZdd�Zdd�ZdS)�_WSGIRequestContextcCs||_||_dSr)�	remote_ip�protocol)r#rLrMrrrr2�s
z_WSGIRequestContext.__init__cCs|jSr)rLrIrrr�__str__�sz_WSGIRequestContext.__str__N)r'r(r)r2rNrrrrrK�srKc@s eZdZdZdd�Zdd�ZdS)r"aConverts a `tornado.web.Application` instance into a WSGI application.

    Example usage::

        import tornado.web
        import tornado.wsgi
        import wsgiref.simple_server

        class MainHandler(tornado.web.RequestHandler):
            def get(self):
                self.write("Hello, world")

        if __name__ == "__main__":
            application = tornado.web.Application([
                (r"/", MainHandler),
            ])
            wsgi_app = tornado.wsgi.WSGIAdapter(application)
            server = wsgiref.simple_server.make_server('', 8888, wsgi_app)
            server.serve_forever()

    See the `appengine demo
    <https://github.com/tornadoweb/tornado/tree/stable/demos/appengine>`_
    for an example of using this module to run a Tornado app on Google
    App Engine.

    In WSGI mode asynchronous methods are not supported.  This means
    that it is not possible to use `.AsyncHTTPClient`, or the
    `tornado.auth` or `tornado.websocket` modules.

    .. versionadded:: 4.0
    cs&t�t�r�fdd�|_dS�|_dS)Ncstj��|�Sr)r
�Applicationr&)�request��applicationrr�<lambda>�s�z&WSGIAdapter.__init__.<locals>.<lambda>)rr!rR)r#rRrrQrr2�s

zWSGIAdapter.__init__c
	Csh|d}t�t|�dd���}|t�t|�dd���7}|�d�r)|d|d7}t��}|�d�r8|d|d<|�d	�rC|d	|d
<|D]}|�d�rZ||||dd��d
d�<qE|�d
�rl|d�t	|d
��}nd}|d}|�dd�}	|�d�r�|d}
n|d}
t
||t|	|��}tj||d|||
|d�}|�
�|�|�|jr�|j�|js�td��|jS)N�REQUEST_METHOD�SCRIPT_NAME��	PATH_INFO�QUERY_STRING�?�CONTENT_TYPE�Content-Type�CONTENT_LENGTHr6�HTTP_��_�-�
wsgi.input��wsgi.url_scheme�REMOTE_ADDRZ	HTTP_HOST�SERVER_NAME�HTTP/1.1)rC�body�host�
connectionz$request did not finish synchronously)�urllib_parse�quoter�getr�HTTPHeaders�
startswith�replace�readr<r+rK�HTTPServerRequestZ_parse_bodyrRr1r/�	Exceptionr.)
r#r$r%r,�urirC�keyrgrMrLrhrirPrrrr&�sL



�

�

�
�
zWSGIAdapter.__call__N)r'r(r)r*r2r&rrrrr"�sr"c@s4eZdZdZdd�Zdd�Zedd��Zdd	�Zd
S)�
WSGIContainera�Makes a WSGI-compatible function runnable on Tornado's HTTP server.

    .. warning::

       WSGI is a *synchronous* interface, while Tornado's concurrency model
       is based on single-threaded asynchronous execution.  This means that
       running a WSGI app with Tornado's `WSGIContainer` is *less scalable*
       than running the same app in a multi-threaded WSGI server like
       ``gunicorn`` or ``uwsgi``.  Use `WSGIContainer` only when there are
       benefits to combining Tornado and WSGI in the same process that
       outweigh the reduced scalability.

    Wrap a WSGI function in a `WSGIContainer` and pass it to `.HTTPServer` to
    run it. For example::

        def simple_app(environ, start_response):
            status = "200 OK"
            response_headers = [("Content-type", "text/plain")]
            start_response(status, response_headers)
            return ["Hello world!\n"]

        container = tornado.wsgi.WSGIContainer(simple_app)
        http_server = tornado.httpserver.HTTPServer(container)
        http_server.listen(8888)
        tornado.ioloop.IOLoop.current().start()

    This class is intended to let other frameworks (Django, web.py, etc)
    run on the Tornado HTTP server and I/O loop.

    The `tornado.web.FallbackHandler` class is often useful for mixing
    Tornado and WSGI apps in the same server.  See
    https://github.com/bdarnell/django-tornado-demo for a complete example.
    cCs
||_dSr)�wsgi_application)r#rvrrrr2
s
zWSGIContainer.__init__c
	sli�g�d��fdd�	}|�t�|�|�}z��|�d���}Wt|d�r*|��nt|d�r5|��ww�s<td���d�dd�\}}t	|�}�d	}t
d
d�|D��}t�|�}|dkrxd
|vro|�
dtt|��f�d|vrx|�
d�d|vr�|�
ddtjjjf�t�d||�}	t��}
|D]
\}}|
�||�q�|jj|	|
|d�|j��|�||�dS)Ncs|�d<|�d<�jS)N�statusrC)rH)rwZresponse_headers�exc_info��data�responserrr%sz.WSGIContainer.__call__.<locals>.start_responserb�closez$WSGI app did not call start_responserw� �rCcss�|]	\}}|��VqdSr)�lowerr7rrr�	<genexpr>#s�z)WSGIContainer.__call__.<locals>.<genexpr>i0zcontent-lengthr6zcontent-type)r[ztext/html; charset=UTF-8ZserverZServerzTornadoServer/%srf)rDr)rvrur$�extend�join�hasattrr|rr�splitr<�setr�utf8rHrrF�salt�ext�tornado�versionrZResponseStartLinerm�addrirErJ�_log)
r#rPr%Zapp_responserg�status_coder>rCZ
header_setrBZ
header_objrt�valuerryrr&
sH
�

�
�
�


zWSGIContainer.__call__cCs�|j�d�}t|�dkr|d}t|d�}n|j}|jdkr!dnd}|jdttj|j	d	d
d��|j
|j|t|�|j
d|jtt�|j��tjd
d
d
d�}d|jvrY|j�d�|d<d|jvrf|j�d�|d<|j��D]\}}||d|�dd���<qk|S)zOConverts a `tornado.httputil.HTTPServerRequest` to a WSGI environment.
        �:�rr~�httpsi��PrVNF)�encodingZplus)r~rT)rTrUrWrXrdreZSERVER_PORTZSERVER_PROTOCOLzwsgi.versionrcrazwsgi.errorszwsgi.multithreadzwsgi.multiprocessz
wsgi.run_oncer[rZr6r\r]r`r_)rhr�rFr<rMr,rrZurl_unescape�path�queryrLrr�rr�rg�sys�stderrrC�pop�itemsro�upper)rPZhostportrh�portr$rtr�rrrr$5s>��

zWSGIContainer.environcCsb|dkrtj}n|dkrtj}ntj}d|��}|jd|jd|jd}|d|||�dS)Ni�i�g@�@r}z (�)z%d %s %.2fms)r	�info�warning�error�request_timer,rsrL)r#r�rPZ
log_methodr�Zsummaryrrrr�Zs��zWSGIContainer._logN)	r'r(r)r*r2r&�staticmethodr$r�rrrrru�s!(
$ru)*r*Z
__future__rrrr��iorZsalt.ext.tornador�r�Zsalt.ext.tornado.concurrentrrrZsalt.ext.tornado.logr	r
Zsalt.ext.tornado.escaperZsalt.ext.tornado.utilr
r�urllib.parse�parserj�urllibrrrrOr!rAZ
set_result�HTTPConnectionr+�objectrKr"rurqZHTTPRequestrrrr�<module>s8

5	N