a „oe<ã@sdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z ddl mZmZmZmZmZmZdZdZdd„Zd d „Zd d „ZGd d„de jƒZGdd„dƒZGdd„dƒZGdd„de jƒZGdd„de jƒZdd„Zefdd„Z e!dk�re ƒdS)zþPython ActiveX Scripting Implementation This module implements the Python ActiveX Scripting client. To register the implementation, simply "run" this Python program - ie either double-click on it, or run "python.exe pyscript.py" from the command line. éN)Úaxscript)Ú frameworkÚscriptdispatch)ÚSCRIPTTEXT_FORCEEXECUTIONÚSCRIPTTEXT_ISEXPRESSIONÚSCRIPTTEXT_ISPERSISTENTÚ ExceptionÚ RaiseAssertÚtracez&{DF630910-1C1D-11d0-AE36-8C0F5E000000}cGstr t|ŽdS©N)Údebugging_attrr )Úargs©rúEC:\Program Files\Certbot\pkgs\win32comext\axscript\client\pyscript.pyÚdebug_attr_print"srcCst dd|¡S)Nú z ©ÚreÚsub©ÚtextrrrÚ ExpandTabs'srcCst dd|¡S)NÚ z rrrrrÚAddCR+src@seZdZdd„ZdS)ÚAXScriptCodeBlockcCsdtj |¡S)Nz PyScript - )rrÚGetDisplayName©Úselfrrrr0sz AXScriptCodeBlock.GetDisplayNameN)Ú__name__Ú __module__Ú __qualname__rrrrrr/src@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) ÚAXScriptAttributez$An attribute in a scripts namespace.cCs||jd<dS©NÚ_scriptEngine_©Ú__dict__)rÚenginerrrÚ__init__=szAXScriptAttribute.__init__cCsB|ddkr$|dd…dkr$t|ƒ‚| |¡}|dur>t|ƒ‚|S)NéÚ_éÿÿÿÿ)ÚAttributeErrorÚ_FindAttribute_)rÚattrÚrcrrrÚ __getattr__@s  zAXScriptAttribute.__getattr__cCsd|jd<dSr"r$rrrrÚ_Close_HszAXScriptAttribute._Close_c Cshz|j| ¡jWSty$Yn0|j ¡D]*}z| ||¡WStyXYq00q0t|ƒ‚dSr )ÚsubItemsÚlowerÚattributeObjectÚKeyErrorÚvaluesÚ_DoFindAttribute_r+)rÚobjr-Úitemrrrr6Ks  z#AXScriptAttribute._DoFindAttribute_c CsF|jj ¡D]*}z| ||¡WSty4Yq 0q t|jj|ƒSr )r#r1r5r6r+ÚgetattrÚglobalNameSpaceModule)rr-r8rrrr,Xs  z!AXScriptAttribute._FindAttribute_N) rrr Ú__doc__r'r/r0r6r,rrrrr!:s  r!c@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) ÚNamedScriptAttributez3An explicitely named object in an objects namespacecCs||jd<dS©NÚ _scriptItem_r$)rZ scriptItemrrrr'mszNamedScriptAttribute.__init__cCsdt|jƒdS)Nz)Úreprr>rrrrÚ__repr__pszNamedScriptAttribute.__repr__cCsNz|jj| ¡jWSty@|jjrr1r2r3r4ÚdispatchContainerr9r+)rr-rrrr/ss  z NamedScriptAttribute.__getattr__cCsB| ¡}|jjr6zt|jj||ƒWSty4Yn0t|ƒ‚dSr )r2r>rBÚsetattrr+)rr-ÚvaluerrrÚ __setattr__}s z NamedScriptAttribute.__setattr__cCsd|jd<dSr=r$rrrrr0ˆszNamedScriptAttribute._Close_N) rrr r;r'rAr/rEr0rrrrr<fs   r<c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú ScriptItemcCs$tj |||||¡i|_d|_dSr )rrFr'Ú scriptletsr3)rZ parentItemÚnameÚdispatchÚflagsrrrr'�szScriptItem.__init__cCs&tj |¡|jr|j ¡d|_dSr )rrFÚResetr3r0rrrrrK’s  zScriptItem.ResetcCstj |¡d|_i|_dSr )rrFÚCloserBrGrrrrrL˜s zScriptItem.ClosecCsÌtj |¡t|ƒ|_|jrÈzL| ¡}d}}|j ¡}| ¡d}z|j |}Wnt ydYn0Wnt j y€d}Yn0|dur°t jj |j|d¡}|dur°||j |<t jj |j||j¡|_dS©Nr)rrFÚRegisterr<r3rIZ GetEngineZ GetTypeInfoZ GetTypeAttrÚmapKnownCOMTypesr4Ú pythoncomZ com_errorÚwin32comZclientZdynamicZ MakeOleReprZ CDispatchrHrB)rr&ZolereprZclsidZtypeinforrrrN�s.       ÿ  ÿzScriptItem.RegisterN)rrr r'rKrLrNrrrrrFŒsrFc@s¸eZdZdZdZejejgZdZ e Z dZ ddgZ dZdd „Zd d „Zd d „Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(S))ÚPyScriptzPython.AXScript.2ÚPythonzPython ActiveX Scripting Enginez*win32com.axscript.client.pyscript.PyScript)ú.pys)ÚpysFileZbothcCs"tj |¡d|_g|_d|_dSr )rÚ COMScriptr'r:Ú codeBlocksÚscriptDispatchrrrrr'Ís zPyScript.__init__cCsRtj |¡ddl}d|_| d¡|_t|ƒ|jjd<g|_ g|_ i|_ d|_ dS)NrZ __ax_main__Úax) rrVÚInitNewÚimprXZ new_moduler:r!r%rWZpersistedCodeBlocksrOÚcodeBlockCounter)rr[rrrrZÓs  zPyScript.InitNewcCs|jD] }d|_qtj |¡S©Nr()rWÚ beenExecutedrrVÚStop)rÚbrrrr_às z PyScript.StopcCsF|jdd…}g|_|D] }|jt@rd|_|j |¡qtj |¡SrM)rWrJrr^ÚappendrrVrK)rZ oldCodeBlocksr`rrrrKæs zPyScript.ResetcCs|jd|_|jSr])r\rrrrÚ_GetNextCodeBlockNumberðs z PyScript._GetNextCodeBlockNumbercCsŽ|j}tj ||¡|sŠ| ¡r0|j|jj|j<|  ¡rŠ|j   ¡D]}|j|jj|j<qB|j j j ¡D]"\}}|jsft|j |ƒ|jj|<qfdSr )Z isRegisteredrrVÚRegisterNamedItemZ IsVisibler3r:r%rHZIsGlobalr1r5rBZ _olerepr_ZmapFuncsÚitemsZhiddenr9)rr8ZwasRegZsubitemrHÚentryrrrrcôs þÿÿzPyScript.RegisterNamedItemcCs>z6|jj}|jD]"}|js| |d¡r| ||¡qWn0dS)NÚexec)r:r%rWr^ÚCompileInScriptedSectionÚExecInScriptedSection)rÚglobsÚ codeBlockrrrÚDoExecutePendingScripts s  z PyScript.DoExecutePendingScriptscCsdSr rrrrrÚDoRunszPyScript.DoRuncCs*| ¡d|_g|_d|_tj |¡dSr )ÚResetNamespacer:rWrXrrVrLrrrrrLs zPyScript.ClosecCs |jdurt ||j¡|_|jSr )rXrZMakeScriptDispatchr:)rrHrrrÚGetScriptDispatchs  ÿzPyScript.GetScriptDispatchcCs4|d ¡|dd…d|d ¡|dd…S)Nrr(r))Úupper)rÚ subItemNameÚ eventNamerrrÚMakeEventMethodName&s  ÿþ ý üÿzPyScript.MakeEventMethodNamec Cs`| |¡} ||kr| } n|  | |dd¡} | ||¡} td| |||dƒ} | | ¡| | j| <dS)NzScript Event %sr)Z GetNamedItemZGetCreateSubItemrrrÚ_AddScriptCodeBlockrG) rZ defaultNameÚcodeZitemNamerprqZ delimiterÚsourceContextCookieÚstartLineNumberr8ZsubItemÚfuncNamerjrrrÚDoAddScriptlet/s ÿ ÿ zPyScript.DoAddScriptletcCs`| |j|j¡}d}}z&|j|}t|ƒt|ƒkr<|}d}WntyPYn0|durÌd|} t |j¡ d¡D]} | d| d} qt| d} |  |d| ¡s¤dSi} |  ||j j | ¡| |}||j|<|du�rs2    ,&5b