
    g                        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	 d dlZddl	m
Z
mZ ddlmZ ej                  dk(  rddZddZdd	Zdd
ZddZedk(  r e        yy# e$ r Y Fw xY w)    )annotationsN   )ClientConnectionconnect)versionwin32c                 <   ddl } | j                  d      }| j                  d      }d}| j                  j                  j	                  |      }||k(  rt        d      | j                         }| j                  j                  j                  || j                  |            dk(  rt        d      t        j                  |t        j                        }| j                  ||z        }| j                  j                  j                  ||      dk(  rt        d      y)	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_modes           H/var/www/openai/venv/lib/python3.12/site-packages/websockets/__main__.pywin_enable_vt100r!      s     	"MM#.%}}R0-2*''445FG))?@@==?==!!00h9OPTUUEFF nnXs}}===/Q!QR==!!00BaG;<< H    c                    t         j                  j                  d|  d       t         j                  j                          y )Nz	7
[A[Lz
8[Br   stdoutwriteflushstrings    r    print_during_inputr*   3   s<    JJ	 ( 	  JJr"   c                    t         j                  j                  d|  d       t         j                  j                          y )Nz[K
r$   r(   s    r    print_over_inputr-   G   s9    JJ	 (-		! JJr"   c                b   | D ]=  }t        |t              rt        d|z          "t        d|j                         z          ? |j	                         s]t
        j                  dk(  rt        j                  }nt        j                  }t        j                  t        j                         |       y y )Nz< z< (binary) r   )
isinstancestrr*   hexis_setr   platformsignalCTRL_C_EVENTSIGINToskillgetpid)	websocketstopmessagectrl_cs       r    print_incoming_messagesr>   S   s{    gs#tg~.}w{{}<=	 
 ;;= <<7"((F]]F
		V$ r"   c                 p   t        j                  ddd      } | j                         }|j                  dd       |j                  dd	d
       | j	                         }|j
                  rt        dt                y |j                  | j                  d       t        j                  dk(  r	 t                	 t#        |j                        }t        d|j                   d       t)        j*                         }t)        j,                  t.        |f      }|j1                          	 	 t3        d      }|j5                  |       # t        $ rK}t        j                  j                  d| d       t        j                  j!                          Y d }~d }~ww xY w# t$        $ r;}t        d|j                   d| d       t        j&                  d       Y d }~d }~ww xY w# t6        t8        f$ r. |j;                          |j=                          t?        d       Y nw xY w|jA                          y )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Connected to .zFailed to connect to z: r   )targetargsz> zConnection closed.)!argparseArgumentParseradd_mutually_exclusive_groupadd_argument
parse_argsr   printwebsockets_versionrE   errorr   r3   r!   r   stderrr&   r'   r   	Exceptionexit	threadingEventThreadr>   startinputsendKeyboardInterruptEOFErrorsetcloser-   join)parsergrouprK   excr:   r;   threadr<   s           r    mainrf   c   s   $$#3F
 //1E	{<8	ugS9D||./01xxBC ||w	+DHH%	
 	dhhZq)*??D %<ItCTUF
LLN/DkGNN7# 1  	JJ::=bB
 JJ	  %dhhZr#a89$ x( /
-./
 KKMsC   0
E	 ;F  +G' 		FAFF 	G$)1GG$':H$#H$__main__)returnNone)r)   r0   rh   ri   )r:   r   r;   zthreading.Eventrh   ri   )
__future__r   rL   r7   r4   r   rW   readlineImportErrorsync.clientr   r   r   rR   r3   r!   r*   r-   r>   rf   __name__ r"   r    <module>rp      sx    "  	  
 	 3 2 <<7=<(	% 8v zF e  		s   A A'&A'