Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
wsgi.cpython-313.pyc128 linesDownload Raw Back to __pycache__
1�

2��j;+���SrSSKrSSKJr SSKrSSKrSSKJr SSKJ	r	 SSKJ3r4 SSKJr SSK
Jr SS	KJrJrJrJrJrJr SS5KJr SSKr\R0(aSSKJr SSKJr S
\S\4Sjr"SS5r \6RBr"g)aWSGI support for the Tornado web framework.7 8WSGI is the Python standard for web servers, and allows for interoperability9between Tornado and other Python web frameworks and servers.10 11This module provides WSGI support via the `WSGIContainer` class, which12makes it possible to run applications using other WSGI frameworks on13the Tornado HTTP server. The reverse is not supported; the Tornado14`.Application` and `.RequestHandler` classes are designed for use with15the Tornado `.HTTPServer` and cannot be used in a generic WSGI16container.17 18�N)�BytesIO)�dummy_executor)�escape)�httputil)�IOLoop)�19access_log)�List�Tuple�Optional�Callable�Any�Dict)�
TracebackType)�Type)�WSGIApplication�s�returnc�R�[U[5(deURS5$)N�latin1)�20isinstance�bytes�decode)rs �RD:\code\apps\devtools\python\user_packages\Python313\site-packages\tornado/wsgi.py�to_wsgi_strr6s$���a�������8�8�H���c��\rSrSrSrSSSS\\RRSS4Sjjr	S	\21RSS4S22jrS	\23RSS4Sjr
S	\24RS\\\44SjrS
\S	\25RSS4SjrSrg)�
WSGIContainer�;a�Makes a WSGI-compatible application runnable on Tornado's HTTP server.26 27.. warning::28 29   WSGI is a *synchronous* interface, while Tornado's concurrency model30   is based on single-threaded *asynchronous* execution.  Many of Tornado's31   distinguishing features are not available in WSGI mode, including efficient32   long-polling and websockets. The primary purpose of `WSGIContainer` is33   to support both WSGI applications and native Tornado ``RequestHandlers`` in34   a single process. WSGI-only applications are likely to be better off35   with a dedicated WSGI server such as ``gunicorn`` or ``uwsgi``.36 37Wrap a WSGI application in a `WSGIContainer` to make it implement the Tornado38`.HTTPServer` ``request_callback`` interface.  The `WSGIContainer` object can39then be passed to classes from the `tornado.routing` module,40`tornado.web.FallbackHandler`, or to `.HTTPServer` directly.41 42This class is intended to let other frameworks (Django, Flask, etc)43run on the Tornado HTTP server and I/O loop.44 45Realistic usage will be more complicated, but the simplest possible example uses a46hand-written WSGI application with `.HTTPServer`::47 48    def simple_app(environ, start_response):49        status = "200 OK"50        response_headers = [("Content-type", "text/plain")]51        start_response(status, response_headers)52        return [b"Hello world!\n"]53 54    async def main():55        container = tornado.wsgi.WSGIContainer(simple_app)56        http_server = tornado.httpserver.HTTPServer(container)57        http_server.listen(8888)58        await asyncio.Event().wait()59 60    asyncio.run(main())61 62The recommended pattern is to use the `tornado.routing` module to set up routing63rules between your WSGI application and, typically, a `tornado.web.Application`.64Alternatively, `tornado.web.Application` can be used as the top-level router65and `tornado.web.FallbackHandler` can embed a `WSGIContainer` within it.66 67If the ``executor`` argument is provided, the WSGI application will be executed68on that executor. This must be an instance of `concurrent.futures.Executor`,69typically a ``ThreadPoolExecutor`` (``ProcessPoolExecutor`` is not supported).70If no ``executor`` is given, the application will run on the event loop thread in71Tornado 6.3; this will change to use an internal thread pool by default in72Tornado 7.0.73 74.. warning::75   By default, the WSGI application is executed on the event loop's thread. This76   limits the server to one request at a time (per process), making it less scalable77   than most other WSGI servers. It is therefore highly recommended that you pass78   a ``ThreadPoolExecutor`` when constructing the `WSGIContainer`, after verifying79   that your application is thread-safe. The default will change to use a80   ``ThreadPoolExecutor`` in Tornado 7.0.81 82.. versionadded:: 6.383   The ``executor`` parameter.84 85.. deprecated:: 6.386   The default behavior of running the WSGI application on the event loop thread87   is deprecated and will change in Tornado 7.0 to use a thread pool by default.88N�wsgi_application�WSGIAppType�executorrc�<�XlUc[UlgUUlg�N)rrr!)�selfrr!s   r�__init__�WSGIContainer.__init__}s��89!1��*2�*:���
���
r�requestc�b�[R"5RURU5 gr#)r�current�spawn_callback�handle_request)r$r's  r�__call__�WSGIContainer.__call__�s������'�'��(;�(;�W�Erc�� ^^^# �0m/mSS[S[[[[4S[[S[[[[904S[[/[44UU4Sjjjn[R"5nURURURURU5U5IShv�Nn[U5mS[[4U4SjjnURURU5IShv�NnUcOTR!U5 M;[#US5(aUR%5 S	R'T5nT(d[)S915eTSR+SS5up�[-U5n92TSnUVV
s1sHup�UR/5iM nnn
[0R2"U5nU93S
:waBSU;a%UR!S[[5U5545 SU;aUR!S5 SU;a$UR!SS[6R8-45 [:R<"SX�5n[:R>"5nUHunnURAUU5 M URBceURBREUUUS9 URBRG5 URIX�5 gGNGN�![#US5(aUR%5 ff=fs sn
nf7f)N�status�headers�exc_infozOptional[Type[BaseException]]rc�0>�UTS'UTS'TR$)Nr/r0)�append)r/r0r1�data�responses   ��r�start_response�4WSGIContainer.handle_request.<locals>.start_response�s!���$�D��N�%�D��O��?�?�"rc�<>�[T5$![a gf=fr#)�next�
StopIteration)�app_response_iters�r�94next_chunk�0WSGIContainer.handle_request.<locals>.next_chunk�s(��� �� 1�2�2��$� � � �s�95�96��closerz$WSGI app did not call start_response� �i0zcontent-length�Content-Lengthzcontent-type)�Content-Typeztext/html; charset=UTF-8�server�ServerzTornadoServer/%szHTTP/1.1)�chunkr#)%�strr	r97r�
BaseExceptionrrrr
rr)�run_in_executorr!r�environ�iterr3�hasattrr>�join�	Exception�split�int�lowerr�utf8�len�tornado�versionr�ResponseStartLine�HTTPHeaders�add�98connection�
write_headers�finish�_log)r$r'r6�loop�app_responser<rE�body�status_code_str�reason�status_coder0�k�v�99header_set�100start_line�101header_obj�key�valuer;r4r5s                   @@@rr+�WSGIContainer.handle_request�s����������
	#��
	#��%��S��/�*�
	#���3��]�+��]�+�-���
	#��u�g�s�l�
#�
	#�
	#��~�~���!�1�1��M�M��!�!��L�L��!��	102�103��	%� $�\� 2��
 ����
 ��"�2�2�4�=�=�*�M�M���=������&�	��|�W�-�-��"�"�$��x�x��!����B�C�C�"&�x�.�"6�"6�s�A�">����/�*���y�/��.5�6�g�F�Q�a�g�g�i�g�104�6��{�{�4� ���#���z�1���� 0�#�c�$�i�.�A�B��Z�/����K�L��:�%��N�N�H�&8�7�?�?�&J�K�L��/�/�105�K�P�106��)�)�+�107�!�J�C���N�N�3��&�"��!�!�-�-�-����(�(��Z�t�(�L����!�!�#��	�	�+�'�c108�$N��109�|�W�-�-��"�"�$�.��7�sK�B=L�K�L�AK!�K�	K!�$A0L�L�0D,L�K!�!$L�	Lc�|�URRS5n[U5S:XaUSn[US5nO URnURS:XaSOSnUR110S[
[R"URS	S111S95URURU[U5URSUR[[R"UR 55["R$UR&[(LS
S112S.nSUR*;aUR*R-S5US'SUR*;aUR*R-S5US'UR*R/5H*upgXuSUR1SS5R35-'M, U$)z~Converts a `tornado.httputil.HTTPServerRequest` to a WSGI environment.113 114.. versionchanged:: 6.3115   No longer a static method.116�:�rr@�httpsi��P�NF)�encoding�plus)r@rT)�REQUEST_METHOD�SCRIPT_NAME�	PATH_INFO�QUERY_STRING�REMOTE_ADDR�SERVER_NAME�SERVER_PORT�SERVER_PROTOCOLzwsgi.versionzwsgi.url_schemez117wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocessz
wsgi.run_oncerB�CONTENT_TYPErA�CONTENT_LENGTH�HTTP_�-�_)�hostrNrRrO�protocol�methodrr�url_unescape�path�query�	remote_iprFrTrrQr^�sys�stderrr!rr0�pop�items�replace�upper)r$r'�hostportr�portrIrgrhs        rrI�WSGIContainer.environ�sq���<�<�%�%�c�*���x�=�A���A�;�D��x��{�#�D��<�<�D�!�*�*�g�5�3�2�D�%�n�n��$��#�#�G�L�L�4�e�L��$�M�M�"�,�,���t�9�&���"�&�/�/�!�&�+�+�g�l�l�";�<��:�:� $�
�
�^� C�!%�"�#118��&�W�_�_�,�&-�o�o�&9�&9�.�&I�G�N�#��w���.�(/���(;�(;�<L�(M�G�$�%�!�/�/�/�/�1�J�C�?D�G�c�k�k�#�s�3�9�9�;�;�<�2��rrac�T�US:a[RnO'US:a[RnO[RnSUR	5-nUR119ceURceUR120S-UR-S-UR-S-nU"SXU5 g)Ni�i�g@�@r?z (�)z%d %s %.2fms)r�info�warning�error�request_timer��urir�)r$rar'�121log_methodr��summarys      rr[�WSGIContainer._log�s������#���J�
�3�
�#�+�+�J�#�)�)�J��� 4� 4� 6�6���~�~�)�)�)��{�{�&�&�&��N�N��
��k�k�
��
����	
 �122�
�	�	�>�;��Fr)r!rr#)�__name__�123__module__�__qualname__�__firstlineno__�__doc__r�124concurrent�futures�Executorr%r�HTTPServerRequestr,r+rrFr
rIrOr[�__static_attributes__�rrrr;s���?�H;?�I�'�I��:�-�-�6�6�7�I�125�	I�F�� :� :�F�t�F�E(�H�,F�,F�E(�4�E(�N&�x�9�9�&�d�3��8�n�&�PG��G�h�.H�.H�G�T�Grr)#r��concurrent.futuresr��iorrSr��tornado.concurrentrrr�tornado.ioloopr�tornado.logr�typingr	r126rrr
r�typesr�
TYPE_CHECKINGr�_typeshed.wsgirr rrFrrr��HTTPRequestr�rr�<module>r�sq�� ����127�-���!�"�=�=��
�	����=��5��S��128NG�NG�b�(�(�r
codekingpro/portable-devtools · Team Ai