
                         J   d Z ddlZddlZddlZddlZddlZddl ddl ddl ej                  ej                  dfgZ eed      r(ej                  ej                  ej                  df        eed      r(ej                  ej                  ej                   df        eed      r(ej                  ej                  ej"                  d	f        eed
      r(ej                  ej                  ej$                  df       dag dZ G d de      Zd Zd Zd Zd Zd Zy)aK  
websocket - WebSocket client library for Python

Copyright (C) 2010 Hiroki Ohtani(liris)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1335  USA

    N   )*SO_KEEPALIVETCP_KEEPIDLE   TCP_KEEPINTVL
   TCP_KEEPCNT   )DEFAULT_SOCKET_OPTIONsock_optsetdefaulttimeoutgetdefaulttimeoutrecv	recv_linesendc                       e Zd Zd Zy)r   c                 >    |g }|i }|| _         || _        d | _        y )N)sockoptsslopttimeout)selfr   r   s      $lib/third_party/websocket/_socket.py__init__zsock_opt.__init__3   s+    ?G>F    N)__name__
__module____qualname__r    r   r   r   r   1   s    r   r   c                     | a y)zu
    Set the global timeout setting to connect.

    timeout: default socket timeout time. This value is second.
    N_default_timeout)r   s    r   r   r   =   s
     r   c                      t         S )z?
    Return the global timeout setting(second) to connect.
    r!   r   r   r   r   r   G   s
     r   c                 t     st        d       fd}	  j                         dk(  r j                        }n |       }|st        d      |S # t        j                  $ r}t        |      }t        |      d }~wt        $ r0}t        |      }t        |t              rd|v rt        |       d }~ww xY w)Nsocket is already closed.c                     	 j                        S # t        $ r!} | j                  d   t        k7  r Y d } ~ nXd } ~ wt        j
                  $ r?}t        |      }| |t        j                  k7  s|t        j                  k7  r Y d }~nd }~ww xY wt        j                  fddj                               \  }}} |rj                        S y Nr   r   )r   SSLErrorargsSSL_ERROR_WANT_READsocketerrorextract_error_codeerrnoEAGAINEWOULDBLOCKselect
gettimeout)eexc
error_coderwbufsizesocks        r   _recvzrecv.<locals>._recvR   s    	99W%% 	vvay// 0|| 	+C0J!U\\)Z5;L;L-L .M		 --"b$//2CD1a99W%%     	B9B5B		Br   	timed outzConnection is already closed.)
"WebSocketConnectionClosedExceptionr2   r   r+   r   extract_err_messageWebSocketTimeoutExceptionr(   
isinstancestr)r9   r8   r:   bytes_r3   messages   ``    r   r   r   N   s    01LMM&$??!YYw'FWF 0+- 	- M >> 1%a('00 %a(gs#w(>+G44s#   ,A B7%A;;B7+B22B7c                     g }	 t        | d      }|j                  |       |t        j                  d      k(  rn7t        j                  d      j	                  |      S )Nr   
 )r   appendsixbjoin)r9   linecs      r   r   r   z   sQ    D
qMAd	 
 559>>$r   c                     t        t        j                        rj                  d       st	        d       fd}	  j                         dk(  r j                        S  |       S # t        j                  $ r}t        |      }t        |      d }~wt        $ r0}t        |      }t        |t              rd|v rt        |       d }~ww xY w)Nzutf-8r%   c                     	 j                        S # t        $ r!} | j                  d   t        k7  r Y d } ~ nXd } ~ wt        j
                  $ r?}t        |      }| |t        j                  k7  s|t        j                  k7  r Y d }~nd }~ww xY wt        j                  dfdj                               \  }}} |rj                        S y r'   )r   r(   r)   SSL_ERROR_WANT_WRITEr+   r,   r-   r.   r/   r0   r1   r2   )r3   r4   r5   r6   r7   datar9   s        r   _sendzsend.<locals>._send   s    	99T?" 	vvay00 1|| 	+C0J!U\\)Z5;L;L-L .M		 --THb$//2CD1a99T?" r;   r   r<   )r@   rH   	text_typeencoder=   r2   r   r+   r   r>   r?   	ExceptionrA   )r9   rP   rQ   r3   rC   s   ``   r   r   r      s    $&{{7#01LMM#$??!99T?"7N>> 1%a('00 %a(gs#w(>+G44s*   #A- &A- -C BC"+CC)__doc__r.   r1   r+   rH   sys_exceptions_ssl_compat_utilsSOL_TCPTCP_NODELAYr   hasattrrG   
SOL_SOCKETr   r   r   r
   r"   __all__objectr   r   r   r   r   r   r   r   r   <module>r`      s  *    
 
    ..&*<*<a@A 
6>"  &"3"3V5H5H!!LM
6>"  &..&2E2Er!JK
6?#  &..&2F2F!KL
6=!  &..&2D2Da!HI (	v 	)X &r   