isfUdZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl Z ddlZddlZddlZddlZddlmZdZiad ed <iZd ed <eed oeejdxZZiZded<ddlZdZdZdZ dZ!ej"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dedfdZ,dedfdZ-dedfdZ.d Z/de edfd!Z0 d.d"Z1de fd#Z2d$Z3d%Z4d.d&Z5d'Z6ed(Z7e8d)krddl9Z9 e9j9ej:ddd*\Z;Ze?e>e7YdZ>[>ndZ>[>wwxYwe@ej:dkse  s ..ctrtdtjzt t jtdd} tj |}| t| t|dS#|wxYw)Nz.Trying to write to a readonly gencache ('%s')! dicts.datwb) is_readonly RuntimeErrorwin32com __gen_path__openospathjoinGetGeneratePathpicklePicklerdump pickleVersionr close)fps r _SaveDictsr*Os  W\\("7EE   * * #CMMA$5$7$78JJ F ??:..DD    FF    FF  JJt   h3[AA4 H H  Q  &&((  """   s%<B B, B,+B,>AE))E?c#6Ktjdd|}tj|5tj|tj dVtj|n#tj|wxYw ddddS#1swxYwYdS)zGiven the output of GetGeneratedFilename, acquire a named mutex for that module This is required so that writes (generation) don't interfere with each other and with reads (import) NF) win32event CreateMutex contextlibclosingWaitForSingleObjectINFINITE ReleaseMutex) module_namemutexs r ModuleMutexrFs  "4 < BA-C21C2cHtj|}t|S)zGet a Python class for a Program ID Given a Program ID, return a Python class which wraps the COM object Returns the Python class, or None if no module is available. Params progid -- A COM ProgramID or IID (eg, "Word.Application") ) pywintypesIIDGetClassForCLSID)progidrLs rGetClassForProgIDras! N6 " "E E " ""rct|}tj|rtj|St |}|dS tj|S#t $rYdSwxYw)zGet a Python class for a CLSID Given a CLSID, return a Python class which wraps the COM object Returns the Python class, or None if no module is available. Params clsid -- A COM CLSID (or string repr of one) N)rJr HasClassGetClassGetModuleForCLSIDKeyError)rLmods rr_r_s JJEU##,$U+++ E " "C {t$U+++ tts A A.-A.cx tj|}n#tj$rYdSwxYwt|S)aGet a Python module for a Program ID Given a Program ID, return a Python module which contains the class which wraps the COM object. Returns the Python module, or None if no module is available. Params progid -- A COM ProgramID or IID (eg, "Word.Application") N)r]r^ com_errorre)r`iids rGetModuleForProgIDrksKnV$$  tt S ! !!s **ct|} t|\}}}}n#t$rYdSwxYw t||||}n#t$rd}YnwxYw||j|}||j|}||jdz|z} t|j dd5t|dddn #1swxYwYnH#t$r;||||f} | tvr t| } ddl m} | || YnwxYwt j|}|S)a Get a Python module for a CLSID Given a CLSID, return a Python module which contains the class which wraps the COM object. Returns the Python module, or None if no module is available. Params progid -- A COM CLSID (ie, not the description) N.rHrmakepy)rJr rfGetModuleForTypelib ImportErrorCLSIDToPackageMapgetVTablesToPackageMap__name__rFrT __import__rroGenerateChildFromTypeLibSpecsysmodules) rL clsid_str typelibCLSIDrMrNrOrgsub_mod sub_mod_nameinforos rreresE I+9)+D( dE55 tt!,eUCC  '++I66 ?-11)< t|| d| d| d} n#t$r | d}YnwxYwn#tj$rYnwxYwYnwxYw| |rt r Jd tj||||} | ddkr | dd} ttj d d} | sG | tj } n#t$rt| } YnwxYwtj||||} n#tj$rd}YnwxYw| |rt r Jdd t#t%||||}|d z}|d z} |d z }ddlm}| j| dks|j| jkr tj|n#t0$rYnwxYw tj|n#t0$rYnwxYwtj |rddl}||| d}d} d}n| j}d t#t%||||}|d z}|dz}d} tj|d}d}nL#t0$r?} tj|d}d}n#t0$r }Yd}~nd}~wwxYwYd}~nd}~wwxYwtj| d}|r ||krd}d} n#tt0f$rd} YnwxYw| t rt||||f} t:|S#t<$rYnwxYwg}t?D]M}|d|dkr9|d|dkr'|d|dkr| |N|r5|!|dd}t||||}nd}|t:|<|StE|||||||} |r!tG| } tI||||| S)aEnsure Python support is loaded for a type library, generating if necessary. Given the IID, LCID and version information for a type library, check and if necessary (re)generate, then import the necessary support files. If we regenerate the file, there is no way to totally snuff out all instances of the old module in Python, and thus we will regenerate the file more than necessary, unless makepy/genpy is modified accordingly. Returns the Python module. No exceptions are caught during the generate process. Params typelibCLSID -- IID of the type library. major -- Integer major version. minor -- Integer minor version lcid -- Integer LCID for the library. progressInstance -- Instance to use as progress indicator, or None to use the GUI progress bar. bValidateFile -- Whether or not to perform cache validation or not bForDemand -- Should a complete generation happen now, or on demand? bBuildHidden -- Should hidden members/attributes etc be generated? rNrrRrz&Can't validate in a read-only gencacherHsupports_unicode_filenamesz{}\{}.pyTco)genpyz.pyc)rr)%rprq pythoncomLoadRegTypeLibrrirQueryPathOfRegTypeLibgetattrrr encoderygetfilesystemencodingr2rJrr"rPrwr MinorVersionmakepy_versionunlinkrisdirshutilrmtreerZr rfGetGeneratedInfosappendsortrrr)r|rMrNrOr bValidateFilerr bReloadNeededmoduletlbAttr typLibPathsuf tlbAttributesfilePathPrefixfilePath filePathPycrr fModTimeSet pyModTimee typLibModTimerrdesc new_minorrets r EnsureModulers/>Mw (tUEJJFF    F #2 %*,, 1:%%u)<)<+!4('!*gaj'!*""'+++!( + &    / 4  - " L L$L L L? "&< % b>T))!+CRCJbg'CQGG55%/%6%6s7P7R7R%S%S )555%(__ 5 ) 8 %!!*,, & " " "!"  "  - " L L$L L L?%__!!$\4FFN&-H(50K #s"     #}Q'777'6+@@@Ih''''DIk****D7==002!MMMMM.111%a( ! +!)#%%(tUEJJ""*E1,v5    " 1 1! 4I"#KK$&GK$8$8$; &' " !# 3 3A 6 "MI$=$=$%M!F  ! ~  l##T5%7C )#..    E)++ ' 'q6T!W$$Q47):):s1va?P?PLL&&&  !"IaL ),eYOO&) s #J%     !%     ?F^^F \4 > > > MsaN B=AB%'$B  B% B!B% B!!B%$B=%B74B=6B77B=:N<B==NA F!&EFE$!F#E$$,FNF%"N$F%%BN)H>=N> I N I  NI$#N$ I1.N0I11B N?LN M%'MM  MM MM N M%%)NN%$N% O O O cDtj|}t|ds |j}|d}|\}}|}t|d|d|d|d|}t|ddl m } | j t|} | |j}n"#tj$rt#dwxYw|S) zYGiven a COM prog_id, return an object that is using makepy support, building if necessaryCLSIDrrrrR)rrz`This COM object can not automate the makepy process - please run makepy manually for this object)rclientDispatchhasattr_oleobj_ GetTypeInfo GetTypeAttrGetContainingTypeLibrrrerwr rdrJrri TypeError) prog_idrdispti disp_clsidtlbindexrrgr disp_classs rEnsureDispatchrs( ? # #G , ,D 4 ! ! **,,B))!,J0022JC..""Cs1vs1vs1vs1v*UUUC j ) ) ) & & & & & &..s:??J:dm,,DD"   r   Ks C C>>Dc^ t||||}t|}d|_t||||f d fd}||j||j||j||j tvrt =|r rtdSdSdS)z3Add a newly generated file to the cache dictionary.rFcf|D],}t|kr t|<d-dS)NT)r rs)dictrL dict_modifiedrs rSetTypelibForAllClsidsz0AddModuleToCache..SetTypelibForAllClsidssE % %E!!%((D00(,u% $  % %rN) rPrrrJCLSIDToClassMaprrVTablesToClassMaprtr r*) typelibclsidrMrNrOverbose bFlushNowrUrgrrrs @@rrrs !tUE B BE U  CC |  dE5 0DM%%%%%%3.///301113011132333 !!! t $] rctjd}|dkrddl}tjd|dz}tj|dzddd}||}t }|D]}||s|t|dzd dd} | d\}} } } t| } t| } t| } tj d |zd z}n #t$rYtj$rYwxYw||| | | f|t%|St'jtjd z} g} | D]2}t(j|s*t(j|dd ksLt(jt(j |dd} | d\}} } } tj d |zd z}t| } t| } t| } n"#t$rYtj$rYwxYw| || | | f4| S) Nz.zip\rrR\/rrI{}z\*r)rrfindzipfilereplaceZipFilesetnamelistr/r0rTintr]r^ ValueErrorriaddr'listglobrr rsplitextr)zip_posrzip_filezip_pathzfinfosnbaserjrMrNrOfilesrfilenames rrrs#((22G!||(7Q;7(17??cJJ __X & & 1 1A<<)) S]]Q&(()//44Q7D *.**S//'T5%4yyE E  nS3Y_55   '     IIsD%/ 0 0 0 0  E{{ (/%788 2 2D7==&& rw/?/?/E/Ea/HE/Q/Q7##BGMM$$7$7$:;;A>D *.**S//'T5% nS3Y_554yyE E    '     JJT5%0 1 1 1 1 s20A!E E/E/.E/)A!K  K*K*)K*cd|z}t|5t|dddn #1swxYwYtj|S)zIGiven the name of a module in the gen_py directory, import and return it.zwin32com.gen_py.%sN)rFrvryrz)rUmod_names rrrs#e+H U  8 ;x  s 155c tt}|rt|rt d|D]}|\}}}}|rt dt | t |||||d8#t d|tj dtj dYxYw|rt|rt dtdS)z/Rebuild the cache indexes from the file system.z6Rebuilding cache of generated files for COM support...Checkingrz Could not add module {} - {}: {}rzDone.N) r r6rr0rrPrrryexc_infor*)rrrrjrMrNrOs rrrs$   EH3u::H FGGG  "&T5%  ; *2D9 : : :  S$ugq A A A A  299#,..+S\^^A->      3u:: gLLLLLs -BACctdtjtt}|D]2\}}}}t ||||}t|jd|3dS)NzCache is in directoryz - )rrrrr valuesrp__doc__)dr|rMrNrOrgs r_Dumpr  s !8#8999 N ! ! # #$$A,-11( dE5!,eUCC ////000011rcPd}t|tjddS)Nz Usage: gencache [-q] [-d] [-r] -q - Quiet -d - Dump the cache (typelibrary description and filename). -r - Rebuild the cache dictionary from the existing .py files r)rryexit) usageStrings rusager s*K +HQKKKKKr__main__qrdz-dz-rz-q)r)Dr __future__rr?rrry importlibrtypesrtypingrrr]rwin32com.clientr=rwr rr __annotations__r rr rr-rr#rr&r*rcontextmanagerrFrPrVr"rar_rkrerprrrrrrrrrrr r rugetoptargvoptsargserrormessagerr0roptrrrrrsi.#""""" 8:9999JLKKKKwx6677 << fFHGGGG     ***Z  + + +AAA&&& !!!< # # #."""$)))X6  A A A AH"&2CRS 9 9 9 9H"&2CRS""""J(((8!/ AAAAJ4/0{?>///d!!!.111      zMMM"V]38ABB<77 dd < g   s38}}T eeggGS $;; EGGG $;; GG    $;;G)s!D'' E1E  E