File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/ext/tornado/__pycache__/websocket.cpython-310.pyc
Back
o ;jǻ � @ s� d Z ddlmZmZmZ ddlZddlZddlZddlZddl Z ddl m m m Z ddlm m mZ ddlZddlmZ ddl mZmZmZ ddlmZmZmZ ddlmZmZ ddlm Z dd l!m"Z"m#Z# dd lm$Z$ ddl%m&Z& ddl'm(Z(m)Z) e)r�dd l*m+Z+ e,Z-ndd l+m+Z+ G dd� de.�Z/G dd� de/�Z0G dd� dej1�Z2dd� Z3G dd� de4�Z5G dd� de4�Z6G dd� de4�Z7G dd� de5�Z8G dd� de$j9�Z: d"d d!�Z;dS )#a� Implementation of the WebSocket protocol. `WebSockets <http://dev.w3.org/html5/websockets/>`_ allow for bidirectional communication between the browser and server. WebSockets are supported in the current versions of all major browsers, although older versions that do not support WebSockets are still in use (refer to http://caniuse.com/websockets for details). This module implements the final version of the WebSocket protocol as defined in `RFC 6455 <http://tools.ietf.org/html/rfc6455>`_. Certain browser versions (notably Safari 5.x) implemented an earlier draft of the protocol (known as "draft 76") and are not compatible with this module. .. versionchanged:: 4.0 Removed support for the draft 76 protocol version. � )�absolute_import�division�print_functionN)�TracebackFuture)�utf8� native_str� to_unicode)�gen� httpclient�httputil)�IOLoop�PeriodicCallback)�StreamClosedError)�gen_log�app_log)�simple_httpclient)� TCPClient)�_websocket_mask�PY3)�urlparsec @ s e Zd ZdS )�WebSocketErrorN)�__name__� __module__�__qualname__� r r �N/opt/saltstack/salt/lib/python3.10/site-packages/salt/ext/tornado/websocket.pyr 1 s r c @ s e Zd ZdZdS )�WebSocketClosedErrorzLRaised by operations on a closed connection. .. versionadded:: 3.2 N)r r r �__doc__r r r r r 5 s r c s� e Zd ZdZ� fdd�Zejdd� �ZdZe dd� �Z e d d � �Ze dd� �Zd0dd�Z dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd1d d!�Zd"d#� Zd$d%� Zd&d'� Z� fd(d)�Z� fd*d+�Zd,d-� Zd.d/� Z� ZS )2�WebSocketHandlera� Subclass this class to create a basic WebSocket handler. Override `on_message` to handle incoming messages, and use `write_message` to send messages to the client. You can also override `open` and `on_close` to handle opened and closed connections. Custom upgrade response headers can be sent by overriding `~tornado.web.RequestHandler.set_default_headers` or `~tornado.web.RequestHandler.prepare`. See http://dev.w3.org/html5/websockets/ for details on the JavaScript interface. The protocol is specified at http://tools.ietf.org/html/rfc6455. Here is an example WebSocket handler that echos back all received messages back to the client: .. testcode:: class EchoWebSocket(tornado.websocket.WebSocketHandler): def open(self): print("WebSocket opened") def on_message(self, message): self.write_message(u"You said: " + message) def on_close(self): print("WebSocket closed") .. testoutput:: :hide: WebSockets are not standard HTTP connections. The "handshake" is HTTP, but after the handshake, the protocol is message-based. Consequently, most of the Tornado HTTP facilities are not available in handlers of this type. The only communication methods available to you are `write_message()`, `ping()`, and `close()`. Likewise, your request handler class should implement `open()` method rather than ``get()`` or ``post()``. If you map the handler above to ``/websocket`` in your application, you can invoke it in JavaScript with:: var ws = new WebSocket("ws://localhost:8888/websocket"); ws.onopen = function() { ws.send("Hello, world"); }; ws.onmessage = function (evt) { alert(evt.data); }; This script pops up an alert box that says "You said: Hello, world". Web browsers allow any site to open a websocket connection to any other, instead of using the same-origin policy that governs other network access from javascript. This can be surprising and is a potential security hole, so since Tornado 4.0 `WebSocketHandler` requires applications that wish to receive cross-origin websockets to opt in by overriding the `~WebSocketHandler.check_origin` method (see that method's docs for details). Failure to do so is the most likely cause of 403 errors when making a websocket connection. When using a secure websocket connection (``wss://``) with a self-signed certificate, the connection from a browser may fail because it wants to show the "accept this certificate" dialog but has nowhere to show it. You must first visit a regular HTML page using the same certificate to accept it before the websocket connection will succeed. If the application setting ``websocket_ping_interval`` has a non-zero value, a ping will be sent periodically, and the connection will be closed if a response is not received before the ``websocket_ping_timeout``. Messages larger than the ``websocket_max_message_size`` application setting (default 10MiB) will not be accepted. .. versionchanged:: 4.5 Added ``websocket_ping_interval``, ``websocket_ping_timeout``, and ``websocket_max_message_size``. c s<