
    %
i/                         d dl Z d dlZd dlZd dlZd dlmZ  G d d          Zd Z G d d          Zdd ej	        fdZ
d	 Z	 e n# e$ r  e            ZY nw xY wed
k    rd dlZ ej                     dS dS )    N)winoutc                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )ThreadWriterzRAssign an instance to sys.stdout for per-thread printing objects - Courtesy Guido!c                 "    i | _         d| _        dS )z.Constructor -- initialize the table of writersN)writers
origStdOutselfs    C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\pythonwin/pywin/Demos/cmdserver.py__init__zThreadWriter.__init__   s        c                     || j         t          j                    <   | j        t          j        | _        | t          _        dS dS )z*Register the writer for the current threadN)r   _thread	get_identr   sysstdout)r
   writers     r   registerzThreadWriter.register   s;    ,2W&(()?"!jDOCJJJ #"r   c                     	 | j         t          j                    = n# t          $ r Y nw xY wt	          | j                   dk    r| j        t          _        d| _        dS dS )z0Remove the writer for the current thread, if anyr   N)r   r   r   KeyErrorlenr   r   r   r	   s    r   
unregisterzThreadWriter.unregister   sn    	W.0011 	 	 	D	t|!!CJ"DOOO "!s    
))c                 h    | j                             t          j                    | j                   dS )z6Return the current thread's writer, default sys.stdoutN)r   getr   r   r   r	   s    r   	getwriterzThreadWriter.getwriter&   s+    *,,do>>>>>r   c                 T    |                                                      |           dS )z8Write to the current thread's writer, default sys.stdoutN)r   write)r
   strs     r   r   zThreadWriter.write*   s&    s#####r   N)	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      se        XX  
  # # #? ? ?$ $ $ $ $r   r   c                  x    d} | dk     r1t          d|            t          j        d           | dz  } | dk     /d S d S )N   i  zHello there no2   )printwin32apiSleep)nums    r   Testr+   /   sM    
C
**$$$rq ******r   c                       e Zd ZdZdZdZdZdS )flagsr   r%         N)r   r    r!   SERVER_BESTSERVER_IMMEDIATESERVER_THREADSERVER_PROCESSr#   r   r   r-   r-   7   s#        KMNNNr   r-   c                     t          j        |d t           j        j                  }|s| }|                    |           t          j        t          || ||f           d S )N)r   WindowOutputr-   WQ_IDLECreater   start_new_threadServerThread)cmdtitlebCloseOnEndserverFlagsouts        r   StartServerr?   >   s^    

eT6<+?
@
@C JJu \Ce[+IJJJJJr   c                    	 t                               |            t          d|z             d}	 dd l}t	          |dz   |j                   n	#  d}Y nxY w|rt          d           nMt          j                    \  }}}t          |d|           t          j	        |           d }t          d           t           
                                 |r|r| j                                         d S d S d S #  t          j                    \  }}}t          |d|           t          j	        |           d }t          d           Y d S xY w)	NzExecuting "%s"
r%   r   
z"Command terminated without errors.z: z.Command terminated with an unhandled exceptionzThread failed)r   r   r'   __main__exec__dict__r   exc_info	tracebackprint_tbr   frameDestroyWindow)	myoutr:   r;   r<   bOKrB   tvtbs	            r   r9   r9   H   sw    3&'''	OOOtX.////	CCC 	D67777|~~HAq"!T1r"""BBCCC 	(; 	(K%%'''''	( 	( 	( 	(<>>1baq2os$   .C2 A C2 ABC2 2AErB   )r   r   rF   r(   pywin.frameworkr   r   r+   r-   r0   r?   r9   r   	NameErrorr   	demoutils
NotAScriptr#   r   r   <module>rS      s@  
  



      " " " " " "$ $ $ $ $ $ $ $D           QE<M K K K K  D
FF   \^^FFFzI s   A AA