
    %
i#                        d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
Z
ddlZddlZddlmZ ddlmZ e	rddlmZ dd	lmZmZ dd
lmZ dZddZddZddZ G d d          Z G d de          ZddZdS )zException and error handling.

This contains the core exceptions that the implementations should raise
as well as the IActiveScriptError interface code.
    )annotationsN)TracebackType)TYPE_CHECKING)axscript)COMException)DebugManager)AXScriptCodeBlock	COMScript)AXSitetextstrc                :    t          t          |                     S )z'Format a string suitable for an AX Host)
ExpandTabsAddCRr   s    C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\win32comext/axscript/client/error.pyFormatForAXr      s     eDkk"""    c                .    t          j        dd|           S )Nz\tz    resubr   s    r   r   r   #       6%&&&r   c                .    t          j        dd|           S )Nz\nz
r   r   s    r   r   r   '   r   r   c                  J    e Zd ZdZej        gZg dZd ZddZ	d Z
d Zd	 Zd
S )IActiveScriptErrorzAn implementation of IActiveScriptError

    The ActiveX Scripting host calls this client whenever we report
    an exception to it.  This interface provides the exception details
    for the host to report to the user.
    )GetSourceLineTextGetSourcePositionGetExceptionInfoc                &    t          d|           dS )Nz#IActiveScriptError QI - unknown IIDr   )print)selfiids     r   _query_interface_z$IActiveScriptError._query_interface_6   s    3S999qr   excAXScriptExceptionc                    || _         d S N	exception)r"   r%   s     r   _SetExceptionInfoz$IActiveScriptError._SetExceptionInfo:   s    r   c                    | j         j        S r(   )r*   linetextr"   s    r   r   z$IActiveScriptError.GetSourceLineText=   s    ~&&r   c                l    | j         j        }|| j         j        | j         j        z   dz
  | j         j        fS )N   )r*   sourceContextlinenostartLineNocolno)r"   ctxs     r   r   z$IActiveScriptError.GetSourcePosition@   s:    n* N!DN$>>BN 
 	
r   c                    | j         S r(   r)   r.   s    r   r   z#IActiveScriptError.GetExceptionInfoI   s
    ~r   N)r%   r&   )__name__
__module____qualname____doc__r   IID_IActiveScriptError_com_interfaces__public_methods_r$   r+   r   r   r    r   r   r   r   +   s          !78UUU     ' ' '
 
 
    r   r   c                  L     e Zd ZdZ	 	 	 dd fdZddZddZddZddZ xZ	S )r&   zA class used as a COM exception.

    Note this has attributes which conform to the standard attributes
    for COM exceptions, plus a few others specific to our IActiveScriptError
    object.
    Nsiter
   	codeBlockAXScriptCodeBlock | Noneexc_typeNone	exc_valueBaseException | Noneexc_tracebackc                0   t                                          dt          j        d           ||t	          j        dt          d           |d| _        d| _        n|j	        | _        |j
        | _        d| _        |                     ||           d S )	NzUnknown ExceptionzPython ActiveX Scripting Engine)descriptionscodesourcezA`exc_type` and `exc_traceback` were redundant and are now unused.   )category
stacklevelr    )super__init__winerrorDISP_E_EXCEPTIONwarningswarnDeprecationWarningr1   r3   sourceContextCookiestartLineNumberr-   &_AXScriptException__BuildFromException)r"   r@   rA   rC   rE   rG   	__class__s         r   rQ   zAXScriptException.__init__U   s     	++4 	 	
 	
 	
 =#<MS+    !"D D!*!>D(8D!!$	22222r   valuec                    t           rdd l}|                                 	 t          |t                    r|                     |           d S |                     ||           d S #  t          j                      xY wNr   )		debugging	linecache
clearcache
isinstanceSyntaxError_BuildFromSyntaxError_BuildFromOther	traceback	print_exc)r"   r@   r[   r_   s       r   __BuildFromExceptionz&AXScriptException.__BuildFromExceptionv   s     	#  """	%-- 2**511111$$T511111	!!!s   *A% A% %A;r%   rb   c                    |j         pd}|j        pd}|j        pd}|j        pd}t	          |          | _        || _        |dz
  | _        t          |                                          | _	        d S )NzUnknown Errorr   rO   r0   )
msgoffsetr   r2   r   rI   r4   r   rstripr-   )r"   r%   ri   rj   liner2   s         r   rc   z'AXScriptException._BuildFromSyntaxError   sl    g(qx~2q&s++aZ
"4;;==11r   c                *   |r|j         nd }|rt          |          nd }d| _        d| _        t          r?t          j        |||          }t          d                    |                    | _	        d S g d}|}|r3| 
                    ||          \  }}	}
}|d d         dk    rn	|j        }|3g }|rj|}|re| 
                    ||          \  }}	}
}|
|v rnE|                    d          r|	| _        || _        |                    ||	|
|f           |j        }|en|}dg}|                    t          j        |                     t#          |t$          j                  rb|j         d|j        d	d
}|j        t,          j        k    r!|j        r|j        d         r|j        d         }|                    d|z              n(|                    t          j        ||                     t          d                    |                    | _	        d S )Nr   rO   )r_importr_reloadr_open   z<Scriptz#Traceback (most recent call last):
z (0xx)rL   zCOM Error: )__traceback__typer4   r2   r^   re   format_exceptionr   joinrI   ExtractTracebackInfotb_next
startswithr-   appendextendformat_listra   	pythoncom	com_errorstrerrorhresultrR   rS   	excepinfoformat_exception_only)r"   r@   r[   tbrC   list
hide_namestb_topfilenamer2   namerl   format_itemstb_lookbitsdescs                   r   rd   z!AXScriptException._BuildFromOther   sc   $)3U  t"'14;;;T
 	-hrBBD)"''$--88DF
 
 


  	$+/+D+DVT+R+R(HfdD|y((^F	  	$
  	,2G */3/H/HRV/W/W,&$:%% &&y11 )"(DK$(DM##XvtT$BCCC!/  * F67I),77888eY011 
	Jn<<%-<<<<D!:::O ;OA& ; q)KK,----KK	7%HHIII%bggdmm44r   r   r   c                   dd l }|j        }|j        j        }|j        }|j        }|                    ||          }|s1|j                            |          }	|	r|		                    |          }|r|
                                }nd }||||fS r]   )r_   	tb_linenotb_framef_codeco_filenameco_namegetlinescriptCodeBlocksget	GetLineNostrip)
r"   r   r@   r_   r2   cor   r   rl   rA   s
             r   ry   z&AXScriptException.ExtractTracebackInfo   s    [>z$,,Xv>> 	3-11(;;I 3 **622 	::<<DDDt++r   )NNN)
r@   r
   rA   rB   rC   rD   rE   rF   rG   rD   )r@   r
   r[   rF   )r%   rb   )r   r   r@   r
   )
r7   r8   r9   r:   rQ   rY   rc   rd   ry   __classcell__)rZ   s   @r   r&   r&   M   s          *."3 3 3 3 3 3 3B   
2 
2 
2 
285 85 85 85t, , , , , , , ,r   r&   scriptingSiter   debugManagerr   exceptionInstancec                4   t                      }|                    |           t          j        j                            |t          j                  }|r|                                }|sdS 	 | 	                    |          }nh# t          j        $ rV}t          d|           t          d|j        d           t          d|j        d           t          j        }Y d}~nd}~ww xY w|t          j        k    rt%          t          j                  }|S |S )a[  General function to handle any exception in AX code

    This function creates an instance of our IActiveScriptError interface, and
    gives it to the host, along with out exception class.  The host will
    likely call back on the IActiveScriptError interface to get the source text
    and other information not normally in COM exceptions.
    Nz**OnScriptError failed:zException description: ''zException text: ')rJ   )r   r+   win32comserverutilwrapr   r;   HandleRuntimeErrorOnScriptErrorr   r   r!   rI   r-   rR   S_FALSES_OKr   SCRIPT_E_REPORTED)	r   r   r   instancegatewayfCallOnErrorresultdetailsrets	            r   ProcessAXScriptExceptionr      s3    "##H0111o"''(2QRRG #6688 	4",,W55 " " "'111K):)FKKKLLLA"3"<AAABBB!	"  !;<<<
 ! s   .B C)AC$$C))r   r   )r   r   r   r   r   r&   ) r:   
__future__r   r   re   rT   typesr   typingr   r   win32com.server.utilr   rR   win32com.axscriptr   win32com.server.exceptionr   !win32comext.axscript.client.debugr   %win32comext.axscript.client.frameworkr	   r
   "win32comext.axscript.server.axsiter   r^   r   r   r   r   r&   r   r>   r   r   <module>r      s    # " " " " " 				                                 & & & & & & 2 2 2 2 2 2 :>>>>>>RRRRRRRR999999	# # # #' ' ' '' ' ' '       DO, O, O, O, O, O, O, O,d%! %! %! %! %! %!r   