
    h$<                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJrJr  SSKJrJrJr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  \R:                  (       a  SSKJrJr   " S S5      r g)z+A non-blocking, single-threaded TCP server.    N)gen)app_log)IOLoop)IOStreamSSLIOStream)bind_socketsadd_accept_handlerssl_wrap_socket_DEFAULT_BACKLOG)process)errno_from_exception)UnionDictAnyIterableOptional	Awaitable)CallableListc                      \ rS rSrSr   SS\\\\\	4   \
R                  4      S\\   S\\   SS4S jjrS\R                  \SS	4S
\S\\   S\R"                  S\S\\   S\SS4S jjrS\\R                     SS4S jrS\R                  SS4S jrS\R                  \SS	4S
\S\\   S\R"                  S\S\\   S\SS4S jjr S S\\   S\\   SS4S jjrS!S jrS\S\S\\S      4S jrS\R                  S\	SS4S jrSrg)"	TCPServer+   ad  A non-blocking, single-threaded TCP server.

To use `TCPServer`, define a subclass which overrides the `handle_stream`
method. For example, a simple echo server could be defined like this::

  from tornado.tcpserver import TCPServer
  from tornado.iostream import StreamClosedError

  class EchoServer(TCPServer):
      async def handle_stream(self, stream, address):
          while True:
              try:
                  data = await stream.read_until(b"\n") await
                  stream.write(data)
              except StreamClosedError:
                  break

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"))
   TCPServer(ssl_options=ssl_ctx)

`TCPServer` initialization follows one of three patterns:

1. `listen`: single-process::

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

        asyncio.run(main())

   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. `add_sockets`: multi-process::

        sockets = bind_sockets(8888)
        tornado.process.fork_processes(0)
        async def post_fork_main():
            server = TCPServer()
            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. `bind`/`start`: simple **deprecated** multi-process::

        server = TCPServer()
        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.

.. versionadded:: 3.1
   The ``max_buffer_size`` argument.

.. versionchanged:: 5.0
   The ``io_loop`` argument has been removed.
Nssl_optionsmax_buffer_sizeread_chunk_sizereturnc                 R   Xl         0 U l        0 U l        / U l        SU l        SU l        X l        X0l        U R                   b  [        U R                   [        5      (       a  SU R                   ;  a  [        S5      e[        R                  R                  U R                   S   5      (       d  [        SU R                   S   -  5      eSU R                   ;   aM  [        R                  R                  U R                   S   5      (       d  [        SU R                   S   -  5      eg g g g )NFcertfilez%missing key "certfile" in ssl_optionszcertfile "%s" does not existkeyfilezkeyfile "%s" does not exist)r   _sockets	_handlers_pending_sockets_started_stoppedr   r   
isinstancedictKeyErrorospathexists
ValueError)selfr   r   r   s       dC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\tornado/tcpserver.py__init__TCPServer.__init__|   s    ' ".. 'Jt7G7G,N,N!1!11FGG77>>$"2"2:">?? 2T5E5Ej5QQ  D,,,RWW^^  +6 6 !1D4D4DY4OO 6, -O'    Fportaddressfamilybacklogflags
reuse_portc           	      B    [        UUUUUUS9nU R                  U5        g)a   Starts accepting connections on the given port.

This method may be called more than once to listen on multiple ports.
`listen` takes effect immediately; it is not necessary to call
`TCPServer.start` afterwards.  It is, however, necessary to start the
event loop if it is not already running.

All arguments have the same meaning as in
`tornado.netutil.bind_sockets`.

.. versionchanged:: 6.2

   Added ``family``, ``backlog``, ``flags``, and ``reuse_port``
   arguments to match `tornado.netutil.bind_sockets`.
r2   r3   r4   r5   r6   N)r   add_socketsr,   r1   r2   r3   r4   r5   r6   socketss           r-   listenTCPServer.listen   s0    0 !
 	!r0   r;   c                     U HO  nX R                   UR                  5       '   [        X R                  5      U R                  UR                  5       '   MQ     g)ai  Makes this server start accepting connections on the given sockets.

The ``sockets`` parameter is a list of socket objects such as
those returned by `~tornado.netutil.bind_sockets`.
`add_sockets` is typically used in combination with that
method and `tornado.process.fork_processes` to provide greater
control over the initialization of a multi-process server.
N)r    filenor	   _handle_connectionr!   )r,   r;   socks      r-   r9   TCPServer.add_sockets   sB     D+/MM$++-(,>---DNN4;;=) r0   socketc                 (    U R                  U/5        g)zASingular version of `add_sockets`.  Takes a single socket object.N)r9   )r,   rC   s     r-   
add_socketTCPServer.add_socket   s    &"r0   c           	          [        UUUUUUS9nU R                  (       a  U R                  U5        gU R                  R	                  U5        g)a_  Binds this server to the given port on the given address.

To start the server, call `start`. If you want to run this server in a
single process, you can call `listen` as a shortcut to the sequence of
`bind` and `start` calls.

Address may be either an IP address or hostname.  If it's a hostname,
the server will listen on all IP addresses associated with the name.
Address may be an empty string or None to listen on all available
interfaces.  Family may be set to either `socket.AF_INET` or
`socket.AF_INET6` to restrict to IPv4 or IPv6 addresses, otherwise both
will be used if available.

The ``backlog`` argument has the same meaning as for `socket.listen
<socket.socket.listen>`. The ``reuse_port`` argument has the same
meaning as for `.bind_sockets`.

This method may be called multiple times prior to `start` to listen on
multiple ports or interfaces.

.. versionchanged:: 4.4
   Added the ``reuse_port`` argument.

.. versionchanged:: 6.2
   Added the ``flags`` argument to match `.bind_sockets`.

.. deprecated:: 6.2
   Use either ``listen()`` or ``add_sockets()`` instead of ``bind()``
   and ``start()``.
r8   N)r   r#   r9   r"   extendr:   s           r-   bindTCPServer.bind   sL    N !
 ==W%!!((1r0   num_processesmax_restartsc                     U R                   (       a   eSU l         US:w  a  [        R                  " X5        U R                  n/ U l        U R	                  U5        g)a  Starts this server in the `.IOLoop`.

By default, we run the server in this process and do not fork any
additional child process.

If num_processes is ``None`` or <= 0, we detect the number of cores
available on this machine and fork that number of child
processes. If num_processes is given and > 1, we fork that
specific number of sub-processes.

Since we use processes and not threads, there is no shared memory
between any server code.

Note that multiple processes are not compatible with the autoreload
module (or the ``autoreload=True`` option to `tornado.web.Application`
which defaults to True when ``debug=True``).
When using multiple processes, no IOLoops can be created or
referenced until after the call to ``TCPServer.start(n)``.

Values of ``num_processes`` other than 1 are not supported on Windows.

The ``max_restarts`` argument is passed to `.fork_processes`.

.. versionchanged:: 6.0

   Added ``max_restarts`` argument.

.. deprecated:: 6.2
   Use either ``listen()`` or ``add_sockets()`` instead of ``bind()``
   and ``start()``.
T   N)r#   r   fork_processesr"   r9   )r,   rK   rL   r;   s       r-   startTCPServer.start  sP    D ==  A""=?'' "!r0   c                    U R                   (       a  gSU l         U R                  R                  5        HK  u  pUR                  5       U:X  d   eU R                  R                  U5      " 5         UR                  5         MM     g)zuStops listening for new connections.

Requests currently in progress may still continue after the
server is stopped.
NT)r$   r    itemsr?   r!   popclose)r,   fdrA   s      r-   stopTCPServer.stop2  s`     ==++-HB;;=B&&&NNr"$JJL	 .r0   streamc                     [        5       e)a  Override to handle a new `.IOStream` from an incoming connection.

This method may be a coroutine; if so any exceptions it raises
asynchronously will be logged. Accepting of incoming connections
will not be blocked by this coroutine.

If this `TCPServer` is configured for SSL, ``handle_stream``
may be called before the SSL handshake has completed. Use
`.SSLIOStream.wait_for_handshake` if you need to verify the client's
certificate or use NPN/ALPN.

.. versionchanged:: 4.2
   Added the option for this method to be a coroutine.
)NotImplementedError)r,   rY   r2   s      r-   handle_streamTCPServer.handle_streamA  s    " "##r0   
connectionc                 8   U R                   b)  [        (       d   S5       e [        UU R                   SSS9n U R                   b   [        UU R                  U R                  S9nO[        UU R                  U R                  S9nU R!                  XB5      nUb;  ["        R$                  " 5       R'                  [(        R*                  " U5      S 5        g g ! [        R                   a<  nUR                  S   [        R
                  :X  a  UR                  5       s S nA$ e S nAf[         aH  n[        U5      [        R                  [        R                  4;   a  UR                  5       s S nA$ e S nAff = f! [,         a    [.        R0                  " SSS	9   g f = f)
NzOpenSSL required for SSLTF)server_sidedo_handshake_on_connectr   )r   r   c                 "    U R                  5       $ )N)result)fs    r-   <lambda>.TCPServer._handle_connection.<locals>.<lambda>  s
    188:r0   zError in connection callback)exc_info)r   sslr
   SSLErrorargsSSL_ERROR_EOFrU   OSErrorr   errnoECONNABORTEDEINVALr   r   r   r   r\   r   current
add_futurer   convert_yielded	Exceptionr   error)r,   r^   r2   errrY   futures         r-   r@   TCPServer._handle_connectionT  sn   '32223,$$ $,1	
4	I+$$($8$8$($8$8 "$($8$8$($8$8 ''8F! ++''/1E "G << 88A;#"3"33%++--  (,1C1CU\\0RR%++--D  	IMM84H	IsM   C BE7 E4(0DE4DE4,<E/(E4.E//E47FF)r!   r"   r    r#   r$   r   r   r   )NNN)rN   N)r   N) __name__
__module____qualname____firstlineno____doc__r   r   r   strr   rh   
SSLContextintr.   rC   	AF_UNSPECr   AddressFamilyboolr<   r   r9   rE   rI   rP   rW   r   tupler   r\   r@   __static_attributes__ r0   r-   r   r   +   s   Nd HL)-)-	!eDcNCNN$BCD! "#! "#	!
 
!L "&'-'7'7'#  " " # " $$	 "
  " } "  " 
 "D8FMM#: t # #4 # "&'-'7'7'# 2222 #22 $$	22
 22 }22 22 
22j OS("%c](">Fsm("	("T$$).$	)D/	"$&2IV]] 2IS 2IT 2Ir0   r   )!r|   rm   r(   rC   rh   tornador   tornado.logr   tornado.ioloopr   tornado.iostreamr   r   tornado.netutilr   r	   r
   r   r   tornado.utilr   typingr   r   r   r   r   r   TYPE_CHECKINGr   r   r   r   r0   r-   <module>r      sW     2  	  
   ! 2   -  B B	%[I [Ir0   