ó
    ð›‘hJ€  ã                   ó´  • S SK JrJr  S SKJr  S SKJr  S SKr\R                  " 5         S SK	r
S SKJr  S SKJr  S SKJrJrJr  S SKJr  S S	KJr  S S
K	Jr  S SKJrJrJr  S SKJrJr  S SKJr  S SK J!r!  S SK"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)  S SK*J+r+J,r,  S SK-J.r.J/r/J0r0J1r1  Sr2S r3S r4S r5S r6 " S S\)5      r7 " S S\
Rp                  RN                  Rr                  5      r:\ " S S\:\'Rv                  5      5       r;\ " S S \:\'Rx                  5      5       r< " S! S"\=5      r>\ " S# S$\>\'R~                  \
Rp                  RN                  R€                  5      5       r?\ " S% S&\>\'R‚                  \
Rp                  RN                  R„                  5      5       rA\" \5       " S' S(\=5      5       rC " S) S*\C\;5      rD " S+ S,\C\<5      rE " S- S.\?5      rF " S/ S0\A5      rG\S;S1 j5       rH\S<S2 j5       rI\ " S3 S4\R”                  \;5      5       rJ\ " S5 S6\R–                  \?5      5       rK\ " S7 S8\R˜                  \<5      5       rL\ " S9 S:\Rš                  \A5      5       rMg)=é    )Ú	b64encodeÚ	b64decode)ÚOptional)ÚimplementerN)Ú	endpoints)Ú
ITransport)ÚConnectionDoneÚConnectionAbortedÚConnectionLost)ÚDeferred)ÚFailure)ÚconnectionDone)ÚpublicÚhltypeÚhlval)Ú_is_tls_errorÚ_maybe_tls_reason)Ú	websocket)ÚTransportDetails)ÚConnectionRequestÚConnectionResponseÚConnectionDeny)Úprotocol)ÚIWebSocketClientAgent)Úcreate_transport_detailsÚtransport_channel_id)ÚPerMessageDeflateOfferÚPerMessageDeflateOfferAcceptÚPerMessageDeflateResponseÚPerMessageDeflateResponseAccept)Úcreate_client_agentÚWebSocketAdapterProtocolÚWebSocketServerProtocolÚWebSocketClientProtocolÚWebSocketAdapterFactoryÚWebSocketServerFactoryÚWebSocketClientFactoryÚWrappingWebSocketAdapterÚWrappingWebSocketServerProtocolÚWrappingWebSocketClientProtocolÚWrappingWebSocketServerFactoryÚWrappingWebSocketClientFactoryÚlistenWSÚ	connectWSÚWampWebSocketServerProtocolÚWampWebSocketServerFactoryÚWampWebSocketClientProtocolÚWampWebSocketClientFactoryc                 ó   • [        U 5      $ )z:
:returns: an instance implementing IWebSocketClientAgent
)Ú_TwistedWebSocketClientAgent©Úreactors    Ú^C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\autobahn/twisted/websocket.pyr!   r!   V   s   € ô (¨Ó0Ð0ó    c                 óâ   • [        U [        5      (       d#  [        SR                  [	        U 5      5      5      eU R                  S5      (       d!  U R                  S5      (       d  [        S5      eg)z6
raises a ValueError if `transport_config` is invalid
z-'transport_config' must be a string, found {}zws://zwss://z6'transport_config' must start with 'ws://' or 'wss://'N)Ú
isinstanceÚstrÚ
ValueErrorÚformatÚtypeÚ
startswith)Útransport_configs    r7   Úcheck_transport_configrA   ]   sl   € ô
 Ð&¬×,Ñ,ÜØ;×BÑBÄ4ÐHXÓCYÓZó
ð 	
ð ×&Ñ& w×/Ñ/Ø×&Ñ& x×0Ñ0ÜØDó
ð 	
ð r8   c                 ó¸   • [        U [        5      (       d  [        S5      e/ SQnU R                  5        H"  nX!;  d  M
  [        SR	                  U5      5      e   g)z-
raises a ValueError if `options` is invalid
z'options' must be a dict)ÚoriginÚ	protocolsÚ	useragentÚheadersÚproxyz'options' may not contain '{}'N)r:   Údictr<   Úkeysr=   )ÚoptionsÚ
valid_keysÚactual_ks      r7   Úcheck_client_optionsrM   q   s[   € ô
 �gœt×$Ñ$ÜØ&ó
ð 	
ò
€Jð —L‘L–NˆØÕ%ÜØ0×7Ñ7¸ÓAóð ò #r8   c                 óÞ  • UR                   (       a!  SSKJn  UR                  UR                  5      nUR
                  b;  WUl        [        R                  " U UR
                  S   UR
                  S   5      nU$ UR                   (       a5  SSKJn  [        R                  " U UR                  UR                  W5      nU$ [        R                  " U UR                  UR                  5      nU$ )Nr   ©ÚsslÚhostÚport)ÚisSecureÚtwisted.internetrP   ÚoptionsForClientTLSrQ   rG   ÚcontextFactoryr   ÚHostnameEndpointÚSSL4ClientEndpointrR   )r6   Úfactoryr@   rJ   rP   Úcontext_factoryÚendpoints          r7   Ú_endpoint_from_configr\   Š   sË   € ð ××å(Ø×1Ñ1°'·,±,Ó?ˆà‡}�}Ñ Ø!0ˆÔÜ×-Ò-ØØ�M‰M˜&Ñ!Ø�M‰M˜&Ñ!ó
ˆð0 €Oð# ××Ý,Ü ×3Ò3ØØ—‘Ø—‘Øó	ˆHð €Oô !×1Ò1ØØ—‘Ø—‘óˆHð €Or8   c                   ó(   • \ rS rSrSrS rSS jrSrg)r4   é³   z.
This agent creates connections using Twisted
c                 ó   • Xl         g ©N©Ú_reactor)Úselfr6   s     r7   Ú__init__Ú%_TwistedWebSocketClientAgent.__init__¸   s   € Ø�r8   Nc                 ó(  ^^	• [        U5        [        U5        [        SUU R                  S.UD6nUc  [        OUUl        [        U R                  XAU5      n[        5       m	UR                  U5      nU	4S jmUU	4S jnUR                  UT5        T	$ )aÕ  
Open a new connection.

:param dict transport_config: valid transport configuration

:param dict options: additional options for the factory

:param protocol_class: a callable that returns an instance of
    the protocol (WebSocketClientProtocol if the default None
    is passed in)

:returns: a Deferred that fires with an instance of
    `protocol_class` (or WebSocketClientProtocol by default)
    that has successfully shaken hands (completed the
    handshake).
)Úurlr6   c                 ó(   >• TR                  U 5        g r`   )Úerrback)ÚfÚrtn_ds    €r7   ÚfailedÚ1_TwistedWebSocketClientAgent.open.<locals>.failedÜ   s   ø€ Ø�M‰M˜!Õr8   c                 óP   >^ • U U4S jnT R                   R                  UT5        T $ )Nc                 ó*   >• TR                  T5        U $ r`   )Úcallback)ÚargÚprotork   s    €€r7   Úhandshake_completedÚQ_TwistedWebSocketClientAgent.open.<locals>.got_proto.<locals>.handshake_completedá   s   ø€ Ø—‘˜uÔ%Ø�
r8   )Úis_openÚaddCallbacks)rr   rs   rl   rk   s   ` €€r7   Ú	got_protoÚ4_TwistedWebSocketClientAgent.open.<locals>.got_protoß   s$   ù€ öð �M‰M×&Ñ&Ð':¸FÔCØˆLr8   © )
rA   rM   r'   rb   r$   r   r\   r   Úconnectrv   )
rc   r@   rJ   Úprotocol_classrY   r[   Úproto_drw   rl   rk   s
           @@r7   ÚopenÚ!_TwistedWebSocketClientAgent.open»   sš   ù€ ô" 	Ð/Ô0Ü˜WÔ%ä(ð 
Ø Ø—M‘Mñ
ð ñ
ˆð
 7EÑ6LÕ2ÐR`ˆÔô )¨¯©¸ÐSZÓ[ˆä“
ˆØ×"Ñ" 7Ó+ˆõ	ö	ð 	×Ñ˜Y¨Ô/Øˆr8   ra   r`   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rd   r}   Ú__static_attributes__ry   r8   r7   r4   r4   ³   s   † ñò ÷,r8   r4   c                   óä   • \ rS rSr% Sr\R                  " 5       rSr\	\
   \S'   Sr\	\   \S'   S r\4S\4S jjrS	\4S
 jrSS jrS rS rS rS rS rS rS rS rS rS rS rS r S r!Sr"g)r"   éê   ap  
Adapter class for Twisted WebSocket client and server protocols.

Called from Twisted:

* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.connectionMade`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.connectionLost`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.dataReceived`

Called from Network-independent Code (WebSocket implementation):

* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onOpen`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageBegin`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageFrameData`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageFrameEnd`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageEnd`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessage`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onPing`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onPong`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onClose`

FIXME:

* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._closeConnection`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._create_transport_details`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.registerProducer`
* :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.unregisterProducer`
NÚpeerÚ	is_serverc                 ó¾  • [        U R                  U R                  5      U l        [        R
                  U R                  l        U R                  R                  U l         U R                  R                  U R                  5        U R                  5         U R                  R                  S[        U R                  5      [        U R                  5      S9  g !    NV= f)Nz/{func} connection established for peer="{peer}"©Úfuncr‡   )r   Ú	transportrˆ   Ú_transport_detailsr   ÚCHANNEL_FRAMING_WEBSOCKETÚchannel_framingr‡   ÚsetTcpNoDelayÚ
tcpNoDelayÚ_connectionMadeÚlogÚdebugr   ÚconnectionMader   ©rc   s    r7   r•   Ú'WebSocketAdapterProtocol.connectionMade  s«   € ô
 #;¸4¿>¹>È4Ï>É>Ó"ZˆÔÜ2B×2\Ñ2\ˆ×ÑÔ/ð ×+Ñ+×0Ñ0ˆŒ	ð	Ø�N‰N×(Ñ(¨¯©Ô9ð 	×ÑÔð 	�‰�‰ÐHÜ" 4×#6Ñ#6Ó7Ü! $§)¡)Ó,ð 	ò 	.øð	áús   Á!%C ÃCÚreasonc                 ó†  • Sn[        UR                  [        5      (       a(  U R                  R	                  SU R
                  S9  SnGO\[        UR                  5      (       a0  U R                  R                  [        UR                  5      5        GO[        UR                  [        5      (       a%  U R                  R	                  SU R
                  S9  OÎ[        UR                  [        5      (       al  [        UR                  5      n[        UR                  S5      (       a  UR                  R                  nU R                  R	                  SU R
                  US9  OCU R                  R	                  S	U R
                  [        UR                  5      UR                  S
9  U R                  U5        U(       aB  U R                  R	                  S[!        U R"                  5      [%        U R
                  5      S9  g U R                  R	                  S[!        U R"                  5      [%        U R
                  5      US9  g )NFz,Connection to/from {peer} was closed cleanly)r‡   Tz-Connection to/from {peer} was aborted locallyÚmessagezDConnection to/from {peer} was lost in a non-clean fashion: {message})r‡   rš   z7Connection to/from {peer} lost ({error_type}): {error}))r‡   Ú
error_typeÚerrorz8{func} connection lost for peer="{peer}", closed cleanlyrŠ   zD{func} connection lost for peer="{peer}", closed with error {reason})r‹   r‡   r˜   )r:   Úvaluer	   r“   r”   r‡   r   rœ   r   r
   r   r;   Úhasattrrš   r>   Ú_connectionLostr   ÚconnectionLostr   )rc   r˜   Ú	was_cleanrš   s       r7   r    Ú'WebSocketAdapterProtocol.connectionLost'  s¯  € ð ˆ	Ü�f—l‘l¤N×3Ñ3Ø�H‰H�N‰NÐIØ $§	¡	ð ñ +àŠIä˜6Ÿ<™<×(Ñ(Ø�H‰H�N‰NÔ,¨V¯\©\Ó:Ö;ä˜Ÿ™Ô&7×8Ñ8Ø�H‰H�N‰NÐJØ $§	¡	ð ò +ô ˜Ÿ™¤n×5Ñ5Ü˜&Ÿ,™,Ó'ˆGÜ�v—|‘| Y×/Ñ/Ø Ÿ,™,×.Ñ.�Ø�H‰H�N‰NØVØ—Y‘YØð ò ð �H‰H�N‰NÐTØ $§	¡	´d¸6¿<¹<Ó6HÐPV×P\ÑP\ð ñ ^ð 	×Ñ˜VÔ$ö Ø�H‰H�N‰NÐUÜ & t×':Ñ':Ó ;Ü % d§i¡iÓ 0ð ò 2ð �H‰H�N‰NÐaÜ & t×':Ñ':Ó ;Ü % d§i¡iÓ 0Ø"(ð ò *r8   Údatac           
      óÎ   • U R                   R                  S[        U R                  5      [	        U R
                  5      [	        [        U5      5      S9  U R                  U5        g )Nz2{func} received {data_len} bytes for peer="{peer}")r‹   r‡   Údata_len)r“   r”   r   ÚdataReceivedr   r‡   ÚlenÚ_dataReceived©rc   r£   s     r7   r¦   Ú%WebSocketAdapterProtocol.dataReceivedU  sP   € Ø�‰�‰ÐKÜ" 4×#4Ñ#4Ó5Ü! $§)¡)Ó,Ü %¤c¨$£iÓ 0ð 	ñ 	2ð 	×Ñ˜4Õ r8   c                 ó²   • U(       a6  [        U R                  S5      (       a  U R                  R                  5         g U R                  R                  5         g )NÚabortConnection)rž   rŒ   r¬   ÚloseConnection)rc   Úaborts     r7   Ú_closeConnectionÚ)WebSocketAdapterProtocol._closeConnection^  s8   € Þ”W˜TŸ^™^Ð->×?Ñ?Ø�N‰N×*Ñ*Õ,ð �N‰N×)Ñ)Õ+r8   c                 óÔ   • U R                   R                  (       a=  S[        U R                  U R                   R                  S5      0nXR                   l        U R                  5         g )Nz
tls-unique)r�   Ú	is_securer   rŒ   rˆ   Ú
channel_idÚonOpen)rc   r³   s     r7   Ú_onOpenÚ WebSocketAdapterProtocol._onOpene  sQ   € Ø×"Ñ"×,×,ð Ô2°4·>±>À4×CZÑCZ×CdÑCdÐfrÓsðˆJð 2<×#Ñ#Ô.à�‰�r8   c                 ó&   • U R                  U5        g r`   )ÚonMessageBegin)rc   ÚisBinarys     r7   Ú_onMessageBeginÚ(WebSocketAdapterProtocol._onMessageBeginp  s   € Ø×Ñ˜HÕ%r8   c                 ó&   • U R                  U5        g r`   )ÚonMessageFrameBegin)rc   Úlengths     r7   Ú_onMessageFrameBeginÚ-WebSocketAdapterProtocol._onMessageFrameBegins  s   € Ø× Ñ  Õ(r8   c                 ó&   • U R                  U5        g r`   )ÚonMessageFrameData©rc   Úpayloads     r7   Ú_onMessageFrameDataÚ,WebSocketAdapterProtocol._onMessageFrameDatav  s   € Ø×Ñ Õ(r8   c                 ó$   • U R                  5         g r`   )ÚonMessageFrameEndr–   s    r7   Ú_onMessageFrameEndÚ+WebSocketAdapterProtocol._onMessageFrameEndy  s   € Ø×ÑÕ r8   c                 ó&   • U R                  U5        g r`   )ÚonMessageFramerÃ   s     r7   Ú_onMessageFrameÚ(WebSocketAdapterProtocol._onMessageFrame|  s   € Ø×Ñ˜GÕ$r8   c                 ó$   • U R                  5         g r`   )ÚonMessageEndr–   s    r7   Ú_onMessageEndÚ&WebSocketAdapterProtocol._onMessageEnd  s   € Ø×ÑÕr8   c                 ó&   • U R                  X5        g r`   )Ú	onMessage)rc   rÄ   r¹   s      r7   Ú
_onMessageÚ#WebSocketAdapterProtocol._onMessage‚  s   € Ø�‰�wÕ)r8   c                 ó&   • U R                  U5        g r`   )ÚonPingrÃ   s     r7   Ú_onPingÚ WebSocketAdapterProtocol._onPing…  ó   € Ø�‰�GÕr8   c                 ó&   • U R                  U5        g r`   )ÚonPongrÃ   s     r7   Ú_onPongÚ WebSocketAdapterProtocol._onPongˆ  rÛ   r8   c                 ó(   • U R                  XU5        g r`   )ÚonClose©rc   ÚwasCleanÚcoder˜   s       r7   Ú_onCloseÚ!WebSocketAdapterProtocol._onClose‹  s   € Ø�‰�X VÕ,r8   c                 ó:   • U R                   R                  X5        g)z²
Register a Twisted producer with this protocol.

:param producer: A Twisted push or pull producer.
:type producer: object
:param streaming: Producer type.
:type streaming: bool
N)rŒ   ÚregisterProducer)rc   ÚproducerÚ	streamings      r7   rè   Ú)WebSocketAdapterProtocol.registerProducerŽ  s   € ð 	�‰×'Ñ'¨Õ<r8   c                 ó8   • U R                   R                  5         g)z1
Unregister Twisted producer with this protocol.
N)rŒ   ÚunregisterProducerr–   s    r7   rí   Ú+WebSocketAdapterProtocol.unregisterProducer™  s   € ð 	�‰×)Ñ)Õ+r8   )r�   r‡   )F)#r   r€   r�   r‚   rƒ   ÚtxaioÚmake_loggerr“   r‡   r   r;   Ú__annotations__rˆ   Úboolr•   r   r   r    Úbytesr¦   r¯   rµ   rº   r¿   rÅ   rÉ   rÍ   rÑ   rÕ   rÙ   rÞ   rå   rè   rí   r„   ry   r8   r7   r"   r"   ê   sœ   ‡ ñð: ×
Ò
Ó
€Cà€Dˆ(�3‰-ÓØ $€Iˆx˜‰~Ó$ò.ð4 0>ñ ,* Wõ ,*ð\! ô !ô,ò	ò&ò)ò)ò!ò%òò*òòò-ò	=õ,r8   r"   c                   ó>   • \ rS rSrSr\R                  " 5       rSrSr	g)r#   i   z€
Base class for Twisted-based WebSocket server protocols.

Implements :class:`autobahn.websocket.interfaces.IWebSocketChannel`.
Try   N)
r   r€   r�   r‚   rƒ   rï   rð   r“   rˆ   r„   ry   r8   r7   r#   r#      s   † ñð ×
Ò
Ó
€CØƒIr8   r#   c                   óR   • \ rS rSrSr\R                  " 5       rSrS\	4S jr
S rSrg)	r$   i¯  z€
Base class for Twisted-based WebSocket client protocols.

Implements :class:`autobahn.websocket.interfaces.IWebSocketChannel`.
FÚresponsec                 ó€   • U R                   R                  S[        U R                  5      US9  U R	                  U5      $ )Nz{meth}(response={response}))Úmethrö   )r“   r”   r   Ú
_onConnectÚ	onConnect)rc   rö   s     r7   rù   Ú"WebSocketClientProtocol._onConnectº  s2   € Ø�‰�‰Ð4¼6À$Ç/Á/Ó;RÐ]eˆÑfØ�~‰~˜hÓ'Ð'r8   c                 ó˜   • U R                   R                  S5        U R                  R                  U R                  R
                  5        g )NzStarting TLS upgrade)r“   r”   rŒ   ÚstartTLSrY   rV   r–   s    r7   rý   Ú WebSocketClientProtocol.startTLS¾  s/   € Ø�‰�‰Ð-Ô.Ø�‰×Ñ §¡× ;Ñ ;Õ<r8   ry   N)r   r€   r�   r‚   rƒ   rï   rð   r“   rˆ   r   rù   rý   r„   ry   r8   r7   r$   r$   ¯  s.   † ñð ×
Ò
Ó
€CØ€Ið(Ð#5ô (õ=r8   r$   c                   ó   • \ rS rSrSrSrg)r%   iÃ  zH
Adapter class for Twisted-based WebSocket client and server factories.
ry   N©r   r€   r�   r‚   rƒ   r„   ry   r8   r7   r%   r%   Ã  ó   † ôr8   r%   c                   ó@   • \ rS rSrSr\R                  " 5       rS rSr	g)r&   iÉ  zŒ
Base class for Twisted-based WebSocket server factories.

Implements :class:`autobahn.websocket.interfaces.IWebSocketServerChannelFactory`
c                 óŽ   • UR                  SS5      nUc  SSKJn  X0l        [        R                  R
                  " U /UQ70 UD6  g)zî

.. note::
    In addition to all arguments to the constructor of
    :meth:`autobahn.websocket.interfaces.IWebSocketServerChannelFactory`,
    you can supply a ``reactor`` keyword argument to specify the
    Twisted reactor to be used.
r6   Nr   r5   )ÚpoprT   r6   r   r&   rd   )rc   ÚargsÚkwargsr6   s       r7   rd   ÚWebSocketServerFactory.__init__Ó  s?   € ð —*‘*˜Y¨Ó-ˆØ‰?Ý0ØŒä×'Ñ'×0Ò0°ÐG¸ÒGÀÓGr8   r5   N©
r   r€   r�   r‚   rƒ   rï   rð   r“   rd   r„   ry   r8   r7   r&   r&   É  s   † ñð ×
Ò
Ó
€CõHr8   r&   c                   ó@   • \ rS rSrSr\R                  " 5       rS rSr	g)r'   iå  zŒ
Base class for Twisted-based WebSocket client factories.

Implements :class:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`
c                 ó  • UR                  SS5      nUc  SSKJn  X0l        [        R                  R
                  " U /UQ70 UD6  U R                  (       a5  U R                  b'  SSKJn  UR                  U R                  5      U l        ggg)zî

.. note::
    In addition to all arguments to the constructor of
    :func:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`,
    you can supply a ``reactor`` keyword argument to specify the
    Twisted reactor to be used.
r6   Nr   r5   rO   )r  rT   r6   r   r'   rd   rS   rG   rP   rU   rQ   rV   )rc   r  r  r6   rP   s        r7   rd   ÚWebSocketClientFactory.__init__ï  st   € ð —*‘*˜Y¨Ó-ˆØ‰?Ý0ØŒä×'Ñ'×0Ò0°ÐG¸ÒGÀÒGð �=�=˜TŸZ™ZÑ3õ -Ø"%×"9Ñ"9¸$¿)¹)Ó"DˆDÕð 4ˆ=r8   )rV   r6   Nr  ry   r8   r7   r'   r'   å  s   † ñð ×
Ò
Ó
€CõEr8   r'   c                   óN   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)r(   i  aZ  
An adapter for stream-based transport over WebSocket.

This follows `websockify <https://github.com/kanaka/websockify>`_
and should be compatible with that.

It uses WebSocket subprotocol negotiation and supports the
following WebSocket subprotocols:

  - ``binary`` (or a compatible subprotocol)
  - ``base64``

Octets are either transmitted as the payload of WebSocket binary
messages when using the ``binary`` subprotocol (or an alternative
binary compatible subprotocol), or encoded with Base64 and then
transmitted as the payload of WebSocket text messages when using
the ``base64`` subprotocol.
c                 ón  • [        U[        5      (       ay  UnUR                   H*  nX0R                  R                  ;   d  M  US:g  U l        Us  $    [        [        R                  SR                  U R                  R                  5      5      e[        U[        5      (       aˆ  UnUR                  U R                  R                  ;  aM  U R                  [        R                  R                  SR                  U R                  R                  5      5        UR                  S:g  U l        g [        S5      e)NÚbase64z2this server only speaks {0} WebSocket subprotocolsz2this client only speaks {0} WebSocket subprotocolszlogic error)r:   r   rD   rY   Ú_subprotocolsÚ_binaryModer   ÚNOT_ACCEPTABLEr=   r   r   Ú_fail_connectionÚWebSocketProtocolÚ CLOSE_STATUS_CODE_PROTOCOL_ERRORÚ	Exception)rc   ÚrequestOrResponseÚrequestÚprö   s        r7   rú   Ú"WrappingWebSocketAdapter.onConnect$  s;  € äÐ'Ô):×;Ñ;Ø'ˆGØ×&Ô&�ØŸ™×2Ñ2Õ2Ø()¨X©�DÔ$Ø’Hñ 'ô !¤×!>Ñ!>Ð@t×@{Ñ@{ð  }A÷  }Iñ  }I÷  }Wñ  }Wó  AXó  Yð  YÜÐ)Ô+=×>Ñ>Ø(ˆHØ× Ñ ¨¯©×(BÑ(BÓBØ×%Ñ%¤h×&@Ñ&@×&aÑ&að  dX÷  d_ñ  d_ð  `d÷  `lñ  `l÷  `zñ  `zó  d{ô  |Ø (× 1Ñ 1°XÑ =ˆDÕô ˜MÓ*Ð*r8   c                 ó8   • U R                   R                  5         g r`   )Ú_protor•   r–   s    r7   r´   ÚWrappingWebSocketAdapter.onOpen6  s   € Ø�‰×"Ñ"Õ$r8   c                 ót  • X R                   :w  a+  U R                  [        R                  R                  S5        g U(       d   [        U5      nU R                  R                  U5        g ! [         aC  nU R                  [        R                  R                  SR                  U5      5         S nANdS nAff = f)Nz>message payload type does not match the negotiated subprotocolz*message payload base64 decoding error: {0})r  r  r   r  Ú"CLOSE_STATUS_CODE_UNSUPPORTED_DATAr   r  Ú!CLOSE_STATUS_CODE_INVALID_PAYLOADr=   r  r¦   )rc   rÄ   r¹   Úes       r7   rÔ   Ú"WrappingWebSocketAdapter.onMessage9  s³   € Ø×'Ñ'Ó'Ø×!Ñ!¤(×"<Ñ"<×"_Ñ"_ð  bbõ  cæð`Ü'¨Ó0�Gð �K‰K×$Ñ$ WÕ-øô !ó `Ø×)Ñ)¬(×*DÑ*D×*fÑ*fð  iU÷  i\ñ  i\ð  ]^ó  i_÷  `ñ  `ûð`ús   ÁA* Á*
B7Á49B2Â2B7c                 ó:   • U R                   R                  S 5        g r`   )r  r    râ   s       r7   rá   Ú WrappingWebSocketAdapter.onCloseE  s   € Ø�‰×"Ñ" 4Õ(r8   c                 ó¨   • [        U5      [        :X  d   eU R                  (       a  U R                  USS9  g [	        U5      nU R                  USS9  g )NT)r¹   F)r>   ró   r  ÚsendMessager   r©   s     r7   ÚwriteÚWrappingWebSocketAdapter.writeH  sL   € ä�D‹zœUÓ"Ð#Ð"Ø××Ø×Ñ˜T¨DÐÒ1ä˜T“?ˆDØ×Ñ˜T¨EÐÒ2r8   c                 ó8   • U H  nU R                  U5        M     g r`   )r&  )rc   r£   Úds      r7   ÚwriteSequenceÚ&WrappingWebSocketAdapter.writeSequenceQ  s   € ãˆAØ�J‰J�qŽMò r8   c                 ó$   • U R                  5         g r`   )Ú	sendCloser–   s    r7   r­   Ú'WrappingWebSocketAdapter.loseConnectionV  s   € à�‰Õr8   c                 ó6   • U R                   R                  5       $ r`   )rŒ   ÚgetPeerr–   s    r7   r0  Ú WrappingWebSocketAdapter.getPeerZ  ó   € à�~‰~×%Ñ%Ó'Ð'r8   c                 ó6   • U R                   R                  5       $ r`   )rŒ   ÚgetHostr–   s    r7   r4  Ú WrappingWebSocketAdapter.getHost^  r2  r8   )r  N)r   r€   r�   r‚   rƒ   rú   r´   rÔ   rá   r&  r*  r­   r0  r4  r„   ry   r8   r7   r(   r(     s4   † ñò&+ò$%ò	.ò)ò3òò
ò(õ(r8   r(   c                   ó   • \ rS rSrSrSrg)r)   ic  z<
Server protocol for stream-based transport over WebSocket.
ry   Nr   ry   r8   r7   r)   r)   c  r  r8   r)   c                   ó   • \ rS rSrSrSrg)r*   ii  z<
Client protocol for stream-based transport over WebSocket.
ry   Nr   ry   r8   r7   r*   r*   i  r  r8   r*   c                   ó<   • \ rS rSrSr    S	S jrS rS rS rSr	g)
r+   io  zD
Wrapping server factory for stream-based transport over WebSocket.
Nc                 ó  • Xl         SS/U l        U(       a  U R                  R                  U5        [        R	                  U UUU R                  S9  U R                  US9  U R                  SS9  U(       a  S nU R                  US9  g	g	)
z×

:param factory: Stream-based factory to be wrapped.
:type factory: A subclass of ``twisted.internet.protocol.Factory``
:param url: WebSocket URL of the server this server factory will work for.
:type url: unicode
Úbinaryr  ©rg   r6   rD   ©ÚautoFragmentSizeF©Ú
failByDropc                 óZ   • U  H%  n[        U[        5      (       d  M  [        U5      s  $    g r`   )r:   r   r   )ÚoffersÚoffers     r7   ÚacceptÚ7WrappingWebSocketServerFactory.__init__.<locals>.accept—  s%   € Û#�EÜ! %Ô)?×@Ó@Ü;¸EÓBÒBò $r8   ©ÚperMessageCompressionAcceptN)Ú_factoryr  Úappendr&   rd   ÚsetProtocolOptions)rc   rY   rg   r6   ÚenableCompressionr=  ÚsubprotocolrC  s           r7   rd   Ú'WrappingWebSocketServerFactory.__init__t  sš   € ð  ŒØ&¨Ð1ˆÔÞØ×Ñ×%Ñ% kÔ2ä×'Ñ'¨Ø,/Ø07Ø26×2DÑ2Dð 	(ñ 	Fð 	×ÑÐ1AÐÑBð 	×Ñ¨5ÐÑ1æòCð
 ×#Ñ#ÀÐ#ÒGð r8   c                 ó†   • [        5       nXl        U R                  R                  U5      Ul        X"R                  l        U$ r`   )r)   rY   rG  ÚbuildProtocolr  rŒ   ©rc   Úaddrrr   s      r7   rN  Ú,WrappingWebSocketServerFactory.buildProtocolž  ó4   € Ü/Ó1ˆØŒØ—}‘}×2Ñ2°4Ó8ˆŒØ!&�‰ÔØˆr8   c                 ób   • U R                   R                  5         [        R                  U 5        g r`   )rG  ÚstartFactoryr&   r–   s    r7   rT  Ú+WrappingWebSocketServerFactory.startFactory¥  s    € Ø�‰×"Ñ"Ô$Ü×+Ñ+¨DÕ1r8   c                 ób   • U R                   R                  5         [        R                  U 5        g r`   )rG  ÚstopFactoryr&   r–   s    r7   rW  Ú*WrappingWebSocketServerFactory.stopFactory©  s    € Ø�‰×!Ñ!Ô#Ü×*Ñ*¨4Õ0r8   ©rG  r  ©NTr   N)
r   r€   r�   r‚   rƒ   rd   rN  rT  rW  r„   ry   r8   r7   r+   r+   o  s+   † ñð Ø#'Ø"#Ø!ô(HòTò2õ1r8   r+   c                   ó0   • \ rS rSrSr    SS jrS rSrg)r,   i®  zD
Wrapping client factory for stream-based transport over WebSocket.
Nc                 óJ  • Xl         SS/U l        U(       a  U R                  R                  U5        [        R	                  U UUU R                  S9  U R                  US9  U R                  SS9  U(       a-  [        5       /nU R                  US9  S nU R                  US	9  g
g
)zÙ

:param factory: Stream-based factory to be wrapped.
:type factory: A subclass of ``twisted.internet.protocol.Factory``
:param url: WebSocket URL of the server this client factory will connect to.
:type url: unicode
r:  r  r;  r<  Fr>  )ÚperMessageCompressionOffersc                 óD   • [        U [        5      (       a  [        U 5      $ g r`   )r:   r   r    )rö   s    r7   rC  Ú7WrappingWebSocketClientFactory.__init__.<locals>.acceptÚ  s!   € Ü˜hÔ(A×BÑBÜ:¸8ÓDÐDð Cr8   rE  N)rG  r  rH  r'   rd   rI  r   )	rc   rY   rg   r6   rJ  r=  rK  rA  rC  s	            r7   rd   Ú'WrappingWebSocketClientFactory.__init__³  s¸   € ð  ŒØ&¨Ð1ˆÔÞØ×Ñ×%Ñ% kÔ2ä×'Ñ'¨Ø,/Ø07Ø26×2DÑ2Dð 	(ñ 	Fð 	×ÑÐ1AÐÑBð 	×Ñ¨5ÐÑ1æô -Ó.Ð/ˆFØ×#Ñ#ÀÐ#ÑGòEð ×#Ñ#ÀÐ#ÒGð r8   c                 ó†   • [        5       nXl        U R                  R                  U5      Ul        X"R                  l        U$ r`   )r*   rY   rG  rN  r  rŒ   rO  s      r7   rN  Ú,WrappingWebSocketClientFactory.buildProtocolà  rR  r8   rY  rZ  )r   r€   r�   r‚   rƒ   rd   rN  r„   ry   r8   r7   r,   r,   ®  s!   † ñð Ø#'Ø"#Ø!ô+HõZr8   r,   c                 óî  • [        U S5      (       a  U R                  nOSSKJn  U R                  (       a  Uc  SSKJn  UR                  5       nU R                  b6  Xl        UR                  U R                  S   U R                  S   XU5      nU$ U R                  (       a*  UR                  U R                  U R                  XX#5      nU$ UR                  U R                  U R                  XU5      nU$ )aß  
Establish WebSocket connection to a server. The connection parameters like target
host, port, resource and others are provided via the factory.

:param factory: The WebSocket protocol factory to be used for creating client protocol instances.
:type factory: An :class:`autobahn.websocket.WebSocketClientFactory` instance.

:param contextFactory: SSL context factory, required for secure WebSocket connections ("wss").
:type contextFactory: A `twisted.internet.ssl.ClientContextFactory <http://twistedmatrix.com/documents/current/api/twisted.internet.ssl.ClientContextFactory.html>`_ instance.

:param timeout: Number of seconds to wait before assuming the connection has failed.
:type timeout: int

:param bindAddress: A (host, port) tuple of local address to bind to, or None.
:type bindAddress: tuple

:returns: The connector.
:rtype: An object which implements `twisted.interface.IConnector <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IConnector.html>`_.
r6   r   r5   rO   rQ   rR   )rž   r6   rT   rS   rP   ÚClientContextFactoryrG   rV   Ú
connectTCPÚ
connectSSLrQ   rR   )rY   rV   ÚtimeoutÚbindAddressr6   rP   Úconns          r7   r.   r.   è  sÕ   € ô, ˆw˜	×"Ñ"Ø—/‘/‰å,à××ØÑ!å,Ø ×5Ñ5Ó7ˆNà‡}�}Ñ Ø!/ÔØ×!Ñ! '§-¡-°Ñ"7¸¿¹ÀvÑ9NÐPWÐbmÓnˆð €Kð	 ××Ø×%Ñ% g§l¡l°G·L±LÀ'Ð[bÓpˆDð €Kð ×%Ñ% g§l¡l°G·L±LÀ'ÐT_Ó`ˆDØ€Kr8   c                 ó  • [        U S5      (       a  U R                  nOSSKJn  U R                  (       a-  Uc  [	        S5      eUR                  U R                  XX#5      nU$ UR                  U R                  XU5      nU$ )aZ  
Listen for incoming WebSocket connections from clients. The connection parameters like
listening port and others are provided via the factory.

:param factory: The WebSocket protocol factory to be used for creating server protocol instances.
:type factory: An :class:`autobahn.websocket.WebSocketServerFactory` instance.

:param contextFactory: SSL context factory, required for secure WebSocket connections ("wss").
:type contextFactory: A twisted.internet.ssl.ContextFactory.

:param backlog: Size of the listen queue.
:type backlog: int

:param interface: The interface (derived from hostname given) to bind to, defaults to '' (all).
:type interface: str

:returns: The listening port.
:rtype: An object that implements `twisted.interface.IListeningPort <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IListeningPort.html>`_.
r6   r   r5   zCSecure WebSocket listen requested, but no SSL context factory given)rž   r6   rT   rS   r  Ú	listenSSLrR   Ú	listenTCP)rY   rV   ÚbacklogÚ	interfacer6   Úlisteners         r7   r-   r-     sv   € ô, ˆw˜	×"Ñ"Ø—/‘/‰å,à××ØÑ!ÜÐaÓbÐbØ×$Ñ$ W§\¡\°7ÈGÓ_ˆð €Oð ×$Ñ$ W§\¡\°7ÀYÓOˆØ€Or8   c                   ó   • \ rS rSrSrSrg)r/   i8  zq
Twisted-based WAMP-over-WebSocket server protocol.

Implements:

* :class:`autobahn.wamp.interfaces.ITransport`
ry   Nr   ry   r8   r7   r/   r/   8  ó   † ôr8   r/   c                   ó"   • \ rS rSrSr\rS rSrg)r0   iC  z<
Twisted-based WAMP-over-WebSocket server protocol factory.
c                 óº   • UR                  SS5      n[        R                  R                  XU5        U R                  US'   [
        R                  " U /UQ70 UD6  g)a^  

:param factory: A callable that produces instances that implement
    :class:`autobahn.wamp.interfaces.ITransportHandler`
:type factory: callable

:param serializers: A list of WAMP serializers to use (or ``None``
    for all available serializers).
:type serializers: list of objects implementing
    :class:`autobahn.wamp.interfaces.ISerializer`
ÚserializersNrD   )r  r   r0   rd   Ú
_protocolsr&   ©rc   rY   r  r  rt  s        r7   rd   Ú#WampWebSocketServerFactory.__init__K  sR   € ð —j‘j °Ó5ˆä×,Ñ,×5Ñ5°dÀ[ÔQà"Ÿo™oˆˆ{Ñô 	×'Ò'¨Ð>¨tÒ>°vÓ>r8   ry   N)	r   r€   r�   r‚   rƒ   r/   r   rd   r„   ry   r8   r7   r0   r0   C  s   † ñð +€Hõ?r8   r0   c                   ó   • \ rS rSrSrSrg)r1   ib  zq
Twisted-based WAMP-over-WebSocket client protocol.

Implements:

* :class:`autobahn.wamp.interfaces.ITransport`
ry   Nr   ry   r8   r7   r1   r1   b  rq  r8   r1   c                   ó"   • \ rS rSrSr\rS rSrg)r2   im  z<
Twisted-based WAMP-over-WebSocket client protocol factory.
c                 óÈ   • UR                  SS5      n[        R                  R                  XU5        U R                  US'   [
        R                  " U /UQ70 UD6  SU l        g)aœ  

:param factory: A callable that produces instances that implement
    :class:`autobahn.wamp.interfaces.ITransportHandler`
:type factory: callable

:param serializer: The WAMP serializer to use (or ``None`` for
   "best" serializer, chosen as the first serializer available from
   this list: CBOR, MessagePack, UBJSON, JSON).
:type serializer: object implementing :class:`autobahn.wamp.interfaces.ISerializer`
rt  NrD   F)r  r   r2   rd   ru  r'   Únoisyrv  s        r7   rd   Ú#WampWebSocketClientFactory.__init__u  sY   € ð —j‘j °Ó5ˆä×,Ñ,×5Ñ5°dÀ[ÔQà"Ÿo™oˆˆ{Ñä×'Ò'¨Ð>¨tÒ>°vÒ>ð ˆ�
r8   )r{  N)	r   r€   r�   r‚   rƒ   r1   r   rd   r„   ry   r8   r7   r2   r2   m  s   † ñð +€Hõr8   r2   )Né   N)Né2   Ú )Nr  r   r   Útypingr   Úzope.interfacer   rï   Úuse_twistedÚtwisted.internet.protocolÚtwistedrT   r   Útwisted.internet.interfacesr   Útwisted.internet.errorr	   r
   r   Útwisted.internet.deferr   Útwisted.python.failurer   r   Úautobahn.utilr   r   r   r   r   Úautobahn.wampr   Úautobahn.wamp.typesr   Úautobahn.websocket.typesr   r   r   Úautobahn.websocketr   Úautobahn.websocket.interfacesr   Úautobahn.twisted.utilr   r   Úautobahn.websocket.compressr   r   r   r    Ú__all__r!   rA   rM   r\   r4   ÚinternetÚProtocolr"   r#   r$   Úobjectr%   r&   ÚServerFactoryr'   ÚClientFactoryr(   r)   r*   r+   r,   r.   r-   r/   r0   r1   r2   ry   r8   r7   Ú<module>r—     s•  ð÷6 (Ý å &ã Ø × Ò Ô ã  Ý &Ý 2÷ñ å +Ý *Ý 4ç /Ñ /ß :Ý #Ý 0ß ZÑ ZÝ 'Ý ?ß P÷$ó $ð€ò41òò(ò2&ôR4Ð#8ô 4ôns,˜w×/Ñ/×8Ñ8×AÑAô s,ðl ôÐ6¸×8XÑ8Xó ó ðð ô=Ð6¸×8XÑ8Xó =ó ð=ô&˜fô ð ôHÐ4°h×6UÑ6UÐW^×WgÑWg×WpÑWp×W~ÑW~ó Hó ðHð6 ô EÐ4°h×6UÑ6UÐW^×WgÑWg×WpÑWp×W~ÑW~ó  Eó ð EñR ˆZÓôP(˜vó P(ó ðP(ôfÐ&>Ð@Wô ôÐ&>Ð@Wô ô<1Ð%;ô <1ô~7Ð%;ô 7ðt ó(ó ð(ðV ó ó ð ðF ô )×"GÑ"GÐI`ó ó ðð ô? ×!EÑ!EÐG]ó ?ó ð?ð< ô )×"GÑ"GÐI`ó ó ðð ô ×!EÑ!EÐG]ó ó ñr8   