1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
U
[±dã@sÆdZddlmZddlmZddlmZmZmZm    Z    ddl
m Z m Z m Z mZmZmZmZddlmZddlmZmZmZmZdd    lmZGd
d „d eƒZGd d „d eƒZejZejZGdd„dƒZdS)zU
wsproto/connection
~~~~~~~~~~~~~~~~~~
 
An implementation of a WebSocket connection.
é)Údeque)ÚEnum)ÚDequeÚ    GeneratorÚListÚOptionalé)Ú BytesMessageÚCloseConnectionÚEventÚMessageÚPingÚPongÚ TextMessage)Ú    Extension)Ú CloseReasonÚ FrameProtocolÚOpcodeÚ ParseFailed)ÚLocalProtocolErrorc@s(eZdZdZdZdZdZdZdZdZ    dS)    ÚConnectionStatez1
    RFC 6455, Section 4 - Opening Handshake
    rrééééN)
Ú__name__Ú
__module__Ú __qualname__Ú__doc__Z
CONNECTINGÚOPENÚREMOTE_CLOSINGÚ LOCAL_CLOSINGÚCLOSEDZ    REJECTING©r#r#úId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\wsproto/connection.pyrsrc@seZdZdZdZdZdS)ÚConnectionTypez#An enumeration of connection types.rrN)rrrrÚCLIENTÚSERVERr#r#r#r$r%-sr%c@s|eZdZdZdeeeeeddœdd„Z    e
e dœdd    „ƒZ e ed
œd d „Zeedd œdd„Zee ddfdœdd„ZdS)Ú
Connectionaä
    A low-level WebSocket connection object.
 
    This wraps two other protocol objects, an HTTP/1.1 protocol object used
    to do the initial HTTP upgrade handshake and a WebSocket frame protocol
    object used to exchange messages and other control frames.
 
    :param conn_type: Whether this object is on the client- or server-side of
        a connection. To initialise as a client pass ``CLIENT`` otherwise
        pass ``SERVER``.
    :type conn_type: ``ConnectionType``
    Nó)Úconnection_typeÚ
extensionsÚ trailing_dataÚreturncCs<|tjk|_tƒ|_t|j|p gƒ|_tj|_    | 
|¡dS©N) r%r&ÚclientrÚ_eventsrÚ_protorrÚ_stateÚ receive_data)Úselfr*r+r,r#r#r$Ú__init__Is
 zConnection.__init__)r-cCs|jSr.)r2)r4r#r#r$ÚstateUszConnection.state)Úeventr-cCsôd}t|tƒr2|jtjkr2||j |j|j¡7}n¾t|t    ƒr\|jtjkr\||j 
|j ¡7}n”t|t ƒr†|jtjkr†||j  |j ¡7}njt|tƒrØ|jtjtjhkrØ||j |j|j¡7}|jtjkrÎtj|_qðtj|_ntd|›d|j›dƒ‚|S)Nr)zEvent z cannot be sent in state Ú.)Ú
isinstancer r6rrr1Z    send_dataÚdataÚmessage_finishedr ZpingÚpayloadrZpongr
r ÚcloseÚcodeÚreasonr"r2r!r)r4r7r:r#r#r$ÚsendYs&þ 
 
ÿzConnection.send)r:r-cCsb|dkr(|j ttjd¡tj|_dS|jtj    tj
fkrH|j   |¡n|jtjkr^t dƒ‚ndS)aO
        Pass some received data to the connection for handling.
 
        A list of events that the remote peer triggered by sending this data can
        be retrieved with :meth:`~wsproto.connection.Connection.events`.
 
        :param data: The data received from the remote peer on the network.
        :type data: ``bytes``
        N)r>zConnection already closed.)r0Úappendr
rZABNORMAL_CLOSURErr"r2r6rr!r1Z receive_bytesr)r4r:r#r#r$r3ps  
zConnection.receive_datac
cs°|jr|j ¡Vqz\|j ¡D]J}|jtjkrh|jr@|jsDt    ‚t
|j t t fƒsXt    ‚t|j dVq"|jtjkr¨|jr€|js„t    ‚t
|j t t fƒs˜t    ‚t|j dVq"|jtjkrüt
|j tƒsÄt    ‚|j \}}|jtjkrätj|_ntj|_t||dVq"|jtjkr4t
|j tƒst    ‚t|j |j|jdVq"|jtjkr"t
|j t t fƒsVt    ‚t|j |j|jdVq"q"Wn8tk
rª}zt|j t|ƒdVW5d}~XYnXdS)zÅ
        Return a generator that provides any events that have been generated
        by protocol activity.
 
        :returns: generator of :class:`Event <wsproto.events.Event>` subclasses
        )r<)r>r?)r:Úframe_finishedr;N)!r0Úpopleftr1Zreceived_framesÚopcoderZPINGrBr;ÚAssertionErrorr9r<ÚbytesÚ    bytearrayr ZPONGrZCLOSEÚtupler6rr!r"r2r r
ZTEXTÚstrrÚBINARYr    rr>)r4Úframer>r?Úexcr#r#r$Úevents‹sH   
 
ý
 ý
zConnection.events)Nr))rrrrr%rrrrFr5Úpropertyrr6r r@r3rrMr#r#r#r$r(;sü
û r(N) rÚ collectionsrÚenumrÚtypingrrrrrMr    r
r r r rrr+rZframe_protocolrrrrZ    utilitiesrrr%r&r'r(r#r#r#r$Ú<module>s  $