%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib64/python2.7/site-packages/tornado/
Upload File :
Create Path :
Current File : //lib64/python2.7/site-packages/tornado/websocket.pyc

�
��L]c@�s�dZddlmZmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlZddl
ZddlZddlmZddlmZmZmZddlmZmZddlmZddlmZdd	lmZmZdd
lmZddlmZddl m!Z!ydd
l"m#Z#Wn!e$k
rgdd
l#m#Z#nXye%Wne&k
r�e'Z%nXde(fd��YZ)de)fd��YZ*dej+j,fd��YZ-d�Z.xBdddddddgD]%Z/e0e-e/e.e1e-e/���q�Wde2fd��YZ3de2fd��YZ4d e2fd!��YZ5d"e3fd#��YZ6d$ej7fd%��YZ8e9e9e9e9e9d&�Z:dS('s�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.
i(tabsolute_importtdivisiontprint_functiontwith_statementN(tTracebackFuture(tutf8t
native_strt
to_unicode(t
httpclientthttputil(tIOLoop(tStreamClosedError(tgen_logtapp_log(tsimple_httpclient(t	TCPClient(t_websocket_mask(turlparsetWebSocketErrorcB�seZRS((t__name__t
__module__(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR5stWebSocketClosedErrorcB�seZdZRS(sLRaised by operations on a closed connection.

    .. versionadded:: 3.2
    (RRt__doc__(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR9stWebSocketHandlercB�s�eZdZd�Zejjd��Zed�Z	d�Z
d�Zd�Zd�Z
d�Zd	�Zd
�Zddd�Zd�Zd
�Zd�Zd�Zd�ZRS(sk
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.

    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.
    cK�sMtjjj||||�d|_d|_d|_d|_t	|_
dS(N(ttornadotwebtRequestHandlert__init__tNonet
ws_connectiont
close_codetclose_reasontstreamtFalset_on_close_called(tselftapplicationtrequesttkwargs((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s				cO�s�||_||_|jjjdd�j�dkrg|jd�d}|j|�tj	|�dS|jj}t
d�|jdd�jd��}d	|kr�|jd�d
}|j|�tj	|�dSd|jjkr|jjjd�}n|jjjdd�}|dk	rf|j
|�rf|jd
�d}|j|�tj	|�dS|jjj�|_|jj|j�|j�|_|jr�|jj�n;|jj�s�|jjtjjd��|jj�ndS(NtUpgradett	websocketi�s"Can "Upgrade" only to "WebSocket".cS�s|j�j�S(N(tstriptlower(ts((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt<lambda>�st
Connectiont,tupgrades"Connection" must be "Upgrade".tOriginsSec-Websocket-Origini�s#Cross origin websockets not allowedsBHTTP/1.1 426 Upgrade Required
Sec-WebSocket-Version: 7, 8, 13

(t	open_argstopen_kwargsR%theaderstgetR+t
set_statustfinishRtdebugtmaptsplitRtcheck_origint
connectiontdetachR tset_close_callbackton_connection_closetget_websocket_protocolRtaccept_connectiontclosedtwriteRtescapeRtclose(R#targsR&tlog_msgR4R<torigin((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR5�sF		$


	





	
cC�sY|jdkrt��nt|t�r?tjj|�}n|jj|d|�dS(s
Sends the given message to the client of this Web Socket.

        The message may be either a string or a dict (which will be
        encoded as json).  If the ``binary`` argument is false, the
        message will be sent as utf8; in binary mode any byte string
        is allowed.

        If the connection is already closed, raises `WebSocketClosedError`.

        .. versionchanged:: 3.2
           `WebSocketClosedError` was added (previously a closed connection
           would raise an `AttributeError`)
        tbinaryN(	RRRt
isinstancetdictRRDtjson_encodet
write_message(R#tmessageRI((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRM�s
cC�sdS(s�Invoked when a new WebSocket requests specific subprotocols.

        ``subprotocols`` is a list of strings identifying the
        subprotocols proposed by the client.  This method may be
        overridden to return one of those strings to select it, or
        ``None`` to not select a subprotocol.  Failure to select a
        subprotocol does not automatically abort the connection,
        although clients may close the connection if none of their
        proposed subprotocols was selected.
        N(R(R#tsubprotocols((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pytselect_subprotocol�scC�sdS(s�Override to return compression options for the connection.

        If this method returns None (the default), compression will
        be disabled.  If it returns a dict (even an empty one), it
        will be enabled.  The contents of the dict may be used to
        control the memory and CPU usage of the compression,
        but no such options are currently implemented.

        .. versionadded:: 4.1
        N(R(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pytget_compression_options�scO�sdS(s�Invoked when a new WebSocket is opened.

        The arguments to `open` are extracted from the `tornado.web.URLSpec`
        regular expression, just like the arguments to
        `tornado.web.RequestHandler.get`.
        N((R#RFR&((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pytopen�scC�s
t�dS(s[Handle incoming messages on the WebSocket

        This method must be overridden.
        N(tNotImplementedError(R#RN((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt
on_message�scC�s/|jdkrt��n|jj|�dS(s"Send ping frame to the remote end.N(RRRt
write_ping(R#tdata((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pytpingscC�sdS(s6Invoked when the response to a ping frame is received.N((R#RV((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyton_pong
scC�sdS(s`Invoked when the WebSocket is closed.

        If the connection was closed cleanly and a status code or reason
        phrase was supplied, these values will be available as the attributes
        ``self.close_code`` and ``self.close_reason``.

        .. versionchanged:: 4.0

           Added ``close_code`` and ``close_reason`` attributes.
        N((R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyton_closescC�s,|jr(|jj||�d|_ndS(sCCloses this Web Socket.

        Once the close handshake is successful the socket will be closed.

        ``code`` may be a numeric status code, taken from the values
        defined in `RFC 6455 section 7.4.1
        <https://tools.ietf.org/html/rfc6455#section-7.4.1>`_.
        ``reason`` may be a textual message about why the connection is
        closing.  These values are made available to the client, but are
        not otherwise interpreted by the websocket protocol.

        .. versionchanged:: 4.0

           Added the ``code`` and ``reason`` arguments.
        N(RRER(R#tcodetreason((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyREs	cC�s@t|�}|j}|j�}|jjjd�}||kS(sgOverride to enable support for allowing alternate origins.

        The ``origin`` argument is the value of the ``Origin`` HTTP
        header, the url responsible for initiating this request.  This
        method is not called for clients that do not send this header;
        such requests are always allowed (because all browsers that
        implement WebSockets support this header, and non-browser
        clients do not have the same cross-site security concerns).

        Should return True to accept the request or False to reject it.
        By default, rejects all requests with an origin on a host other
        than this one.

        This is a security protection against cross site scripting attacks on
        browsers, since WebSockets are allowed to bypass the usual same-origin
        policies and don't use CORS headers.

        To accept all cross-origin traffic (which was the default prior to
        Tornado 4.0), simply override this method to always return true::

            def check_origin(self, origin):
                return True

        To allow connections from any subdomain of your site, you might
        do something like::

            def check_origin(self, origin):
                parsed_origin = urllib.parse.urlparse(origin)
                return parsed_origin.netloc.endswith(".mydomain.com")

        .. versionadded:: 4.0
        tHost(RtnetlocR+R%R4R5(R#RHt
parsed_originthost((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR;/s
!	cC�s|jj|�dS(s1Set the no-delay flag for this stream.

        By default, small messages may be delayed and/or combined to minimize
        the number of packets sent.  This can sometimes cause 200-500ms delays
        due to the interaction between Nagle's algorithm and TCP delayed
        ACKs.  To reduce this delay (at the expense of possibly increasing
        bandwidth usage), call ``self.set_nodelay(True)`` once the websocket
        connection is established.

        See `.BaseIOStream.set_nodelay` for additional details.

        .. versionadded:: 3.1
        N(R tset_nodelay(R#tvalue((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR`YscC�sE|jr"|jj�d|_n|jsAt|_|j�ndS(N(RR?RR"tTrueRY(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR?is	
		cO�s<|jdkr+tt|�j||�n
|jj�dS(N(R RtsuperRt
send_errorRE(R#RFR&((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRdqscC�s;|jjjd�}|dkr7t|d|j��SdS(NsSec-WebSocket-Versiont7t8t13tcompression_options(ReRfRg(R%R4R5tWebSocketProtocol13RQ(R#twebsocket_version((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR@{sN(RRRRRRtasynchronousR5R!RMRPRQRRRTRWRXRYRRER;R`R?RdR@(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRAs"A		:	
	
						
	*			
c�s�fd�}|S(Nc�s2|jdkr"�|||�ntd��dS(Ns$Method not supported for Web Sockets(R RtRuntimeError(R#RFR&(tmethod(s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt_disallow_for_websocket�s((RmRn((Rms7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt_wrap_method�sRCtredirectt
set_headert
set_cookieR6tflushR7tWebSocketProtocolcB�s2eZdZd�Zd�Zd�Zd�ZRS(s0Base class for WebSocket protocol versions.
    cC�s7||_|j|_|j|_t|_t|_dS(N(thandlerR%R R!tclient_terminatedtserver_terminated(R#Ru((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s
		cO�sOy|||�Wn7tk
rJtjd|jjdt�|j�nXdS(sRuns the given callback with exception handling.

        On error, aborts the websocket connection and returns False.
        sUncaught exception in %stexc_infoN(t	ExceptionR
terrorR%tpathRbt_abort(R#tcallbackRFR&((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt
_run_callback�s
	cC�s|j�dS(N(R|(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR?�scC�s-t|_t|_|jj�|j�dS(s?Instantly aborts the WebSocket connection by closing the socketN(RbRvRwR RE(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR|�s		
(RRRRR~R?R|(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRt�s
			t_PerMessageDeflateCompressorcB�s#eZd�Zd�Zd�ZRS(cC�s}|dkrtj}nd|ko2tjknsOtd|tj��n||_|rp|j�|_n	d|_dS(Nis.Invalid max_wbits value %r; allowed range 8-%d(Rtzlibt	MAX_WBITSt
ValueErrort
_max_wbitst_create_compressort_compressor(R#t
persistentt	max_wbits((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s	cC�stjdtj|j�S(Ni����(R�tcompressobjtDEFLATEDR�(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��scC�sQ|jp|j�}|j|�|jtj�}|jd�sIt�|d S(Nt��i����(R�R�tcompressRsR�tZ_SYNC_FLUSHtendswithtAssertionError(R#RVt
compressor((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��s
(RRRR�R�(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s	
	t_PerMessageDeflateDecompressorcB�s#eZd�Zd�Zd�ZRS(cC�s}|dkrtj}nd|ko2tjknsOtd|tj��n||_|rp|j�|_n	d|_dS(Nis.Invalid max_wbits value %r; allowed range 8-%d(RR�R�R�R�t_create_decompressort
_decompressor(R#R�R�((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s	cC�stj|j�S(N(R�t
decompressobjR�(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��scC�s&|jp|j�}|j|d�S(NR�(R�R�t
decompress(R#RVtdecompressor((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��s(RRRR�R�(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��s		RicB�seZdZdZdZdZdZeeBeBZdZe	dd�Zd�Zd�Z
ed	��Zd
�Zd�Zd�Zd
�Zd�Zd�Zdd�Ze	d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z ddd�Z!RS(s�Implementation of the WebSocket protocol from RFC 6455.

    This class supports versions 7 and 8 of the protocol in addition to the
    final version 13.
    i�i@i iicC�s�tj||�||_t|_d|_d|_d|_d|_	d|_
d|_d|_||_
d|_d|_d|_d|_d|_d|_d|_dS(Ni(RtRt
mask_outgoingR!t_final_frameRt
_frame_opcodet
_masked_framet_frame_maskt
_frame_lengtht_fragmented_message_buffert_fragmented_message_opcodet_waitingt_compression_optionsR�R�t_frame_compressedt_message_bytes_int_message_bytes_outt_wire_bytes_int_wire_bytes_out(R#RuR�Rh((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s$																cC�sNy|j�|j�Wn/tk
rItjddt�|j�dSXdS(Ns$Malformed WebSocket request receivedRx(t_handle_websocket_headerst_accept_connectionR�RR8RbR|(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRAs


c�s7d}tt�fd�|��s3td��ndS(s�Verifies all invariant- and required headers

        If a header is missing or have an incorrect value ValueError will be
        raised
        R\sSec-Websocket-KeysSec-Websocket-Versionc�s�jjj|�S(N(R%R4R5(tf(R#(s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR-ss!Missing/Invalid WebSocket headersN(sHostsSec-Websocket-KeysSec-Websocket-Version(tallR9R�(R#tfields((R#s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�scC�sEtj�}|jt|��|jd�ttj|j���S(soComputes the value for the Sec-WebSocket-Accept header,
        given the value for Sec-WebSocket-Key.
        s$258EAFA5-E914-47DA-95CA-C5AB0DC85B11(thashlibtsha1tupdateRRtbase64t	b64encodetdigest(tkeyR�((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pytcompute_accept_values
cC�stj|jjjd��S(NsSec-Websocket-Key(RiR�R%R4R5(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt_challenge_response$scC�s�d}|jjjdd�}g|jd�D]}|j�^q.}|r�|jj|�}|r�||ksvt�d|}q�nd}|j|jj�}x�|D]�}|ddkr�|j	dk	r�|jd|d�d	|dkr|dd	dkr|dd	=nd
tj
d|d�}Pq�q�W|jj�rR|j�dS|jjtjjd|j�||f��|j|jj|jj|jj�|j�dS(NR(sSec-WebSocket-ProtocolR/sSec-WebSocket-Protocol: %s
ispermessage-deflatetserveritclient_max_window_bitssSec-WebSocket-Extensions: %s
skHTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: %s
%s%s
(R%R4R5R:R*RuRPR�t_parse_extensions_headerR�Rt_create_compressorsR	t_encode_headerR RBR|RCRRDRR�R~RRR2R3t_receive_frame(R#tsubprotocol_headerROR,tselectedtextension_headert
extensionstext((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�(s@(


	
cC�sK|jdd�}|rGg|jd�D]}tj|j��^q(SgS(NsSec-WebSocket-ExtensionsR(R/(R5R:R	t
_parse_headerR*(R#R4R�te((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�Us
,cC�s�|dj�dkst�|dj�dks8t�|j|�}|d|ks]t�|j|�}xS|D]K}|ddkr�|jdk	r�|jd|d	�qstd
|��qsWdS(s�Process the headers sent by the server to this client connection.

        'key' is the websocket handshake challenge/response key.
        R'R)R.R0sSec-Websocket-Acceptispermessage-deflatetclientisunsupported extension %rN(R+R�R�R�R�RR�R�(R#R�R4tacceptR�R�((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt_process_server_headers\s
cC�s_td|d|k�}|j|dd�}|dkrKtj|d<nt|�|d<|S(slConverts a websocket agreed_parameters set to keyword arguments
        for our compressor objects.
        R�t_no_context_takeovert_max_window_bitsR�N(RKR5RR�R�tint(R#tsidetagreed_parameterstoptionstwbits_header((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt_get_compressor_optionsnscC�s�tddddg�}x-|D]%}||krtd|��qqW|dkrZdnd}t|j||��|_t|j||��|_dS(Ntserver_no_context_takeovertclient_no_context_takeovertserver_max_window_bitsR�s$unsupported compression parameter %rR�R�(tsetR�RR�R�R�R�(R#R�R�tallowed_keysR�t
other_side((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�{s
ic
C�sK|r|j}nd}tjd||B|B�}t|�}|jrPd}nd}|dkr|tjd||B�7}nI|dkr�|tjdd|B|�7}n|tjdd|B|�7}|jr�tjd	�}	|	t|	|�}n||7}|jt|�7_y|j	j
|�Wntk
rF|j�nXdS(
NitBi�i~i��s!BHs!BQii(
tFINtstructtpacktlenR�tosturandomRR�R RCRR|(
R#tfintopcodeRVtflagstfinbittframetltmask_bittmask((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt_write_frame�s,		 	

cC�s�|rd}nd}tjj|�}t|t�s<t�|jt|�7_d}|jr�|jj	|�}||j
O}n|jt||d|�dS(s9Sends the given message to the client of this Web Socket.iiiR�N(
RRDRRJtbytesR�R�R�R�R�tRSV1R�Rb(R#RNRIR�R�((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRM�s		cC�s,t|t�st�|jtd|�dS(sSend ping frame.i	N(RJR�R�R�Rb(R#RV((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRU�scC�s<y|jjd|j�Wntk
r7|j�nXdS(Ni(R t
read_bytest_on_frame_startRR|(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��s
cC�s�|jt|�7_tjd|�\}}||j@|_||j@}||j@|_|jd@|_	|j
dk	r�t||j
@�|_||j
M}n|r�|j�dSt|d@�|_|d@}|j	r�|dkr�|j�dSy�|dkrJ||_|jr.|jjd|j�q�|jj|j|j�nJ|dkro|jjd|j�n%|dkr�|jjd|j�nWntk
r�|j�nXdS(NtBBii�ii~ii(R�R�R�tunpackR�R�tRSV_MASKtOPCODE_MASKR�t_frame_opcode_is_controlR�RtboolR�R�R|R�R�R R�t_on_masking_keyt_on_frame_datat_on_frame_length_16t_on_frame_length_64R(R#RVtheadert
payloadlent
reserved_bits((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��s<



		

cC�s�|jt|�7_tjd|�d|_y?|jrS|jjd|j�n|jj|j|j	�Wnt
k
r�|j�nXdS(Ns!Hii(R�R�R�R�R�R�R R�R�R�RR|(R#RV((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��s	
cC�s�|jt|�7_tjd|�d|_y?|jrS|jjd|j�n|jj|j|j	�Wnt
k
r�|j�nXdS(Ns!Qii(R�R�R�R�R�R�R R�R�R�RR|(R#RV((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��s	
cC�s]|jt|�7_||_y|jj|j|j�Wntk
rX|j�nXdS(N(	R�R�R�R R�R�t_on_masked_frame_dataRR|(R#RV((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR��s	
cC�s|jt|j|��dS(N(R�RR�(R#RV((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�scC�s#|jt|�7_|jrA|js5|j�dS|j}n�|jdkr�|jdkrm|j�dS|j|7_|jr�|j}|j}d|_q�nG|jdk	r�|j�dS|jr�|j}n|j|_||_|jr	|j	||�n|j
s|j�ndS(Ni(R�R�R�R�R|R�R�RR�t_handle_messageRvR�(R#RVR�((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s4		

			
				cC�s�|jr
dS|jr+|jj|�}n|dkr�|jt|�7_y|jd�}Wntk
r}|j�dSX|j	|j
j|�n|dkr�|jt|�7_|j	|j
j|�n�|dkr\t|_t|�dkrt
jd|d �d|j
_nt|�dkrFt|d�|j
_n|j|j
j�nQ|dkr~|jtd|�n/|dkr�|j	|j
j|�n
|j�dS(	Nisutf-8iis>Hii	i
(RvR�R�R�R�R�tdecodetUnicodeDecodeErrorR|R~RuRTRbR�R�RRRRER�RX(R#R�RVtdecoded((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�+s6		

	#cC�s/|js�|jj�s�|dkr9|dk	r9d}n|dkrNd}ntjd|�}|dk	r|t|�7}n|jtd|�nt|_n|j	r�|j
dk	r�|jjj|j
�d|_
n|jj
�n@|j
dkr+|jjj|jjj�d|j�|_
ndS(s Closes the WebSocket connection.i�R(s>HiiN(RwR RBRR�R�RR�RbRvR�tio_looptremove_timeoutREtadd_timeoutttimeR|(R#RZR[t
close_data((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyREQs&				N("RRRR�R�tRSV2tRSV3R�R�R!RRRAR�tstaticmethodR�R�R�R�R�R�R�R�RMRUR�R�R�R�R�R�R�R�RE(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRi�s<	
	

		-			
				#						&	&tWebSocketClientConnectioncB�szeZdZddd�Zddd�Zd�Zd�Zd�Ze	d�Z
dd�Zd�Zd	�Z
d
�ZRS(s�WebSocket client connection.

    This class should not be instantiated directly; use the
    `websocket_connect` function instead.
    c
C�sI||_t�|_d|_d|_tj�|_t	j
tjd��|_
||_d|_|_|jjd�\}}}idd6dd6|}||||_|jjidd6dd	6|j
d
6dd6�|jdk	r�d
|jd<ntd|�|_tt|�j|d|d�|jd|jdd�	dS(Nit:thttptwsthttpstwssR)R'R.sSec-WebSocket-KeyRgsSec-WebSocket-Versions*permessage-deflate; client_max_window_bitssSec-WebSocket-ExtensionsR�cS�sdS(N(R(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR-�si@i(RhRtconnect_futureRtprotocoltread_futuretcollectionstdequet
read_queueR�R�R�R�R�t_on_message_callbackRRturlt	partitionR4R�Rt
tcp_clientRcR�Rt_on_http_response(R#R�R%ton_message_callbackRhtschemetseptrest((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRqs,				
cC�s2|jdk	r.|jj||�d|_ndS(s�Closes the websocket connection.

        ``code`` and ``reason`` are documented under
        `WebSocketHandler.close`.

        .. versionadded:: 3.2

        .. versionchanged:: 4.0

           Added the ``code`` and ``reason`` arguments.
        N(RRRE(R#RZR[((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRE�scC�sV|jj�s%|jjt��n|jd�|jj�tt	|�j
�dS(N(Rtdonet
set_exceptionRRTRRRERcR�R?(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR?�s


cC�sK|jj�sG|jr.|jj|j�qG|jjtd��ndS(NsNon-websocket response(RRRzRR(R#tresponse((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s
	cC�s�|jdkr(tt|�j||�S||_|j�|_|jj|j|j�|jj	�|j
dk	r�|jj
|j
�d|_
n|jj�|_|jj|j�d|_|jj|�dS(Nie(RZRcR�theaders_receivedR4R@RR�R�R�t_timeoutRR�R�R<R=R R>R?tfinal_callbackRt
set_result(R#t
start_lineR4((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�s
	
	cC�s|jj||�dS(s(Sends a message to the WebSocket server.N(RRM(R#RNRI((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRM�scC�so|jdkst�t�}|jr@|j|jj��n	||_|dk	rk|jj||�n|S(sxReads a message from the WebSocket server.

        If on_message_callback was specified at WebSocket
        initialization, this function will never return messages

        Returns a future whose result is the message, or None
        if the connection is closed.  If a callback argument
        is given it will be called with the future when it is
        ready.
        N(	RRR�RR
RtpopleftR�t
add_future(R#R}tfuture((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pytread_message�s			cC�sX|jr|j|�n;|jdk	rD|jj|�d|_n|jj|�dS(N(RRRRR
tappend(R#RN((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRT�s	cC�sdS(N((R#RV((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyRX�scC�st|dtd|j�S(NR�Rh(RiRbRh(R#((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR@�sN(RRRRRRER?RRR!RMRRTRXR@(((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyR�ks!						cC�s�|dkrtj�}nt|tj�r]|dks?t�|}tj|j	�|_	ntj|d|�}tj
|tjj�}t||d|d|�}|dk	r�|j
|j|�n|jS(sClient-side websocket support.

    Takes a url and returns a Future whose result is a
    `WebSocketClientConnection`.

    ``compression_options`` is interpreted in the same way as the
    return value of `.WebSocketHandler.get_compression_options`.

    The connection supports two styles of operation. In the coroutine
    style, the application typically calls
    `~.WebSocketClientConnection.read_message` in a loop::

        conn = yield websocket_connection(loop)
        while True:
            msg = yield conn.read_message()
            if msg is None: break
            # Do something with msg

    In the callback style, pass an ``on_message_callback`` to
    ``websocket_connect``. In both styles, a message of ``None``
    indicates that the connection has been closed.

    .. versionchanged:: 3.2
       Also accepts ``HTTPRequest`` objects in place of urls.

    .. versionchanged:: 4.1
       Added ``compression_options`` and ``on_message_callback``.
       The ``io_loop`` argument is deprecated.
    tconnect_timeoutRRhN(RR
tcurrentRJRtHTTPRequestR�R	tHTTPHeadersR4t
_RequestProxyt	_DEFAULTSR�RR(RR�R}R!RRhR%tconn((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pytwebsocket_connect�s	(;Rt
__future__RRRRR�RR�R�R�ttornado.escapeRttornado.webR�ttornado.concurrentRRRRRR	ttornado.ioloopR
ttornado.iostreamRttornado.logRR
Rttornado.tcpclientRttornado.utilRturllib.parseRtImportErrortxranget	NameErrortrangeRyRRRRRRoRmtsetattrtgetattrtobjectRtRR�Rit_HTTPConnectionR�RR((((s7/usr/lib64/python2.7/site-packages/tornado/websocket.pyt<module>sV"


�B		!���	

Zerion Mini Shell 1.0