File manager - Edit - /usr/local/CyberCP/lib/python3.10/site-packages/tornado/__pycache__/netutil.cpython-310.pyc
Back
o �h�a � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddl Z ddl mZmZ ddl mZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZ e�ejj�Ze�ejj �Z!e"ed�rqe j#ej$O _#e! j#ej$O _#d�%d � d�%d � dZ&dej'e&ddfd e(dee) dej*de(dee( de+deej fdd�Z,e"ed�r�de&fde)de(de(dejfdd�Z-dejdeejegdf deg df fdd�Z.d e)de+fd!d"�Z/G d#d$� d$e�Z0ej'fd%e)d e(dej*deee(ef fd&d'�Z1G d(d)� d)e0�Z2G d*d+� d+e0�Z3G d,d-� d-e0�Z4G d.d/� d/e4�Z5G d0d1� d1e4�Z6G d2d3� d3e0�Z7e8g d4��Z9 d>d5eee)ef ej:f d6ee+ dej:fd7d8�Z; d?d9ejd5eee)ef ej:f d:ee) d6ee+ d;edej<fd<d=�Z=dS )@z#Miscellaneous network utility code.� N)�dummy_executor�run_on_executor)�IOLoop)�Configurable�errno_from_exception) �List�Callable�Any�Type�Dict�Union�Tuple� Awaitable�Optional�OP_NO_COMPRESSION�foo�idna�latin1� F�port�address�family�backlog�flags� reuse_port�returnc C sx |rt td�std��g }|dkrd}tjs|tjkrtj}|du r%tj}d}t� }tt� || |tj d|�dd� d�D ]�} | |v rBq;|�| � | \} }}} }tj d krc|d krc| tjkrc|d dkrcq;z t�| ||�}W n tjy� } zt|�tjkr�W Y d}~q;� d}~ww tjdkr�z|�tjtjd � W n tjy� } zt|�tjkr�� W Y d}~nd}~ww |r�|�tjtjd � | tjkr�t td�r�|�tjtjd � |dd� \}}|dkr�|dur�t||gt|dd� � �}|�d� z|�|� W n, t �y( } zt|�tj!k�r#|d k�r#|d dk�r#|�"� W Y d}~q;� d}~ww |�#� d }|�$|� |�%|� q;|S )a Creates listening sockets bound to the given port and address. Returns a list of socket objects (multiple sockets are returned if the given address maps to multiple IP addresses, which is most common for mixed IPv4 and IPv6 use). 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>`. ``flags`` is a bitmask of AI_* flags to `~socket.getaddrinfo`, like ``socket.AI_PASSIVE | socket.AI_NUMERICHOST``. ``reuse_port`` option sets ``SO_REUSEPORT`` option for every socket in the list. If your platform doesn't support this option ValueError will be raised. �SO_REUSEPORTz)the platform doesn't support SO_REUSEPORT� Nr c S s | d S �Nr � )�xr r �B/usr/local/CyberCP/lib/python3.10/site-packages/tornado/netutil.py�<lambda>j s zbind_sockets.<locals>.<lambda>)�key�darwin� localhost� �nt� �IPPROTO_IPV6� Fz::1)&�hasattr�socket� ValueError�has_ipv6� AF_UNSPEC�AF_INET� AI_PASSIVE�set�sorted�getaddrinfo�SOCK_STREAM�add�sys�platform�AF_INET6�errorr �errno�EAFNOSUPPORT�os�name� setsockopt� SOL_SOCKET�SO_REUSEADDR�ENOPROTOOPTr r) �IPV6_V6ONLY�tuple�list�setblocking�bind�OSError� EADDRNOTAVAIL�close�getsockname�listen�append)r r r r r r �sockets� bound_port�unique_addresses�res�af�socktype�proto� canonname�sockaddr�sock�e�host�requested_portr r r! �bind_sockets8 s� � �� ��� �� r[ �AF_UNIXi� �file�modec C s� t � t jt j�}z|�t jt jd� W n t jy. } zt|�tj kr$� W Y d}~nd}~ww |� d� zt�| �}W n t yD Y nw t�|j�rQt�| � ntd| ��|�| � t�| |� |�|� |S )a( Creates a listening unix socket. If a socket with the given name already exists, it will be deleted. If any other file with that name exists, an exception will be raised. Returns a socket object (not a list of socket objects like `bind_sockets`) r( NFz"File %s exists and is not a socket)r, r\ r5 r? r@ rA r: r r; rB rF r= �stat�FileNotFoundError�S_ISSOCK�st_mode�remover- rG �chmodrL )r] r^ r rW rX �str r r! �bind_unix_socket� s, ��� � rf rW �callbackc sT t �� �dg�dtjdtddf� ��fdd�}d ���fdd �}���|t j� |S )a� Adds an `.IOLoop` event handler to accept new connections on ``sock``. When a connection is accepted, ``callback(connection, address)`` will be run (``connection`` is a socket object, and ``address`` is the address of the other end of the connection). Note that this signature is different from the ``callback(fd, events)`` signature used for `.IOLoop` handlers. A callable is returned which, when called, will remove the `.IOLoop` event handler and stop processing further incoming connections. .. versionchanged:: 5.0 The ``io_loop`` argument (deprecated since version 4.1) has been removed. .. versionchanged:: 5.0 A callable is returned (``None`` was returned before). F�fd�eventsr Nc sb t t�D ]*}�d r d S z��� \}}W n ty Y d S ty( Y qw � ||� qd S r )�range�_DEFAULT_BACKLOG�accept�BlockingIOError�ConnectionAbortedError)rh ri �i� connectionr )rg �removedrW r r! �accept_handler� s ��z*add_accept_handler.<locals>.accept_handlerc s � � �� d�d<