a „oeïã@s&ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlm Z mZddlmZmZmZmZdd„Zddd„Zddd „Zd d „ZGd d „d ƒZGdd„dejƒZdadd„Zdd„ZejZdd„ZGdd„dejƒZ Gdd„dejƒZ!dd„Z"dS)éN)Ú_GetGatewayCountÚ_GetInterfaceCount)Ú LeakTestCaseÚ TestLoaderÚ TestResultÚ TestRunnercCsPz t ¡WntyYn0tƒ}|r6td|ƒtƒ}|rLtd|ƒdS)Nz.Warning - %d com interface objects still alivez,Warning - %d com gateway objects still alive)ÚsysZ exc_clearÚAttributeErrorrÚprintr)Úc©r ú3C:\Program Files\Certbot\pkgs\win32com\test\util.pyÚ CheckCleans   rc Cs¶|rÖt|tƒr|g}d}|D]´}zt |¡}WntjyHYqÖYn0z&tj}t |d|¡}t  |d¡}Wnt yˆYqÖYn0t j   tj¡dtjdtjdfg} t j   |¡| vrd||f}qÖqdSzddlm} Wn t�ytdƒd } Yn(0z | ƒ} Wntj�y,d } Yn0| �sdd |d} |�rR| d |7} t tj| dd ¡‚dt d¡|f} |�r†td|ƒt  | ¡}|�r²tdƒt| ƒtd|ƒ‚dS)NzCLSID\%sZInprocServer32zpythoncomloader%d%d.dllréz8%r is registered against a different Python version (%s))Ú IsUserAnAdminzACan't import win32com.shell - no idea if you are an admin or not?FTzF%r isn't registered, but I'm not an administrator who can register it.z" (registration check failed as %s)éÿÿÿÿz%s "%s" --unattended > nul 2>&1zRegistering enginezRegistration command was:z"Registration of engine '%s' failed)Ú isinstanceÚstrÚ pywintypesZIIDÚ pythoncomÚ com_errorÚwinregÚHKEY_CLASSES_ROOTÚOpenKeyÚ QueryValueÚ WindowsErrorÚosÚpathÚbasenameÚ__file__rÚ version_infoZwin32com.shell.shellrÚ ImportErrorr ÚwinerrorZCO_E_CLASSSTRINGÚwin32apiZGetModuleFileNameÚsystemÚ RuntimeError)ÚfilenameZprogidsÚverboseZwhy_notZprogidZclsidZHKCRZhkZdllZok_filesrZis_adminÚmsgÚcmdÚrcr r r ÚRegisterPythonServer"sd     þþ   ÿÿ   r+c Cs t d¡}|d|}t |¡}t|dƒ ¡ ¡}t |¡Gdd„dtƒ}zT|rb|dt |ƒƒ‚|dur‚||kr‚|d||fƒ‚|sœ|  d¡d krœ|d ƒ‚|WS|�y}zLt d |ƒt d |ƒt d ƒt |ƒt dƒ|  d||f¡WYd}~n d}~00dS)NZ win32com_testz > "%s" 2>&1Úrc@s eZdZdS)z#ExecuteShellCommand..FailedN)Ú__name__Ú __module__Ú __qualname__r r r r ÚFailedrsr0zexit code was zExpected output %r (got %r)z!Traceback (most recent call last)rztraceback in program outputzFailed to exec command '%r'z Failed asz** start of program output **z** end of program output **zExecuting '%s' failed as %s) ÚtempfileZmktemprr$ÚopenÚreadÚstripÚremoveÚ ExceptionrÚfindr Úfail) r)ÚtestcaseÚexpected_outputZ tracebacks_okZ output_namer*Úoutputr0Úwhyr r r ÚExecuteShellCommandfs*      r=c Osdz||i|¤ŽWn>tjyP}z$|j|krÚfuncÚargsÚkwZdetailsr r r ÚassertRaisesCOM_HRESULT†s  $rBc@sDeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)Ú CaptureWritercCsd|_|_| ¡dS©N)Úold_errÚold_outÚclear©Úselfr r r Ú__init__�s zCaptureWriter.__init__cCs(| ¡tj|_tj|_|t_t_dSrD)rGrÚstdoutrFÚstderrrErHr r r Úcapture”szCaptureWriter.capturecCs,|jr|jt_d|_|jr(|jt_d|_dSrD)rFrrKrErLrHr r r Úreleasešs zCaptureWriter.releasecCs g|_dSrD)ÚcapturedrHr r r rG¢szCaptureWriter.clearcCs|j |¡dSrD)rOÚappend)rIr(r r r Úwrite¥szCaptureWriter.writecCs d |j¡S)NÚ)ÚjoinrOrHr r r Ú get_captured¨szCaptureWriter.get_capturedcCstd |j¡ d¡ƒS)NrRÚ )ÚlenrSrOÚsplitrHr r r Úget_num_lines_captured«sz$CaptureWriter.get_num_lines_capturedN) r-r.r/rJrMrNrGrQrTrXr r r r rC�srCc@seZdZdd„Zdd„ZdS)Ú LogHandlercCsg|_tj |¡dSrD)ÚemittedÚloggingÚHandlerrJrHr r r rJ²szLogHandler.__init__cCs|j |¡dSrD)rZrP)rIÚrecordr r r Úemit¶szLogHandler.emitN)r-r.r/rJr^r r r r rY±srYcCsNttddƒ}tdur.t d¡atƒ}t |¡tt_tjd}g|_ |j |fS)NÚloggerÚtestr) ÚgetattrÚwin32comÚ_win32com_loggerr[ZLoggerrYZ addHandlerr_ÚhandlersrZ)Zold_logZhandlerr r r Úsetup_test_logger½s    recCs(|dusJdƒ‚|durt`n|t_dS)Nzwho needs this?)rbr_)Z prev_loggerr r r Úrestore_test_loggerËsrfcOst|i|¤Ž}t|ƒSrD)Ú_CapturingFunctionTestCaser)r@rAZ real_testr r r ÚCapturingFunctionTestCase×srhc@seZdZddd„Zdd„ZdS)rgNcCsŠ|dur| ¡}tƒ}| ¡z:tj ||¡t|ddƒrNttdƒrN|  |¡W|  ¡n |  ¡0|  ¡}|  ||¡|j r†t|ƒdS)NZ do_leak_testsrZgettotalrefcount)ZdefaultTestResultrCrMÚunittestÚFunctionTestCaseÚ__call__raÚhasattrrZrun_leak_testsrNrTÚ checkOutputZshowAllr )rIÚresultÚwriterr;r r r rkÝs  z#_CapturingFunctionTestCase.__call__cCs*| d¡dkr&d|}|j ||f¡dS)NZ Tracebackrz,Test output contained a traceback --- %s ---)r7ÚerrorsrP)rIr;rnr(r r r rmïsz&_CapturingFunctionTestCase.checkOutput)N)r-r.r/rkrmr r r r rgÜs rgc@s$eZdZdd„Zdd„Zdd„ZdS)Ú ShellTestCasecCs||_||_tj |¡dSrD)Ú_ShellTestCase__cmdÚ_ShellTestCase__eoriÚTestCaserJ)rIr)r:r r r rJöszShellTestCase.__init__cCst|j||jƒdSrD)r=rrrsrHr r r ÚrunTestûszShellTestCase.runTestcCs4d}t|jƒ|kr&|jd|…d}n|j}d|S)Néz...zexec: )rVrr)rIÚmaxZcmd_reprr r r Ú__str__þs zShellTestCase.__str__N)r-r.r/rJrurxr r r r rqõsrqcOstj|i|¤ŽtƒdSrD)Úpywin32_testutilÚtestmainr)r@rAr r r rzsrz)Nr)Nr)#Úgcr[rrr1rirrryrr#rbr"rrrrrrrr+r=rBrCr\rYrcrerfrtrhrjrgrqrzr r r r Ús< Gü  "