
    i                         S SK r S SKrS SK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    " S S\R                  5      r\S:X  a  \R                   " 5         gg)	    N)Mockpatch)recv)SSLWantReadError)WebSocketTimeoutException"WebSocketConnectionClosedExceptionc                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
SocketBugsTest!   z(Test bugs found in socket handling logicc                    [        5       n[        5       UR                  l        SUR                  l        [        S5       n[        5       nX2l        / UR                  l        U R                  [        5       n[        US5        SSS5        U R                  S[        WR                  5      5        SSS5        g! , (       d  f       N<= f! , (       d  f       g= f)z
BUG #5 FIX VERIFICATION: Test SSLWantReadError timeout now raises correct exception

Bug was in _socket.py:100-101 - SSLWantReadError except block returned None implicitly
Fixed: Now properly handles timeout with WebSocketTimeoutException
      ?selectors.DefaultSelectord   N%Connection timed out waiting for datar   r   r   side_effect
gettimeoutreturn_valuer   selectassertRaisesr   assertInstr	exceptionself	mock_sockmock_selector_classmock_selectorcms        MC:\des-py\RoboSAPF\venv\Lib\site-packages\websocket/tests/test_socket_bugs.py6test_bug_implicit_none_return_from_ssl_want_read_fixedESocketBugsTest.test_bug_implicit_none_return_from_ssl_want_read_fixed$        F	%5%7	",/	)./3F FM/<,02M  -""#<=Y$ > MMA3r||CTU 0/
 >= 0/$    7C7B:-C:
C	C
Cc                    [        5       n[        [        R                  S5      nX!R                  l        SUR                  l        [        S5       n[        5       nXCl        / UR                  l        U R                  [        5       n[	        US5        SSS5        U R                  S[        WR                  5      5        SSS5        g! , (       d  f       N<= f! , (       d  f       g= f)z
BUG #5 FIX VERIFICATION: Test that socket.error with EAGAIN now handles timeout correctly

Bug was in _socket.py:102-105 - socket.error except block returned None implicitly
Fixed: Now properly handles timeout with WebSocketTimeoutException
z Resource temporarily unavailabler   r   r   Nr   )r   OSErrorerrnoEAGAINr   r   r   r   r   r   r   r   r   r   r   )r   r   eagain_errorr   r   r   s         r    5test_bug_implicit_none_return_from_socket_error_fixedDSocketBugsTest.test_bug_implicit_none_return_from_socket_error_fixed:   s     F	 u||-OP &2",/	)./3F FM/<,02M  -""#<=Y$ > MMA3r||CTU 0/
 >= 0/s$   7CC-C
C	C
C*c                    [        5       n[        5       UR                  l        SUR                  l        [        S5       n[        5       nX2l        / UR                  l        U R                  [        5       n[        US5        SSS5        U R                  S[        WR                  5      5        SSS5        g! , (       d  f       N<= f! , (       d  f       g= f)z
BUG #6 FIX VERIFICATION: Test that selector timeout now raises correct exception type

Bug was in _socket.py:115 returning None for timeout, treated as connection error
Fixed: Now raises WebSocketTimeoutException directly
r   r   r   Nr   r   r   s        r    3test_bug_wrong_exception_for_selector_timeout_fixedBSocketBugsTest.test_bug_wrong_exception_for_selector_timeout_fixedU   r#   r$   c                    [        5       nSUR                  l        [        R                  " S5      UR
                  l        U R                  [        5       n[        US5        SSS5        SSK	nUR                  S:  a&  U R                  S[        WR                  5      5        gU R                  S[        WR                  5      5        g! , (       d  f       Nn= f)z:
Test that socket.timeout exceptions are properly handled
r   zOperation timed outr   Nr   )   
   zConnection timed out)r   r   r   sockettimeoutr   r   r   r   sysversion_infor   r   r   )r   r   r   r4   s       r    &test_socket_timeout_exception_handling5SocketBugsTest.test_socket_timeout_exception_handlingp   s     F	,/	) &,^^4I%J	" 89RC  : 	w&MM0#bll2CDMM/R\\1BC :9s   C
Cc                    [        5       n[        5       S/UR                  l        SUR                  l        [        S5       n[        5       nX2l        S/UR                  l        [        US5      nU R                  US5        UR                  R                  5         UR                  R                  5         SSS5        g! , (       d  f       g= f)zCTest the correct behavior when SSLWantReadError is properly handleds   data after retryr   r   Tr   N)r   r   r   r   r   r   r   r   assertEqualregisterassert_called)r   r   r   r   results        r    )test_correct_ssl_want_read_retry_behavior8SocketBugsTest.test_correct_ssl_want_read_retry_behavior   s    F	 '7&8:M%N	",/	)./3F FM/<,15M  - )S)FV%89 ""002  ..0 0//s   A5C  
C N)__name__
__module____qualname____firstlineno____doc__r!   r*   r-   r6   r=   __static_attributes__r?       r    r
   r
   !   s"    2V,V6V6D21rF   r
   __main__)r'   r2   unittestunittest.mockr   r   websocket._socketr   websocket._ssl_compatr   websocket._exceptionsr   r   TestCaser
   r@   mainr?   rF   r    <module>rO      sN       % " 2
&{1X&& {1| zMMO rF   