Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
httpserver.cpython-313.pyc192 linesDownload Raw Back to __pycache__
1�

2��j�@���SrSSKrSSKrSSKJr SSKJrJr SSKJ	r	 SSKJ3r4 SSKJr SSKJ
r
 SS	KJr SSKrSS5KJrJrJrJrJrJrJrJrJr \R4(aSSKJr "SS
\
\\	R85r"SS\	R<5r"SS5r "SS\	R<5r!\	RDr#g)a�A non-blocking, single-threaded HTTP server.6 7Typical applications have little direct interaction with the `HTTPServer`8class except to start a server at the beginning of the process9(and even that is often done indirectly via `tornado.web.Application.listen`).10 11.. versionchanged:: 4.012 13   The ``HTTPRequest`` class that used to live in this module has been moved14   to `tornado.httputil.HTTPServerRequest`.  The old name remains as an alias.15�N)�16native_str)�HTTP1ServerConnection�HTTP1ConnectionParameters)�httputil)�iostream)�netutil)�	TCPServer)�Configurable)	�Union�Any�Dict�Callable�List�Type�Tuple�Optional�	Awaitable)�Setc���\rSrSrSrS\S\SS4SjrS!S\\R\17\R/S44S	\S18\S\
\\\\4\R"4S\
\S
\S\
\S\
\S\
\S\
\S\
\S\
\S\
\\SS4Sjjr\S\\4Sj5r\S\\4Sj5rS"SjrS\R:S\SS4SjrS\ S\RBS\RD4Sjr#S\ SS4Sjr$S r%g)#�19HTTPServer�.a�A non-blocking, single-threaded HTTP server.20 21A server is defined by a subclass of `.HTTPServerConnectionDelegate`,22or, for backwards compatibility, a callback that takes an23`.HTTPServerRequest` as an argument. The delegate is usually a24`tornado.web.Application`.25 26`HTTPServer` supports keep-alive connections by default27(automatically for HTTP/1.1, or for HTTP/1.0 when the client28requests ``Connection: keep-alive``).29 30If ``xheaders`` is ``True``, we support the31``X-Real-Ip``/``X-Forwarded-For`` and32``X-Scheme``/``X-Forwarded-Proto`` headers, which override the33remote IP and URI scheme/protocol for all requests.  These headers34are useful when running Tornado behind a reverse proxy or load35balancer.  The ``protocol`` argument can also be set to ``https``36if Tornado is run behind an SSL-decoding proxy that does not set one of37the supported ``xheaders``.38 39By default, when parsing the ``X-Forwarded-For`` header, Tornado will40select the last (i.e., the closest) address on the list of hosts as the41remote host IP address.  To select the next server in the chain, a list of42trusted downstream hosts may be passed as the ``trusted_downstream``43argument.  These hosts will be skipped when parsing the ``X-Forwarded-For``44header.45 46To make this server serve SSL traffic, send the ``ssl_options`` keyword47argument with an `ssl.SSLContext` object. For compatibility with older48versions of Python ``ssl_options`` may also be a dictionary of keyword49arguments for the `ssl.SSLContext.wrap_socket` method.::50 51   ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)52   ssl_ctx.load_cert_chain(os.path.join(data_dir, "mydomain.crt"),53                           os.path.join(data_dir, "mydomain.key"))54   HTTPServer(application, ssl_options=ssl_ctx)55 56`HTTPServer` initialization follows one of three patterns (the57initialization methods are defined on `tornado.tcpserver.TCPServer`):58 591. `~tornado.tcpserver.TCPServer.listen`: single-process::60 61        async def main():62            server = HTTPServer()63            server.listen(8888)64            await asyncio.Event().wait()65 66        asyncio.run(main())67 68   In many cases, `tornado.web.Application.listen` can be used to avoid69   the need to explicitly create the `HTTPServer`.70 71   While this example does not create multiple processes on its own, when72   the ``reuse_port=True`` argument is passed to ``listen()`` you can run73   the program multiple times to create a multi-process service.74 752. `~tornado.tcpserver.TCPServer.add_sockets`: multi-process::76 77        sockets = bind_sockets(8888)78        tornado.process.fork_processes(0)79        async def post_fork_main():80            server = HTTPServer()81            server.add_sockets(sockets)82            await asyncio.Event().wait()83        asyncio.run(post_fork_main())84 85   The ``add_sockets`` interface is more complicated, but it can be used with86   `tornado.process.fork_processes` to run a multi-process service with all87   worker processes forked from a single parent.  ``add_sockets`` can also be88   used in single-process servers if you want to create your listening89   sockets in some way other than `~tornado.netutil.bind_sockets`.90 91   Note that when using this pattern, nothing that touches the event loop92   can be run before ``fork_processes``.93 943. `~tornado.tcpserver.TCPServer.bind`/`~tornado.tcpserver.TCPServer.start`:95   simple **deprecated** multi-process::96 97        server = HTTPServer()98        server.bind(8888)99        server.start(0)  # Forks multiple sub-processes100        IOLoop.current().start()101 102   This pattern is deprecated because it requires interfaces in the103   `asyncio` module that have been deprecated since Python 3.10. Support for104   creating multiple processes in the ``start`` method will be removed in a105   future version of Tornado.106 107.. versionchanged:: 4.0108   Added ``decompress_request``, ``chunk_size``, ``max_header_size``,109   ``idle_connection_timeout``, ``body_timeout``, ``max_body_size``110   arguments.  Added support for `.HTTPServerConnectionDelegate`111   instances as ``request_callback``.112 113.. versionchanged:: 4.1114   `.HTTPServerConnectionDelegate.start_request` is now called with115   two arguments ``(server_conn, request_conn)`` (in accordance with the116   documentation) instead of one ``(request_conn)``.117 118.. versionchanged:: 4.2119   `HTTPServer` is now a subclass of `tornado.util.Configurable`.120 121.. versionchanged:: 4.5122   Added the ``trusted_downstream`` argument.123 124.. versionchanged:: 5.0125   The ``io_loop`` argument has been removed.126�args�kwargs�returnNc��g�N�)�selfrrs   �XD:\code\apps\devtools\python\user_packages\Python313\site-packages\tornado/httpserver.py�__init__�HTTPServer.__init__�s��	
��request_callback�
no_keep_alive�xheaders�ssl_options�protocol�decompress_request�127chunk_size�max_header_size�idle_connection_timeout�body_timeout�
max_body_size�max_buffer_size�trusted_downstreamc128��XlX0lXPl[UUUU	=(d SUU129US9Ul[130R"UUUUS9 [5UlX�l	g)Ni)�131decompressr)r*�header_timeoutr-r,r$)r&r.�read_chunk_size)132r#r%r'r�conn_paramsr	r �set�_connectionsr/)rr#r$r%r&r'r(r)r*r+r,r-r.r/s              r�133initialize�HTTPServer.initialize�si��.!1�� �
� �
�4�)�!�+�2�:�d�'�%�'�134���	����#�+�&�		135� �E���"4�r"c��[$r�r��clss r�configurable_base�HTTPServer.configurable_base�����r"c��[$rr:r;s r�configurable_default�HTTPServer.configurable_default�r?r"c���# �UR(aJ[[UR55nUR5IShv�N UR(aMIggN7f)a�Close all open connections and asynchronously wait for them to finish.136 137This method is used in combination with `~.TCPServer.stop` to138support clean shutdowns (especially for unittests). Typical139usage would call ``stop()`` first to stop accepting new140connections, then ``await close_all_connections()`` to wait for141existing connections to finish.142 143This method does not currently close open websocket connections.144 145Note that this method is a coroutine and must be called with ``await``.146 147N)r6�next�iter�close)r�conns  r�close_all_connections� HTTPServer.close_all_connections�sG��������T�.�.�/�0�D��*�*�,�������
�s�AA!�A�A!�A!�stream�addressc���[XURUR5n[XRU5nUR148R
U5 URU5 gr)�_HTTPRequestContextr'r/rr4r6�add�
start_serving)rrJrK�contextrGs     r�
handle_stream�HTTPServer.handle_stream�sS��%��T�]�]�D�,C�,C�149��%�V�-=�-=�w�G�������d�#����4� r"�server_conn�request_connc���[UR[R5(aURR	X5nO[URU5nUR(a[X25nU$r)�150isinstancer#r�HTTPServerConnectionDelegate�
start_request�_CallableAdapterr%�
_ProxyAdapter)rrSrT�delegates    rrX�HTTPServer.start_request�s[���d�+�+�X�-R�-R�S�S��,�,�:�:�;�U�H�'��(=�(=�|�L�H��=�=�$�X�<�H��r"c�l�URR[R"[U55 gr)r6�remove�typing�castr)rrSs  r�on_close�HTTPServer.on_closes"����� � ����-B�K�!P�Qr")r6r4r'r#r/r%)FFNNFNNNNNNN�rN)&�__name__�151__module__�__qualname__�__firstlineno__�__doc__rr rrrWr�HTTPServerRequest�boolrr
�str�ssl�152SSLContext�int�floatrr7�classmethodrr153r=rArHr�IOStreamrrQ�object�HTTPConnection�HTTPMessageDelegaterXra�__static_attributes__rr"rrr.s���k�Z
�c�
�S�
�T�
�$��GK�"&�#(�$(�)-�37�(,�'+�)-�26�#*5���1�1��h�0�0�1�4�7�8�
:�154�*5��
*5��*5��e�D��c��N�C�N�N�$B�C�D�*5��3�-�*5�!�*5��S�M�*5�"�#��*5�"*�%��*5��u�o�*5� ��}�*5� "�#��!*5�"%�T�#�Y�/�#*5�$155�%*5�X��$�|�"4������T�,�%7�����&!�H�$5�$5�!��!�$�!��!��19�1H�1H��	�	%�	%��R�F�R�t�Rr"rc���\rSrSrS\\R/S4S\RSS4SjrS\	\R\R4S\RS\
\S4S	jrS156\S\
\S4SjrSSjrSS
jrSrg)rYir#NrTrc�F�X lXlSUlSUl/Ulgr)�157connectionr#�requestr[�_chunks)rr#rTs   rr �_CallableAdapter.__init__s$��158'�� 0�������
���r"�159start_line�headersc��[R"UR[R"[R160U5US9Ulg)N)rxr|r})rrirxr_r`�RequestStartLinery�rr|r}s   r�headers_received�!_CallableAdapter.headers_receiveds9��161 �1�1�����{�{�8�#<�#<�j�I��162���163r"�chunkc�:�URRU5 gr)rz�append�rr�s  r�
data_received�_CallableAdapter.data_receiveds�������E�"�r"c���URceSRUR5URlURR	5 URUR5 g)Nr")ry�joinrz�body�_parse_bodyr#�rs r�finish�_CallableAdapter.finish sM���|�|�'�'�'��H�H�T�\�\�2�������� � �"����d�l�l�+r"c��U?gr)rzr�s r�on_connection_close�$_CallableAdapter.on_connection_close&s���Lr")rzrxr[ryr#rc)rdrerfrgrrrirsr rr�ResponseStartLine�HTTPHeadersrrr��bytesr�r�r�rurr"rrYrYs���	�"�H�$>�$>�#?��#E�F�	��-�-�	�164�		�165��(�3�3�X�5O�5O�O�P�166��%�%�167�168�)�D�/�	"�	169��5��X�i��o�-F��,�r"rYc��\rSrSrSS\R170S\S\\S\\	\SS4171Sjjr172S\4S	jrS173\RSS4SjrSSjrS
rg)rMi*NrJrKr'r/rc���X lURbURRUlOSUlUR[R[R1744;aUbUSUlOSUlU(aX0lO.[U[R5(aSUlOSUlURUlURUl[U=(d /5Ulg)Nrz0.0.0.0�https�http)rK�socket�family�address_family�AF_INET�AF_INET6�	remote_ipr'rVr�SSLIOStream�_orig_remote_ip�_orig_protocolr5r/)rrJrKr'r/s     rr �_HTTPRequestContext.__init__+s������=�=�$�"(�-�-�"6�"6�D��"&�D��
���F�N�N�F�O�O�#D�D��#�$�Q�Z�D�N�'�D�N��$�M�
��� 4� 4�
5�
5�#�D�M�"�D�M�#�~�~���"�m�m���"%�&8�&>�B�"?��r"c��UR[R[R4;aUR$[UR[5(a[UR5$[UR5$r)175r�r�r�r�r�rVrKr�rrkr�s r�__str__�_HTTPRequestContext.__str__MsX�����6�>�>�6�?�?�"C�C��>�>�!�
����e�
,�
,��d�l�l�+�+��t�|�|�$�$r"r}c���URSUR5nS[URS555HnX R;dM O URSU5n[176R"U5(aX lURSURSUR55nU(a"URS5SR5nUS;aX0lg	g	)177z2Rewrite the ``remote_ip`` and ``protocol`` fields.zX-Forwarded-Forc3�@# �UHoR5v� M g7fr)�strip)�.0�cands  r�	<genexpr>�6_HTTPRequestContext._apply_xheaders.<locals>.<genexpr>]s���D�,C�D�:�:�<�<�,C�s��,z	X-Real-IpzX-SchemezX-Forwarded-Proto�����)r�r�N)	�getr��reversed�splitr/r�is_valid_ipr'r�)rr}�ip�proto_headers    r�_apply_xheaders�#_HTTPRequestContext._apply_xheadersXs����[�[�*�D�N�N�
;��D�H�R�X�X�c�]�,C�D�B��0�0�0��E��[�[��b�
)�����r�"�"��N��{�{�����$7����G�178���(�-�-�c�2�2�6�<�<�>�L��,�,�(�M�-r"c�H�URUlURUlg)z�Undo changes from `_apply_xheaders`.179 180Xheaders are per-request so they should not leak to the next181request on the same connection.182N)r�r�r�r'r�s r�_unapply_xheaders�%_HTTPRequestContext._unapply_xheadersns���-�-����+�+��
r")r�r�rKr�r'r�r/rrc)rdrerfrgrrqrrrkrr r�rr�r�r�rurr"rrMrM*s���37� @��!�!� @�� @��3�-�	 @�183%�T�#�Y�/� @�184�
 @�D	%��	%�)�x�';�';�)��)�,,r"rMc���\rSrSrS\R185S\RSS4SjrS\\R\R4S\RS\\
S4S	jrS186\S\\
S4SjrSSjrSS
jrSSjrSrg)rZixr[rTrNc��X lXlgr�rxr[)rr[rTs   rr �_ProxyAdapter.__init__ys��187'�� �
r"r|r}c��URRRU5 URR	X5$r)rxrPr�r[r�r�s   rr��_ProxyAdapter.headers_received�s1��	
�����/�/��8��}�}�-�-�j�B�Br"r�c�8�URRU5$r)r[r�r�s  rr��_ProxyAdapter.data_received�s���}�}�*�*�5�1�1r"c�X�URR5 UR5 gr)r[r��_cleanupr�s rr��_ProxyAdapter.finish�s���
�
�����
�
�r"c�X�URR5 UR5 gr)r[r�r�r�s rr��!_ProxyAdapter.on_connection_close�s���
�
�)�)�+��
�
�r"c�L�URRR5 gr)rxrPr�r�s rr��_ProxyAdapter._cleanup�s�������1�1�3r"r�rc)rdrerfrgrrtrsr rrr�r�rrr�r�r�r�r�r�rurr"rrZrZxs���!��.�.�!��-�-�!�188�	!�C��(�3�3�X�5O�5O�O�P�C��%�%�C�189�)�D�/�	"�	C�2�5�2�X�i��o�-F�2���4r"rZ)$rhr�rl�tornado.escaper�tornado.http1connectionrr�tornadorrr�tornado.tcpserverr	�tornado.utilr190r_rrr
rrrrrr�
TYPE_CHECKINGrrWrrtrYrMrZri�HTTPRequestrr"r�<module>r�s��� 191��192�%�T����'�%�
�U�U�U�	����SR��L�(�*O�*O�SR�l#�x�3�3�#�LK,�K,�\4�H�0�0�4�D�(�(�r"