
    +gXR                         S SK r S SKrS SKrS SKrS SKJrJr  SSKJrJ	r	J
r
Jr  SSKJrJr  SSKJrJr  SSKJrJr  SSKJrJrJrJrJr  SS	KJrJrJrJr  SS
K J!r!  SSK"J#r#   SS/r$ " S S5      r%S\%4S\&4S jjr'g)    N)OptionalUnion   )ABNFSTATUS_NORMALcontinuous_frameframe_buffer)WebSocketProtocolException"WebSocketConnectionClosedException)SUPPORTED_REDIRECT_STATUSES	handshake)connect
proxy_info)debugerrortraceisEnabledForErrorisEnabledForTrace)getdefaulttimeoutrecvsendsock_opt)ssl)NoLock	WebSocketcreate_connectionc                   ^   \ rS rSrSr      S1S\S\S\4S jjrS rS	 rS
 r	S r
S rS\\\S4   4S jrS\\\S4   4S jr\" \\5      rS r\" \5      rS r\" \5      rS rS r\" \5      rS r\R8                  4S\\\4   S\S\4S jjrS\S\4S jr S\\\!4   S\4S jr"S\4S jr#S\S\4S jr$S2S\\\4   4S jjr%S2S\\\4   4S  jjr&S\\\4   4S! jr'S3S"\S\(4S# jjr)S3S"\S\(4S$ jjr*S% r+\,S&4S'\S(\4S) jjr-\,S&S*4S'\S(\S\4S+ jjr.S, r/S- r0S\\\4   4S. jr1S/ r2S0r3g)4r   '   a:  
Low level WebSocket interface.

This class is based on the WebSocket protocol `draft-hixie-thewebsocketprotocol-76 <http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76>`_

We can connect to the websocket server and send/receive data.
The following example is an echo client.

>>> import websocket
>>> ws = websocket.WebSocket()
>>> ws.connect("ws://echo.websocket.events")
>>> ws.recv()
'echo.websocket.events sponsored by Lob.com'
>>> ws.send("Hello, Server")
19
>>> ws.recv()
'Hello, Server'
>>> ws.close()

Parameters
----------
get_mask_key: func
    A callable function to get new mask keys, see the
    WebSocket.set_mask_key's docstring for more information.
sockopt: tuple
    Values for socket.setsockopt.
    sockopt must be tuple and each element is argument of sock.setsockopt.
sslopt: dict
    Optional dict object for ssl socket options. See FAQ for details.
fire_cont_frame: bool
    Fire recv event for each cont frame. Default is False.
enable_multithread: bool
    If set to True, lock send method.
skip_utf8_validation: bool
    Skip utf8 validation.
Nfire_cont_frameenable_multithreadskip_utf8_validationc                 d   [        X#5      U l         SU l        SU l        SU l        Xl        [        U R                  U5      U l        [        XF5      U l        U(       a5  [        R                  " 5       U l        [        R                  " 5       U l        g[        5       U l        [        5       U l        g)z
Initialize WebSocket object.

Parameters
----------
sslopt: dict
    Optional dict object for ssl socket options. See FAQ for details.
NF)r   handshake_responsesock	connectedget_mask_keyr	   _recvr   
cont_frame	threadingLocklockreadlockr   )selfr&   sockoptssloptr   r    r!   _s           W/Users/Alptekin/Desktop/izin_takip/venv/lib/python3.13/site-packages/websocket/_core.py__init__WebSocket.__init__M   s}    $ !1"&-1	((5IJ*?Q!(DI%NN,DMDI"HDM    c              #   4   #     U R                  5       v   M  7f)zH
Allow iteration over websocket, implying sequential `recv` executions.
r   r-   s    r1   __iter__WebSocket.__iter__p   s      ))+ s   c                 "    U R                  5       $ Nr6   r7   s    r1   __next__WebSocket.__next__w   s    yy{r4   c                 "    U R                  5       $ r;   )r<   r7   s    r1   nextWebSocket.nextz   s    }}r4   c                 6    U R                   R                  5       $ r;   )r$   filenor7   s    r1   rB   WebSocket.fileno}   s    yy!!r4   c                     Xl         g)aK  
Set function to create mask key. You can customize mask key generator.
Mainly, this is for testing purpose.

Parameters
----------
func: func
    callable object. the func takes 1 argument as integer.
    The argument means length of mask key.
    This func must return string(byte array),
    which length is argument specified.
N)r&   )r-   funcs     r1   set_mask_keyWebSocket.set_mask_key   s
     !r4   returnc                 .    U R                   R                  $ )z
Get the websocket timeout (in seconds) as an int or float

Returns
----------
timeout: int or float
     returns timeout value (in seconds). This value could be either float/integer.
)r   timeoutr7   s    r1   
gettimeoutWebSocket.gettimeout   s     }}$$$r4   rJ   c                 ~    XR                   l        U R                  (       a  U R                  R                  U5        gg)z
Set the timeout to the websocket.

Parameters
----------
timeout: int or float
    timeout time (in seconds). This value could be either float/integer.
N)r   rJ   r$   
settimeout)r-   rJ   s     r1   rN   WebSocket.settimeout   s,     !(99II  ) r4   c                 R    U R                   (       a  U R                   R                  $ g)z
Get subprotocol
N)r#   subprotocolr7   s    r1   getsubprotocolWebSocket.getsubprotocol   s"     ""**666r4   c                 R    U R                   (       a  U R                   R                  $ g)z
Get handshake status
N)r#   statusr7   s    r1   	getstatusWebSocket.getstatus   s"     ""**111r4   c                 R    U R                   (       a  U R                   R                  $ g)z
Get handshake response header
N)r#   headersr7   s    r1   
getheadersWebSocket.getheaders   s"     ""**222r4   c                 Z     [        U R                  [        R                  5      $ !    g= fNF)
isinstancer$   r   	SSLSocketr7   s    r1   is_sslWebSocket.is_ssl   s&    	dii77	s   #& *c           
      6   UR                  SU R                  R                  5      U R                  l        [        XR                  [	        S0 UD6UR                  SS5      5      u  U l        n [        U R                  U/UQ70 UD6U l        [        UR                  SS5      5       H  nU R                  R                  [        ;   d  M#  U R                  R                  S   nU R                  R                  5         [        UU R                  [	        S0 UD6UR                  SS5      5      u  U l        n[        U R                  U/UQ70 UD6U l        M     SU l        g!   U R                  (       a!  U R                  R                  5         SU l        e = f)	a}  
Connect to url. url is websocket url scheme.
ie. ws://host:port/resource
You can customize using 'options'.
If you set "header" list object, you can set your own custom header.

>>> ws = WebSocket()
>>> ws.connect("ws://echo.websocket.events",
        ...     header=["User-Agent: MyProgram",
        ...             "x-custom: header"])

Parameters
----------
header: list or dict
    Custom http header list or dict.
cookie: str
    Cookie value.
origin: str
    Custom origin url.
connection: str
    Custom connection header value.
    Default value "Upgrade" set in _handshake.py
suppress_origin: bool
    Suppress outputting origin header.
host: str
    Custom host header string.
timeout: int or float
    Socket timeout time. This value is an integer or float.
    If you set None for this value, it means "use default_timeout value"
http_proxy_host: str
    HTTP proxy host name.
http_proxy_port: str or int
    HTTP proxy port. Default is 80.
http_no_proxy: list
    Whitelisted host names that don't use the proxy.
http_proxy_auth: tuple
    HTTP proxy auth information. Tuple of username and password. Default is None.
http_proxy_timeout: int or float
    HTTP proxy timeout, default is 60 sec as per python-socks.
redirect_limit: int
    Number of redirects to follow.
subprotocols: list
    List of available subprotocols. Default is None.
socket: socket
    Pre-initialized stream socket.
rJ   socketNredirect_limit   locationT )getr   rJ   r   r   popr$   r   r#   rangerU   r   rY   closer%   )r-   urloptionsaddrsr0   s        r1   r   WebSocket.connect   sV   ^ !(It}}7L7L M"
 5W 5w{{8T7R
	5	&/		3&R&R'&RD#7;;'7;<**115PP1199*ECIIOO%'."-W-Hd3	($DIu /8		3/)./29/D+ = "DN	yy		! 	s   /AE# BE# #5Fpayloadopcodec                 P    [         R                  " X5      nU R                  U5      $ )z
Send the data as string.

Parameters
----------
payload: str
    Payload must be utf-8 string or unicode,
    If the opcode is OPCODE_TEXT.
    Otherwise, it must be string(byte array).
opcode: int
    Operation code (opcode) to send.
)r   create_frame
send_frame)r-   rp   rq   frames       r1   r   WebSocket.send  s#     !!'2u%%r4   	text_datac                 B    U R                  U[        R                  5      $ )z
Sends UTF-8 encoded text.
)r   r   OPCODE_TEXT)r-   rw   s     r1   	send_textWebSocket.send_text+  s     yyD$4$455r4   datac                 B    U R                  U[        R                  5      $ )z
Sends a sequence of bytes.
r   r   OPCODE_BINARYr-   r|   s     r1   
send_bytesWebSocket.send_bytes1  s     yyt1122r4   c                    U R                   (       a  U R                   Ul         UR                  5       n[        U5      n[        5       (       a3  [	        S[        U5       35        [	        SUR                  5        35        U R                     U(       a  U R                  U5      nX$S nU(       a  M  SSS5        U$ ! , (       d  f       U$ = f)a  
Send the data frame.

>>> ws = create_connection("ws://echo.websocket.events")
>>> frame = ABNF.create_frame("Hello", ABNF.OPCODE_TEXT)
>>> ws.send_frame(frame)
>>> cont_frame = ABNF.create_frame("My name is ", ABNF.OPCODE_CONT, 0)
>>> ws.send_frame(frame)
>>> cont_frame = ABNF.create_frame("Foo Bar", ABNF.OPCODE_CONT, 1)
>>> ws.send_frame(frame)

Parameters
----------
frame: ABNF frame
    frame data created by ABNF.create_frame
z++Sent raw: z++Sent decoded: N)	r&   formatlenr   r   repr__str__r+   _send)r-   ru   r|   lengthls        r1   rt   WebSocket.send_frame7  s    " !%!2!2E||~TLd-.$U]]_$567YYJJt$Bx $ 
  Y
 s   $B<<
Cc                 B    U R                  U[        R                  5      $ )zn
Send a binary message (OPCODE_BINARY).

Parameters
----------
payload: bytes
    payload of message to send.
r~   r-   rp   s     r1   send_binaryWebSocket.send_binaryV  s     yy$"4"455r4   c                     [        U[        5      (       a  UR                  S5      nU R                  U[        R
                  5        g)zV
Send ping data.

Parameters
----------
payload: str
    data payload to send server.
utf-8N)r^   strencoder   r   OPCODE_PINGr   s     r1   pingWebSocket.pinga  3     gs##nnW-G		'4++,r4   c                     [        U[        5      (       a  UR                  S5      nU R                  U[        R
                  5        g)zV
Send pong data.

Parameters
----------
payload: str
    data payload to send server.
r   N)r^   r   r   r   r   OPCODE_PONGr   s     r1   pongWebSocket.pongn  r   r4   c                 L   U R                      U R                  5       u  pSSS5        W[        R                  :X  a@  Wn[	        U[
        5      (       a  UR                  S5      $ [	        U[        5      (       a  U$ gU[        R                  :X  a  WnU$ g! , (       d  f       N{= f)zg
Receive string data(byte array) from the server.

Returns
----------
data: string (byte array) value.
Nr    )	r,   	recv_datar   ry   r^   bytesdecoder   r   )r-   rq   r|   data_receiveddata_binarys        r1   r   WebSocket.recv{  s     ]]>>+LF T%%%/3M-//$++G44M3//$$ 0t)))!%K ]s   B
B#control_framec                 B    U R                  U5      u  p#X#R                  4$ )a  
Receive data with operation code.

Parameters
----------
control_frame: bool
    a boolean flag indicating whether to return control frame
    data, defaults to False

Returns
-------
opcode, frame.data: tuple
    tuple of operation code and string(byte array) value.
)recv_data_framer|   )r-   r   rq   ru   s       r1   r   WebSocket.recv_data  s#     ,,];zz!!r4   c                     U R                  5       n[        5       (       aA  [        S[        UR	                  5       5       35        [        SUR                  5        35        U(       d  [        SU 35      eUR                  [        R                  [        R                  [        R                  4;   ar  U R                  R                  U5        U R                  R                  U5        U R                  R                  U5      (       a  U R                  R!                  U5      $ OUR                  [        R"                  :X  a  U R%                  5         UR                  U4$ UR                  [        R&                  :X  aV  [)        UR*                  5      S:  a  U R-                  UR*                  5        O[        S5      eU(       a  UR                  U4$ O3UR                  [        R.                  :X  a  U(       a  UR                  U4$ GM
  )aM  
Receive data with operation code.

If a valid ping message is received, a pong response is sent.

Parameters
----------
control_frame: bool
    a boolean flag indicating whether to return control frame
    data, defaults to False

Returns
-------
frame.opcode, frame: tuple
    tuple of operation code and string(byte array) value.
z++Rcv raw: z++Rcv decoded: zNot a valid frame ~   zPing message is too long)
recv_framer   r   r   r   r   r
   rq   r   ry   r   OPCODE_CONTr(   validateaddis_fireextractOPCODE_CLOSE
send_closer   r   r|   r   r   )r-   r   ru   s      r1   r   WebSocket.recv_data_frame  s   " OO%E ""D$8#9:;'89: 13EeW1MNN  ""  " 
 ((/##E*??**511??22599 2 !2!22!||U**!1!11uzz?S(IIejj)45OPP  <<.. !!1!11  <<..A r4   c                 6    U R                   R                  5       $ )zg
Receive data as frame from server.

Returns
-------
self.frame_buffer.recv_frame(): ABNF frame object
)r	   r   r7   s    r1   r   WebSocket.recv_frame  s       ++--r4   r4   rU   reasonc                     US:  d  U[         R                  :  a  [        S5      eSU l        U R	                  [
        R                  " SU5      U-   [         R                  5        g)z
Send close data to the server.

Parameters
----------
status: int
    Status code to send. See STATUS_XXX.
reason: str or bytes
    The reason to close. This must be string or UTF-8 bytes.
r   code is invalid rangeF!HN)r   	LENGTH_16
ValueErrorr%   r   structpackr   )r-   rU   r   s      r1   r   WebSocket.send_close  sM     A:4>>1455		&++dF+f4d6G6GHr4   re   c                    U R                   (       d  gUS:  d  U[        R                  :  a  [        S5      e SU l         U R	                  [
        R                  " SU5      U-   [        R                  5        U R                  R                  5       nU R                  R                  U5        [        R                  " 5       nUb  [        R                  " 5       U-
  U:  a   U R                  5       nUR                  [        R                  :w  a  MP  [        5       (       al  [
        R                  " SUR                   SS 5      S   nUS:  a  US::  a  [#        S	[%        U5       35        O!U[&        :w  a  [)        S	[%        U5       35         U R                  R                  U5        U R                  R+                  [,        R.                  5        U R+                  5         g!    MZ  = f!    N= f)
a"  
Close Websocket object

Parameters
----------
status: int
    Status code to send. See VALID_CLOSE_STATUS in ABNF.
reason: bytes
    The reason to close in UTF-8.
timeout: int or float
    Timeout until receive a close frame.
    If None, it will wait forever until receive a close frame.
Nr   r   Fr      i  i  zclose status: )r%   r   r   r   r   r   r   r   r$   rK   rN   timer   rq   r   unpackr|   r   r   r   r   shutdownrc   	SHUT_RDWR)r-   rU   r   rJ   sock_timeout
start_timeru   recv_statuss           r1   rk   WebSocket.close  s~    ~~A:4>>1455	"DNIIfkk$/&8$:K:KL99//1LII  )J/TYY[:%=%G OO-E||t'8'88 (**&,mmD%**Qq/&J1&M&$.;$3F!N43D2E"FG(M9!N43D2E"FG II  .IIv//0 		s2   B(G+ ".G# G+ A;G# AG+ #G(%G+ +G/c                 z    U R                   (       a*  U R                  R                  [        R                  5        gg)zQ
Low-level asynchronous abort, wakes up other threads that are waiting in recv_*
N)r%   r$   r   rc   r   r7   s    r1   abortWebSocket.abort  s(     >>IIv//0 r4   c                 x    U R                   (       a)  U R                   R                  5         SU l         SU l        gg)z
close socket, immediately.
NF)r$   rk   r%   r7   s    r1   r   WebSocket.shutdown%  s,     99IIOODI"DN r4   c                 .    [        U R                  U5      $ r;   )r   r$   r   s     r1   r   WebSocket._send.  s    DIIt$$r4   c                      [        U R                  U5      $ ! [         a;    U R                  (       a  U R                  R                  5         S U l        SU l        e f = fr]   )r   r$   r   rk   r%   )r-   bufsizes     r1   r'   WebSocket._recv1  sM    			7++1 	yy		!DI"DN	s
    AA)	r%   r(   r	   r&   r#   r+   r,   r$   r   )NNNFTF)r   )F)4__name__
__module____qualname____firstlineno____doc__boolr2   r8   r<   r?   rB   rF   r   floatintrK   rN   propertyrJ   rR   rQ   rV   rU   rZ   r`   rY   r   r   ry   r   r   r   rz   	bytearrayr   rt   r   r   r   r   tupler   r   r   r   r   rk   r   r   r   r'   __static_attributes__rg   r4   r1   r   r   '   s&   #N  %#'%*!%
 !% !!% #!%F"!	%E%d"23 	%*%sD(8"9 * z:.G >*K i F z"GHT >B=M=M &E%*- &s &RU &"63 63 63uUI%56 33 33 >	65 	6S 	6-E#u*- --E#u*- -eCJ' ,"t " "$1/T 1/e 1/f. (5c I Ie I  #0UV ,C , ,s ,\1#%%U
+ %r4   rl   c           	      8   UR                  S/ 5      nUR                  S0 5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nU" S	UUUUUS.UD6n	U	R                  Ub  UO	[        5       5        U	R                  " U 40 UD6  U	$ )
a  
Connect to url and return websocket object.

Connect to url and return the WebSocket object.
Passing optional timeout parameter will set the timeout on the socket.
If no timeout is supplied,
the global default timeout setting returned by getdefaulttimeout() is used.
You can customize using 'options'.
If you set "header" list object, you can set your own custom header.

>>> conn = create_connection("ws://echo.websocket.events",
     ...     header=["User-Agent: MyProgram",
     ...             "x-custom: header"])

Parameters
----------
class_: class
    class to instantiate when creating the connection. It has to implement
    settimeout and connect. It's __init__ should be compatible with
    WebSocket.__init__, i.e. accept all of it's kwargs.
header: list or dict
    custom http header list or dict.
cookie: str
    Cookie value.
origin: str
    custom origin url.
suppress_origin: bool
    suppress outputting origin header.
host: str
    custom host header string.
timeout: int or float
    socket timeout time. This value could be either float/integer.
    If set to None, it uses the default_timeout value.
http_proxy_host: str
    HTTP proxy host name.
http_proxy_port: str or int
    HTTP proxy port. If not set, set to 80.
http_no_proxy: list
    Whitelisted host names that don't use the proxy.
http_proxy_auth: tuple
    HTTP proxy auth information. tuple of username and password. Default is None.
http_proxy_timeout: int or float
    HTTP proxy timeout, default is 60 sec as per python-socks.
enable_multithread: bool
    Enable lock for multithread.
redirect_limit: int
    Number of redirects to follow.
sockopt: tuple
    Values for socket.setsockopt.
    sockopt must be a tuple and each element is an argument of sock.setsockopt.
sslopt: dict
    Optional dict object for ssl socket options. See FAQ for details.
subprotocols: list
    List of available subprotocols. Default is None.
skip_utf8_validation: bool
    Skip utf8 validation.
socket: socket
    Pre-initialized stream socket.
r.   r/   r   Fr    Tr!   )r.   r/   r   r    r!   rg   )ri   rN   r   r   )
rl   rJ   class_rm   r.   r/   r   r    r!   websocks
             r1   r   r   <  s    x kk)R(G[[2&Fkk"3U;O %94@";;'=uE '-1 G '"5w;L;NOOOC#7#Nr4   )(rc   r   r)   r   typingr   r   _abnfr   r   r   r	   _exceptionsr
   r   
_handshaker   r   _httpr   r   _loggingr   r   r   r   r   _socketr   r   r   r   _ssl_compatr   _utilsr   __all__r   r   r   rg   r4   r1   <module>r      sl        " G F W > & O O < <  & +
,R Rj )-Y K3 Kr4   