WebSocket
class¶
Importing the WebSocket
from esmerald
is as simple as:
from esmerald import WebSocket
esmerald.WebSocket
¶
WebSocket(scope, receive, send)
Bases: WebsocketMixin
PARAMETER | DESCRIPTION |
---|---|
scope
|
TYPE:
|
receive
|
TYPE:
|
send
|
TYPE:
|
Source code in lilya/websockets.py
20 21 22 23 24 25 26 27 |
|
set_session
¶
set_session(value)
Sets the value of a request session by passing a dictionary.
PARAMETER | DESCRIPTION |
---|---|
value
|
TYPE:
|
Source code in lilya/_internal/_connection.py
176 177 178 179 180 |
|
clear_session
¶
clear_session()
Clears the scope session.
Source code in lilya/_internal/_connection.py
182 183 184 185 186 |
|
is_secure
¶
is_secure()
Check if the connection is secure (HTTPS).
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the connection is secure (HTTPS), False otherwise.
TYPE:
|
Source code in lilya/_internal/_connection.py
188 189 190 191 192 193 194 195 |
|
path_for
¶
path_for(name, /, **path_params)
PARAMETER | DESCRIPTION |
---|---|
name
|
TYPE:
|
**path_params
|
TYPE:
|
Source code in lilya/_internal/_connection.py
197 198 199 200 |
|
raise_for_disconnect
¶
raise_for_disconnect(message)
PARAMETER | DESCRIPTION |
---|---|
message
|
TYPE:
|
Source code in lilya/websockets.py
29 30 31 |
|
raise_for_connection_state
async
¶
raise_for_connection_state()
Source code in lilya/websockets.py
33 34 35 |
|
receive
async
¶
receive()
Receive ASGI websocket messages, ensuring valid state transitions.
Source code in lilya/websockets.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
send
async
¶
send(message)
Send ASGI websocket messages, ensuring valid state transitions.
PARAMETER | DESCRIPTION |
---|---|
message
|
TYPE:
|
Source code in lilya/websockets.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
accept
async
¶
accept(subprotocol=None, headers=None)
PARAMETER | DESCRIPTION |
---|---|
subprotocol
|
TYPE:
|
headers
|
TYPE:
|
Source code in lilya/websockets.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
receive_text
async
¶
receive_text()
Source code in lilya/websockets.py
126 127 128 129 130 131 |
|
receive_bytes
async
¶
receive_bytes()
Source code in lilya/websockets.py
133 134 135 136 137 138 |
|
receive_json
async
¶
receive_json(mode='text')
PARAMETER | DESCRIPTION |
---|---|
mode
|
TYPE:
|
Source code in lilya/websockets.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
iter_text
async
¶
iter_text()
Source code in lilya/websockets.py
155 156 157 158 159 160 |
|
iter_bytes
async
¶
iter_bytes()
Source code in lilya/websockets.py
162 163 164 165 166 167 |
|
iter_json
async
¶
iter_json()
Source code in lilya/websockets.py
169 170 171 172 173 174 |
|
send_text
async
¶
send_text(data)
PARAMETER | DESCRIPTION |
---|---|
data
|
TYPE:
|
Source code in lilya/websockets.py
176 177 |
|
send_bytes
async
¶
send_bytes(data)
PARAMETER | DESCRIPTION |
---|---|
data
|
TYPE:
|
Source code in lilya/websockets.py
179 180 |
|
send_json
async
¶
send_json(data, mode='text')
PARAMETER | DESCRIPTION |
---|---|
data
|
TYPE:
|
mode
|
TYPE:
|
Source code in lilya/websockets.py
182 183 184 185 186 187 188 189 190 191 192 |
|
close
async
¶
close(code=1000, reason=None)
PARAMETER | DESCRIPTION |
---|---|
code
|
TYPE:
|
reason
|
TYPE:
|
Source code in lilya/websockets.py
194 195 |
|
esmerald.WebSocketDisconnect
¶
WebSocketDisconnect(code=1000, reason=None)
Bases: WebSocketDisconnect
Esmerald WebSocketDisconnect
PARAMETER | DESCRIPTION |
---|---|
code
|
TYPE:
|
reason
|
TYPE:
|
Source code in esmerald/websockets.py
15 16 |
|