o
    DRh                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlZzd dlZW n	 ey)   Y nw ddl	m
Z
mZ ddlmZ ejdkrBdd	d
ZdddZdddZdddZdddZedkr_e  dS dS )    )annotationsN   )ClientConnectionconnect)versionwin32returnNonec                  C  s   ddl } | d}| d}d}| jj|}||krtd|  }| jj|| |dkr4tdt	|t
j}| ||B }| jj||dkrPtddS )	z
        Enable VT-100 for console output on Windows.

        See also https://github.com/python/cpython/issues/73245.

        r   Ni   zunable to obtain stdout handlez$unable to query current console modezunable to set console mode)ctypesc_uintwindllkernel32GetStdHandleRuntimeErrorGetConsoleModebyrefint
from_bytessys	byteorderSetConsoleMode)r   STD_OUTPUT_HANDLEINVALID_HANDLE_VALUE"ENABLE_VIRTUAL_TERMINAL_PROCESSINGhandlecur_modepy_int_modenew_mode r    U/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/websockets/__main__.pywin_enable_vt100   s   

r"   stringstrc                 C  "   t jd|  d t j  d S )Nz	7
[A[Lz
8[Br   stdoutwriteflushr#   r    r    r!   print_during_input3   s   r+   c                 C  r%   )Nz[K
r&   r*   r    r    r!   print_over_inputG   s   r-   	websocketr   stopthreading.Eventc                 C  sj   | D ]}t |trtd|  qtd|   q| s3tjdkr&tj}ntj	}t
t
 | d S d S )Nz< z< (binary) r   )
isinstancer$   r+   hexis_setr   platformsignalCTRL_C_EVENTSIGINToskillgetpid)r.   r/   messagectrl_cr    r    r!   print_incoming_messagesS   s   

r=   c               
   C  s  t jdddd} |  }|jddd |jdd	d
d |  }|jr+tdt  d S |jd u r5| 	d t
jdkrazt  W n! ty` } zt
jd| d t
j  W Y d }~nd }~ww zt|j}W n# ty } ztd|j d| d t
d W Y d }~nd }~ww td|j d t }tjt||fd}|  z	 td}|| q ttfy   |  |  td Y nw |   d S )Nzpython -m websocketszInteractive WebSocket client.F)progdescriptionadd_helpz	--version
store_true)actionuriz<uri>?)metavarnargszwebsockets z+the following arguments are required: <uri>r   zUnable to set terminal to VT100 mode. This is only supported since Win10 anniversary update. Expect weird symbols on the terminal.
Error: r,   zFailed to connect to z: .r   zConnected to )targetargsTz> zConnection closed.)!argparseArgumentParseradd_mutually_exclusive_groupadd_argument
parse_argsr   printwebsockets_versionrC   errorr   r4   r"   r   stderrr(   r)   r   	Exceptionexit	threadingEventThreadr=   startinputsendKeyboardInterruptEOFErrorsetcloser-   join)parsergrouprI   excr.   r/   threadr;   r    r    r!   mainc   s`   




rd   __main__)r   r	   )r#   r$   r   r	   )r.   r   r/   r0   r   r	   )
__future__r   rJ   r8   r5   r   rU   readlineImportErrorsync.clientr   r   r   rP   r4   r"   r+   r-   r=   rd   __name__r    r    r    r!   <module>   s,    





;
