
    h@                        S r SSKrSSKrSSKJr  SSKJrJr  SSKJ	r	  SSKJ
r
  SSKJr  SSKJr  SS	KJr  SSKrSS
KJrJrJrJrJrJrJrJrJr  \R4                  (       a  SSKJr   " S S\\\	R8                  5      r " S S\	R<                  5      r " S S5      r  " S S\	R<                  5      r!\	RD                  r#g)a  A non-blocking, single-threaded HTTP server.

Typical applications have little direct interaction with the `HTTPServer`
class except to start a server at the beginning of the process
(and even that is often done indirectly via `tornado.web.Application.listen`).

.. versionchanged:: 4.0

   The ``HTTPRequest`` class that used to live in this module has been moved
   to `tornado.httputil.HTTPServerRequest`.  The old name remains as an alias.
    N)
native_str)HTTP1ServerConnectionHTTP1ConnectionParameters)httputil)iostream)netutil)	TCPServer)Configurable)	UnionAnyDictCallableListTypeTupleOptional	Awaitable)Setc                      \ rS rSrSrS\S\SS4S jr            S!S\\R                  \
\R                  /S4   4   S	\S
\S\\\\\4   \R"                  4      S\\   S\S\\   S\\   S\\   S\\   S\\   S\\   S\\\      SS4S jjr\S\\   4S j5       r\S\\   4S j5       rS"S jrS\R:                  S\SS4S jrS\ S\RB                  S\RD                  4S jr#S\ SS4S jr$S r%g)#
HTTPServer.   a  A non-blocking, single-threaded HTTP server.

A server is defined by a subclass of `.HTTPServerConnectionDelegate`,
or, for backwards compatibility, a callback that takes an
`.HTTPServerRequest` as an argument. The delegate is usually a
`tornado.web.Application`.

`HTTPServer` supports keep-alive connections by default
(automatically for HTTP/1.1, or for HTTP/1.0 when the client
requests ``Connection: keep-alive``).

If ``xheaders`` is ``True``, we support the
``X-Real-Ip``/``X-Forwarded-For`` and
``X-Scheme``/``X-Forwarded-Proto`` headers, which override the
remote IP and URI scheme/protocol for all requests.  These headers
are useful when running Tornado behind a reverse proxy or load
balancer.  The ``protocol`` argument can also be set to ``https``
if Tornado is run behind an SSL-decoding proxy that does not set one of
the supported ``xheaders``.

By default, when parsing the ``X-Forwarded-For`` header, Tornado will
select the last (i.e., the closest) address on the list of hosts as the
remote host IP address.  To select the next server in the chain, a list of
trusted downstream hosts may be passed as the ``trusted_downstream``
argument.  These hosts will be skipped when parsing the ``X-Forwarded-For``
header.

To make this server serve SSL traffic, send the ``ssl_options`` keyword
argument with an `ssl.SSLContext` object. For compatibility with older
versions of Python ``ssl_options`` may also be a dictionary of keyword
arguments for the `ssl.SSLContext.wrap_socket` method.::

   ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
   ssl_ctx.load_cert_chain(os.path.join(data_dir, "mydomain.crt"),
                           os.path.join(data_dir, "mydomain.key"))
   HTTPServer(application, ssl_options=ssl_ctx)

`HTTPServer` initialization follows one of three patterns (the
initialization methods are defined on `tornado.tcpserver.TCPServer`):

1. `~tornado.tcpserver.TCPServer.listen`: single-process::

        async def main():
            server = HTTPServer()
            server.listen(8888)
            await asyncio.Event().wait()

        asyncio.run(main())

   In many cases, `tornado.web.Application.listen` can be used to avoid
   the need to explicitly create the `HTTPServer`.

   While this example does not create multiple processes on its own, when
   the ``reuse_port=True`` argument is passed to ``listen()`` you can run
   the program multiple times to create a multi-process service.

2. `~tornado.tcpserver.TCPServer.add_sockets`: multi-process::

        sockets = bind_sockets(8888)
        tornado.process.fork_processes(0)
        async def post_fork_main():
            server = HTTPServer()
            server.add_sockets(sockets)
            await asyncio.Event().wait()
        asyncio.run(post_fork_main())

   The ``add_sockets`` interface is more complicated, but it can be used with
   `tornado.process.fork_processes` to run a multi-process service with all
   worker processes forked from a single parent.  ``add_sockets`` can also be
   used in single-process servers if you want to create your listening
   sockets in some way other than `~tornado.netutil.bind_sockets`.

   Note that when using this pattern, nothing that touches the event loop
   can be run before ``fork_processes``.

3. `~tornado.tcpserver.TCPServer.bind`/`~tornado.tcpserver.TCPServer.start`:
   simple **deprecated** multi-process::

        server = HTTPServer()
        server.bind(8888)
        server.start(0)  # Forks multiple sub-processes
        IOLoop.current().start()

   This pattern is deprecated because it requires interfaces in the
   `asyncio` module that have been deprecated since Python 3.10. Support for
   creating multiple processes in the ``start`` method will be removed in a
   future version of Tornado.

.. versionchanged:: 4.0
   Added ``decompress_request``, ``chunk_size``, ``max_header_size``,
   ``idle_connection_timeout``, ``body_timeout``, ``max_body_size``
   arguments.  Added support for `.HTTPServerConnectionDelegate`
   instances as ``request_callback``.

.. versionchanged:: 4.1
   `.HTTPServerConnectionDelegate.start_request` is now called with
   two arguments ``(server_conn, request_conn)`` (in accordance with the
   documentation) instead of one ``(request_conn)``.

.. versionchanged:: 4.2
   `HTTPServer` is now a subclass of `tornado.util.Configurable`.

.. versionchanged:: 4.5
   Added the ``trusted_downstream`` argument.

.. versionchanged:: 5.0
   The ``io_loop`` argument has been removed.
argskwargsreturnNc                     g N )selfr   r   s      eC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\tornado/httpserver.py__init__HTTPServer.__init__   s     	    request_callbackno_keep_alivexheadersssl_optionsprotocoldecompress_request
chunk_sizemax_header_sizeidle_connection_timeoutbody_timeoutmax_body_sizemax_buffer_sizetrusted_downstreamc           
          Xl         X0l        XPl        [        UUUU	=(       d    SUU
US9U l        [
        R                  " U UUUS9  [        5       U l        Xl	        g )Ni  )
decompressr)   r*   header_timeoutr-   r,   r$   )r&   r.   read_chunk_size)
r#   r%   r'   r   conn_paramsr	   r    set_connectionsr/   )r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   s                 r   
initializeHTTPServer.initialize   si    . !1  4)!+2:d'%'
 	#+&		
  E"4r"   c                     [         $ r   r   clss    r   configurable_baseHTTPServer.configurable_base       r"   c                     [         $ r   r:   r;   s    r   configurable_defaultHTTPServer.configurable_default   r?   r"   c                    #    U R                   (       aJ  [        [        U R                   5      5      nUR                  5       I Sh  vN   U R                   (       a  MI  gg N7f)a  Close all open connections and asynchronously wait for them to finish.

This method is used in combination with `~.TCPServer.stop` to
support clean shutdowns (especially for unittests). Typical
usage would call ``stop()`` first to stop accepting new
connections, then ``await close_all_connections()`` to wait for
existing connections to finish.

This method does not currently close open websocket connections.

Note that this method is a coroutine and must be called with ``await``.

N)r6   nextiterclose)r   conns     r   close_all_connections HTTPServer.close_all_connections   sG      T../0D**,  s   AA!AA!A!streamaddressc                     [        XU R                  U R                  5      n[        XR                  U5      nU R
                  R                  U5        UR                  U 5        g r   )_HTTPRequestContextr'   r/   r   r4   r6   addstart_serving)r   rJ   rK   contextrG   s        r   handle_streamHTTPServer.handle_stream   sS    %T]]D,C,C
 %V-=-=wGd#4 r"   server_connrequest_connc                     [        U R                  [        R                  5      (       a  U R                  R	                  X5      nO[        U R                  U5      nU R                  (       a  [        X25      nU$ r   )
isinstancer#   r   HTTPServerConnectionDelegatestart_request_CallableAdapterr%   _ProxyAdapter)r   rS   rT   delegates       r   rX   HTTPServer.start_request   s[     d++X-R-RSS,,::;UH'(=(=|LH==$X<Hr"   c                 l    U R                   R                  [        R                  " [        U5      5        g r   )r6   removetypingcastr   )r   rS   s     r   on_closeHTTPServer.on_close   s"      -BK!PQr"   )r6   r4   r'   r#   r/   r%   )FFNNFNNNNNNNr   N)&__name__
__module____qualname____firstlineno____doc__r   r    r   r   rW   r   HTTPServerRequestboolr   r   strssl
SSLContextintfloatr   r7   classmethodr   r
   r=   rA   rH   r   IOStreamr   rQ   objectHTTPConnectionHTTPMessageDelegaterX   ra   __static_attributes__r   r"   r   r   r   .   s   kZc S T  $GK"&#($()-37(,'+)-26#*511h001478:
*5 *5 *5 eDcNCNN$BCD*5 3-*5 !*5 SM*5 "#*5 "*%*5 uo*5  }*5  "#!*5" %T#Y/#*5$ 
%*5X $|"4   T,%7  &!H$5$5 ! !$ !!191H1H		%	%RF Rt Rr"   r   c                       \ rS rSrS\\R                  /S4   S\R                  SS4S jrS\	\R                  \R                  4   S\R                  S\\S      4S	 jrS
\S\\S      4S jrSS jrSS jrSrg)rY   i  r#   NrT   r   c                 F    X l         Xl        S U l        S U l        / U l        g r   )
connectionr#   requestr[   _chunks)r   r#   rT   s      r   r    _CallableAdapter.__init__  s$    
 ' 0r"   
start_lineheadersc                     [         R                  " U R                  [        R                  " [         R
                  U5      US9U l        g )N)rx   r|   r}   )r   ri   rx   r_   r`   RequestStartLinery   r   r|   r}   s      r   headers_received!_CallableAdapter.headers_received  s9    
  11{{8#<#<jI

 r"   chunkc                 :    U R                   R                  U5        g r   )rz   appendr   r   s     r   data_received_CallableAdapter.data_received  s    E"r"   c                     U R                   c   eSR                  U R                  5      U R                   l        U R                   R	                  5         U R                  U R                   5        g )Nr"   )ry   joinrz   body_parse_bodyr#   r   s    r   finish_CallableAdapter.finish   sM    ||'''HHT\\2  "dll+r"   c                     U ? g r   )rz   r   s    r   on_connection_close$_CallableAdapter.on_connection_close&  s    Lr"   )rz   rx   r[   ry   r#   rc   )rd   re   rf   rg   r   r   ri   rs   r    r   r   ResponseStartLineHTTPHeadersr   r   r   bytesr   r   r   ru   r   r"   r   rY   rY     s    	"H$>$>#?#EF	 --	 
		
(33X5O5OOP
 %%
 
)D/	"	
5 Xio-F ,r"   rY   c                       \ rS rSr SS\R
                  S\S\\   S\\	\      SS4
S jjr
S\4S	 jrS
\R                  SS4S jrSS jrSrg)rM   i*  NrJ   rK   r'   r/   r   c                    X l         UR                  b  UR                  R                  U l        OS U l        U R                  [        R                  [        R
                  4;   a  Ub  US   U l        OSU l        U(       a  X0l        O.[        U[        R                  5      (       a  SU l        OSU l        U R                  U l        U R                  U l        [        U=(       d    / 5      U l        g )Nr   z0.0.0.0httpshttp)rK   socketfamilyaddress_familyAF_INETAF_INET6	remote_ipr'   rV   r   SSLIOStream_orig_remote_ip_orig_protocolr5   r/   )r   rJ   rK   r'   r/   s        r   r    _HTTPRequestContext.__init__+  s      ==$"(--"6"6D"&D FNNFOO#DD#$QZDN 'DN$M 4 455#DM"DM#~~"mm"%&8&>B"?r"   c                    U R                   [        R                  [        R                  4;   a  U R                  $ [        U R                  [        5      (       a  [        U R                  5      $ [        U R                  5      $ r   )
r   r   r   r   r   rV   rK   r   r   rk   r   s    r   __str___HTTPRequestContext.__str__M  sX    6>>6??"CC>>!e,, dll++t||$$r"   r}   c                    UR                  SU R                  5      nS [        UR                  S5      5       5        H  nX R                  ;  d  M    O   UR                  SU5      n[
        R                  " U5      (       a  X l        UR                  SUR                  SU R                  5      5      nU(       a"  UR                  S5      S   R                  5       nUS;   a  X0l        g	g	)
z2Rewrite the ``remote_ip`` and ``protocol`` fields.zX-Forwarded-Forc              3   @   #    U  H  oR                  5       v   M     g 7fr   )strip).0cands     r   	<genexpr>6_HTTPRequestContext._apply_xheaders.<locals>.<genexpr>]  s     D,CD::<<,Cs   ,z	X-Real-IpzX-SchemezX-Forwarded-Proto)r   r   N)	getr   reversedsplitr/   r   is_valid_ipr'   r   )r   r}   ipproto_headers       r   _apply_xheaders#_HTTPRequestContext._apply_xheadersX  s     [[*DNN;DHRXXc],CDB000 E [[b)r""N{{$7G
  (--c226<<>L,,(M -r"   c                 H    U R                   U l        U R                  U l        g)zUndo changes from `_apply_xheaders`.

Xheaders are per-request so they should not leak to the next
request on the same connection.
N)r   r   r   r'   r   s    r   _unapply_xheaders%_HTTPRequestContext._unapply_xheadersn  s     --++r"   )r   r   rK   r   r'   r   r/   r   rc   )rd   re   rf   rg   r   rq   r   r   rk   r   r    r   r   r   r   r   ru   r   r"   r   rM   rM   *  s     37 @!! @  @ 3-	 @
 %T#Y/ @ 
 @D	% 	%)x';'; ) ),,r"   rM   c                       \ rS rSrS\R
                  S\R                  SS4S jrS\\R                  \R                  4   S\R                  S\\S      4S	 jrS
\S\\S      4S jrSS jrSS jrSS jrSrg)rZ   ix  r[   rT   r   Nc                     X l         Xl        g r   rx   r[   )r   r[   rT   s      r   r    _ProxyAdapter.__init__y  s    
 ' r"   r|   r}   c                     U R                   R                  R                  U5        U R                  R	                  X5      $ r   )rx   rP   r   r[   r   r   s      r   r   _ProxyAdapter.headers_received  s1     	//8}}--jBBr"   r   c                 8    U R                   R                  U5      $ r   )r[   r   r   s     r   r   _ProxyAdapter.data_received  s    }}**511r"   c                 X    U R                   R                  5         U R                  5         g r   )r[   r   _cleanupr   s    r   r   _ProxyAdapter.finish  s    r"   c                 X    U R                   R                  5         U R                  5         g r   )r[   r   r   r   s    r   r   !_ProxyAdapter.on_connection_close  s    ))+r"   c                 L    U R                   R                  R                  5         g r   )rx   rP   r   r   s    r   r   _ProxyAdapter._cleanup  s    113r"   r   rc   )rd   re   rf   rg   r   rt   rs   r    r   r   r   r   r   r   r   r   r   r   r   r   ru   r   r"   r   rZ   rZ   x  s    !..! --! 
	!C(33X5O5OOPC %%C 
)D/	"	C25 2Xio-F 24r"   rZ   )$rh   r   rl   tornado.escaper   tornado.http1connectionr   r   tornador   r   r   tornado.tcpserverr	   tornado.utilr
   r_   r   r   r   r   r   r   r   r   r   TYPE_CHECKINGr   rW   r   rt   rY   rM   rZ   ri   HTTPRequestr   r"   r   <module>r      s    
  
 % T    ' %  U U U	SRL(*O*O SRl#x33 #LK, K,\4H00 4D ((r"   