Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/tornado/__pycache__/tcpserver.cpython-39.pyc
Ðазад
a _�ht4 � @ s� d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m Z ddlmZm Z ddlmZmZmZ ddlmZ dd lmZ ddlZdd lmZmZmZmZmZmZ ejr�ddlmZmZ G dd � d e�Z dS )z+A non-blocking, single-threaded TCP server.� N)�gen)�app_log)�IOLoop)�IOStream�SSLIOStream)�bind_sockets�add_accept_handler�ssl_wrap_socket)�process)�errno_from_exception)�Union�Dict�Any�Iterable�Optional� Awaitable)�Callable�Listc @ s� e Zd ZdZd"eeeef ej f e e dd�dd�Zd#e edd�dd �Ze ej dd �dd�Zejdd �dd�Zdejddfe eeje edd�dd�Zd$ee e dd�dd�Zdd�dd�Zeeeed d�dd�Zejedd�d d!�ZdS )%� TCPServera� 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 from tornado import gen 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.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`: simple single-process:: server = TCPServer() server.listen(8888) IOLoop.current().start() 2. `bind`/`start`: simple multi-process:: server = TCPServer() server.bind(8888) server.start(0) # Forks multiple sub-processes IOLoop.current().start() When using this interface, an `.IOLoop` must *not* be passed to the `TCPServer` constructor. `start` will always start the server on the default singleton `.IOLoop`. 3. `add_sockets`: advanced multi-process:: sockets = bind_sockets(8888) tornado.process.fork_processes(0) server = TCPServer() server.add_sockets(sockets) IOLoop.current().start() The `add_sockets` interface is more complicated, but it can be used with `tornado.process.fork_processes` to give you more flexibility in when the fork happens. `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`. .. 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 C s� || _ i | _i | _g | _d| _d| _|| _|| _| j d ur�t| j t �r�d| j vrXt d��tj� | j d �s|td| j d ��d| j v r�tj� | j d �s�td| j d ��d S )NF�certfilez%missing key "certfile" in ssl_optionszcertfile "%s" does not exist�keyfilezkeyfile "%s" does not exist)r �_sockets� _handlers�_pending_sockets�_started�_stoppedr r � isinstance�dict�KeyError�os�path�exists� ValueError)�selfr r r � r( ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/tornado/tcpserver.py�__init__l s* ���zTCPServer.__init__� )�port�addressr c C s t ||d�}| �|� dS )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 `.IOLoop`. )r- N)r �add_sockets)r'