a
   1D                   @   s  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T ddlT ddlT ej	ej
dfgZeedrreejejdf eedreej	ejdf eedreej	ejd	f eed
reej	ejdf dag dZG dd deZdd Zdd Zdd Zdd Zdd ZdS )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                   @   s   e Zd Zdd ZdS )r   c                 C   s.   |d u rg }|d u ri }|| _ || _d | _d S )N)sockoptsslopttimeout)selfr   r    r   5/usr/lib/python3.9/site-packages/websocket/_socket.py__init__3   s    zsock_opt.__init__N)__name__
__module____qualname__r   r   r   r   r   r   1   s   r   c                 C   s   | a dS )zu
    Set the global timeout setting to connect.

    timeout: default socket timeout time. This value is second.
    N_default_timeout)r   r   r   r   r   =   s    r   c                   C   s   t S )z?
    Return the global timeout setting(second) to connect.
    r   r   r   r   r   r   G   s    r   c              
      s   st d fdd}z" dkr4 }n| }W n~ tjyr } zt|}t|W Y d }~nRd }~0  ty } z2t|}t|t	rd|v rt|n W Y d }~n
d }~0 0 |st d|S )Nsocket is already closed.c               
      s   z  W S  ty   Y nN tjyj }  z4t| }|d u r@ |tjksT|tjkrV W Y d } ~ n
d } ~ 0 0 tfdd	 \}}}|r  S d S Nr   )
r   ZSSLWantReadErrorsocketerrorextract_error_codeerrnoEAGAINEWOULDBLOCKselect
gettimeoutexcZ
error_coderwebufsizesockr   r   _recvR   s    zrecv.<locals>._recvr   	timed outzConnection is already closed.)
"WebSocketConnectionClosedExceptionr'   r   r    r   extract_err_messageWebSocketTimeoutExceptionZSSLError
isinstancestr)r/   r.   r0   Zbytes_r,   messager   r-   r   r   N   s(    

r   c                 C   s:   g }t | d}|| |tdkrq*qtd|S )Nr   
 )r   appendsixbjoin)r/   linecr   r   r   r   x   s    

r   c              
      s   t  tjr d s"td fdd}z$ dkrJ W S | W S W n~ tjy } zt	|}t
|W Y d }~nRd }~0  ty } z2t	|}t |trd|v rt
|n W Y d }~n
d }~0 0 d S )Nzutf-8r   c               
      s   z  W S  ty   Y nN tjyj }  z4t| }|d u r@ |tjksT|tjkrV W Y d } ~ n
d } ~ 0 0 tdfd	 \}}}|r  S d S r   )
r   ZSSLWantWriteErrorr    r!   r"   r#   r$   r%   r&   r'   r(   datar/   r   r   _send   s    zsend.<locals>._sendr   r1   )r5   r;   Z	text_typeencoder2   r'   r   r    r   r3   r4   	Exceptionr6   )r/   rA   rB   r,   r7   r   r@   r   r      s"    

r   )__doc__r#   r&   r    r;   sys_exceptionsZ_ssl_compatZ_utilsZSOL_TCPZTCP_NODELAYr   hasattrr:   Z
SOL_SOCKETr   r   r   r	   r   __all__objectr   r   r   r   r   r   r   r   r   r   <module>   s2   




*
