
    	hs                       % S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJr  Sr0 qS	\S
'   0 rS\S'   \" \S5      =(       a    \" \R2                  S5      =rr0 rS\S'   SSKrS rSrS r S r!\RD                  S 5       r#S r$S r%S r&S r'S r(S r)S r*S r+S\S4S jr,S\S4S jr-S\S4S jr.S  r/S\(       + \S4S! jr0 S.S" jr1S\(       + 4S# jr2S$ r3S% r4S.S& jr5S' r6\" 5         S( r7\8S):X  a  SSK9r9 \9Rr                  " \Rt                  SS S*5      u  r;r<\@" \Rt                  5      S:X  d  \<(       a  \?" \7" 5       5        SrA\; H+  u  rBrC\BS+:X  a  \6" 5         \BS,:X  a  \5" \A5        \BS-:X  d  M)  SrAM-     gg! \9Rz                   a  r>\?" \>5        \7" 5          Sr>C>NSr>C>ff = f)/a\  Manages the cache of generated Python code.

Description
  This file manages the cache of generated Python code.  When run from the
  command line, it also provides a number of options for managing that cache.

Implementation
  Each typelib is generated into a filename of format "{guid}x{lcid}x{major}x{minor}.py"

  An external persistant dictionary maps from all known IIDs in all known type libraries
  to the type library itself.

  Thus, whenever Python code knows the IID of an object, it can find the IID, LCID and version of
  the type library which supports it.  Given this information, it can find the Python module
  with the support.

  If necessary, this support can be generated on the fly.

Hacks, to do, etc
  Currently just uses a pickled dictionary, but should used some sort of indexed file.
  Maybe an OLE2 compound file, or a bsddb file?
    )annotationsN)reload)
ModuleType)Any   CLSIDToClassz$dict[str, tuple[str, int, int, int]]clsidToTypelibz2dict[tuple[str, int, int, int], ModuleType | None]versionRedirectMap
__loader__archivez$dict[tuple[str, int, int, int], Any]demandGeneratedTypeLibrariesc                 N     [        5         g ! [         a    [        5          g f = f)N)
_LoadDictsOSErrorRebuild     kC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\win32com/client/gencache.py__init__r   D   s      	s   
 $$c                    [         (       a  [        S[        R                  -  5      e[	        [
        R                  R                  [        5       S5      S5      n  [        R                  " U 5      nUR                  [        5        UR                  [        5        U R                  5         g ! U R                  5         f = f)Nz.Trying to write to a readonly gencache ('%s')!	dicts.datwb)is_readonlyRuntimeErrorwin32com__gen_path__openospathjoinGetGeneratePathpicklePicklerdumppickleVersionr
   close)fps     r   
_SaveDictsr*   O   s    {<x?T?TT
 	
 	RWW\\/+[94@ANN1	}	~			s   A B, ,B>c                    [         (       a  SS Kn [        R                  nUR                  n[
        R                  R                  [        R                  S5      nUR                  U5      (       a  U[        U5      S-   S  nOg  UR                  U5      nU R                  U5      nO8[        [
        R                  R                  [        R                  S5      S5      n [         R"                  " U5      nUR%                  5       nUR%                  5       q[(        R+                  5         UR-                  5         g ! [         a     g [         a     g f = f! UR-                  5         f = f)Nr   r   r   rb)is_zipior   r   r   r   r    r!   r   
startswithlenget_dataAttributeErrorr   BytesIOr   r#   	Unpicklerloadr
   r   clearr'   )r.   loaderarc_path
dicts_pathdatar(   r)   versions           r   r   r   ]   s   v$$>>WW\\("7"7E
  **#CMA$5$78J 	??:.D" JJt h33[A4HQ&&(  "		7  	 	 	0 	
	s%   D;  A
E ;
E	EEE(c              #  T  #    [         R                  " SSU 5      n[        R                  " U5         [         R                  " U[         R
                  5         Sv   [         R                  " U5         SSS5        g! [         R                  " U5        f = f! , (       d  f       g= f7f)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
contextlibclosingWaitForSingleObjectINFINITEReleaseMutex)module_namemutexs     r   ModuleMutexrF      sw      ""4<E			E	"&&uj.A.AB	+##E* 
#	" ##E* 
#	"s4   /B(&BA<B3	B(<BB
B%!B(c                R    [        U 5      R                  5       SS SU SU SU 3-   $ )ztGiven the clsid, lcid, major and  minor for a type lib, return
the file name (no extension) providing this support.
r   x)strupper)clsidlcidmajorminors       r   GetGeneratedFileNamerP      s6     u:a#$qq&@@@r   c                8    [        U R                  SS5      5      $ )z!Reverse of GetGeneratedFileName()rI      )tuplesplit)fnames    r   SplitGeneratedFileNamerV      s    S!$%%r   c                    [         (       a   S5       e [        R                  " [        R                  5         [        R                  R                  [        R                  S5      n [        R                  " U 5        [        R                  $ ! [
         a     Naf = f! [
         aa    [        W S5      nUR                  S5        UR                  S5        UR                  S5        UR                  5          [        R                  $ f = f)zIReturns the name of the path to generate to.
Checks the directory is OK.
z1Why do you want the genpath for a readonly store?z__init__.pywzK# Generated file - this directory may be deleted to reset the COM cache...
zimport win32com
zRif __path__[:-1] != win32com.__gen_path__: __path__.append(win32com.__gen_path__)
)r   r   makedirsr   r   r   r    r!   statr   writer'   )rU   r(   s     r   r"   r"      s     {OOO?
H))*X22MB
    !  
  		Z	
 	
#$	a	
 	
	   	s$   $B AB 
BBADDc                D    [         R                  " U 5      n[        U5      $ )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")
)
pywintypesIIDGetClassForCLSID)progidrL   s     r   GetClassForProgIDra      s     NN6"EE""r   c                    [        U 5      n [        R                  " U 5      (       a  [        R                  " U 5      $ [	        U 5      nUc  g [        R                  " U 5      $ ! [
         a     gf = f)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)rJ   r	   HasClassGetClassGetModuleForCLSIDKeyError)rL   mods     r   r_   r_      si     JEU##$$U++
E
"C
{$$U++ s   A# #
A0/A0c                z     [         R                  " U 5      n[        U5      $ ! [         R                   a     gf = f)a  Get 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     r   GetModuleForProgIDrk      s<    nnV$ S!!  s   # ::c                r   [        U 5      n [        U   u  p#pE [        X#XE5      nUb  UR
                  R                  U5      nUc  UR                  R                  U5      nUba  UR                  S-   U-   n [        UR                  R                  S5      S   5         [        U5        SSS5        [         R"                  U   nU$ ! [         a     gf = f! [         a    Sn Nf = f! , (       d  f       NE= f! [         a1    X#XE4n	U	[        ;   a	  [        U	   n	SSKJn
  U
R                  Xy5         Nf = f)zGet 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.rH   r   makepy)rJ   r
   rf   GetModuleForTypelibImportErrorCLSIDToPackageMapgetVTablesToPackageMap__name__rF   rT   
__import__r    ro   GenerateChildFromTypeLibSpecsysmodules)rL   	clsid_strtypelibCLSIDrM   rN   rO   rg   sub_modsub_mod_nameinforo   s              r   re   re      s9    E
I+9)+D(E!,eC ''++I6?--11)<G<<#-7LC !3!3C!8!<=|, > ++l+CJ7  
   >= C#57 777=D$33GBCsR   C C 8'C; C*+C; 
CCC'&C'*
C84C; 8C; ;8D65D6c                    [        XX#5      n[        U5      nSUR                  ;  a  [        XX#5        SUR                  ;   d   eU$ )a  Get a Python module for a type library ID

Given the CLSID of a typelibrary, return an imported Python module,
else None

Params
typelibCLSID -- IID of the type library.
major -- Integer major version.
minor -- Integer minor version
lcid -- Integer LCID for the library.
_in_gencache_)rP   
_GetModule__dict__AddModuleToCache)r|   rM   rN   rO   modNamerg   s         r   rp   rp   '  sI     #<uDG
W
C cll*U:#,,...Jr   c                N    SSK Jn  UR                  XX#4UUUS9  [        XX#5      $ )a  Generate support for a type library.

Given the IID, LCID and version information for a type library, generate
and import the necessary support files.

Returns the Python module.  No exceptions are caught.

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.
r   rn   progressInstance
bForDemandbBuildHidden)rw   ro   GenerateFromTypeLibSpecrp   )r|   rM   rN   rO   r   r   r   ro   s           r   MakeModuleForTypelibr   =  s:    0 
""	U*)!	 #  |5@@r   c                    SSK Jn   UR                  U U[        US9  U R                  5       nUS   nUS   nUS   nUS   n	[        XgX5      $ ! [        R
                   a     gf = f)a  Generate support for a type library.

Given a PyITypeLib interface generate and import the necessary support files.  This is useful
for getting makepy support for a typelibrary that is not registered - the caller can locate
and load the type library itself, rather than relying on COM to find it.

Returns the Python module.

Params
typelib_ob -- The type library itself
progressInstance -- Instance to use as progress indicator, or None to
                    use the GUI progress bar.
r   rn   r   Nr      rR   )rw   ro   r   bForDemandDefaultr]   ri   
GetLibAttrrp   )

typelib_obr   r   r   ro   tlaguidrM   rN   rO   s
             r   MakeModuleForTypelibInterfacer   `  s      &&-(%	 	' 	
 


!Cq6Dq6DFEFEt588  s   A A%$A%c                    U R                  5       nUS   nUS   nUS   nUS   nU(       a  U [        [        U5      XgU4'    [        XVXx5      $ ! [         a     Of = f[        XX#5      $ )a  Check we have support for a type library, generating if not.

Given a PyITypeLib interface generate and import the necessary
support files if necessary. This is useful for getting makepy support
for a typelibrary that is not registered - the caller can locate and
load the type library itself, rather than relying on COM to find it.

Returns the Python module.

Params
typelib_ob -- The type library itself
progressInstance -- Instance to use as progress indicator, or None to
                    use the GUI progress bar.
r   r   r   rR   )r   r   rJ   rp   rq   r   )	r   r   r   r   r   r   rM   rN   rO   s	            r   EnsureModuleForTypelibInterfacer     s    " 


!Cq6Dq6DFEFE HR$c$ie%DE"4u<<  )j s   A 
AAc                "   U R                  5       nUS   nUS   nUS   nUS   n[        U5      X4U4n [        U	 [        R                  5        H  u  pxX:X  d  M  [        U	 M     g! [         a    [	        SR                  U5      5         NRf = f)zdDrop any references to a typelib previously added with EnsureModuleForTypelibInterface and forDemandr   r   r   rR   zZForgetAboutTypelibInterface:: Warning - type library with info {} is not being remembered!N)r   rJ   r   rf   printformatr   items)	r   r   r   rM   rN   rO   r   keyvals	            r   ForgetAboutTypelibInterfacer     s    



!Cq6Dq6DFEFEt9d5(D
(. ',,.;"3' /  
hoo	

s   A' '$BBc           
      	   Sn  [        XX#5      n	U	b  U(       a  [        (       a   S5       e [        R                  " XX15      nUS   S:X  a  USS n[        [        R                  S	S5      nU(       d%   UR                  [        R                  " 5       5      n[        R                  " XX15      R	                  5       nU	Gbt  U(       Gal  [        (       a   S5       eS
R!                  [#        5       [%        XX#5      5      nUS-   nUS-   n US-  nSSKJn  U	R*                  WS   :w  d  UR,                  U	R,                  :w  aq   [        R.                  " U5         [        R.                  " U5        [        R                  R3                  U5      (       a  SSKnUR7                  U5        US   nSn	SnOU	R*                  nS
R!                  [#        5       [%        XX#5      5      nUS-   nUS-   nSn [        R8                  " U5      S   nSn[        R8                  " W5      S   nU(       a
  UW:  a  SnSn	U	cP  [        (       a  [        U 5      XU4n [:        U   $ [E        U UUUUUUS9n	U(       a  [G        U	5      n	[I        XX#5        U	$ ! [         a    Sn	 [        R                  " XX15      R	                  5       n
U
S   U:w  d	  U
S   U:w  a1   [        X
S   U
S   U
S   5      n	 GN! [         a
    U
S   n  GNf = f GN! [        R
                   a      GNf = ff = f! [         a    [        U5      n GNf = f! [        R
                   a    Sn GNf = f! [0         a     GNf = f! [0         a     GN	f = f! [0         aC  n [        R8                  " U5      S   nSn SnAGN! [0         a  n SnA SnAGNSnAff = fSnAff = f! [        [0        4 a    Sn	 GNf = f! [<         a     Of = f/ n[?        5        H>  nUS   US   :X  d  M  US   US   :X  d  M  US   US   :X  d  M-  URA                  U5        M@     U(       a&  URC                  5         US   S   n[        XUU5      nOSnU[:        U'   U$ )a  Ensure 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?
r   Nr   rR   r   z&Can't validate in a read-only gencacherH    supports_unicode_filenamesz{}\{}.pyc)genpyz.pyc      )r   r   )%rp   rq   	pythoncomLoadRegTypeLibr   ri   r   QueryPathOfRegTypeLibgetattrr   r    encodery   getfilesystemencodingr2   rJ   r   r"   rP   rw   r   MinorVersionmakepy_versionunlinkr   isdirshutilrmtreerZ   r   rf   GetGeneratedInfosappendsortr   r   r   )r|   rM   rN   rO   r   bValidateFiler   r   bReloadNeededmoduletlbAttr
typLibPathsuftlbAttributesfilePathPrefixfilePathfilePathPycr   r   fModTimeSet	pyModTimeetypLibModTimer   r   desc	new_minorrets                               r   EnsureModuler     s   > Mw	(UJF6 -"{L$LL?"&<< 

 b>T)!+CRJbgg'CQG5%/%6%6s7P7P7R%S
 !* 8 8 !*,  -"{L$LL?%__!$\FN &-H(50Ks"
   ##}Q'77''6+@+@@IIh'IIk* 77==00!MM.1%a( !++!)#%(UJ" *E1,v5
 " 1! 4I"#K !#
 3A 6MI$=$%M!F ~ ;l#T%7C)#..( &!%
 F^F\>M}  	
 F#22 *, 
 1:%u)<+!4(!*gaj'!*" ' + !(
+ *= && /	R * 5%(_
5
 && " !"	":    ,  $&GGK$8$;	&'"  !    E)+q6T!W$Q47):s1va?PLL& ,  

!"IaL	),eYO&)s#Jsb  J O AM  6$L$ %M  ?BO M M. 2AO 5<O 2M? *O O( L!7LK*'O *K>9L:O =K>>LO LL!O LL!!O $L=9M  <L==M   MO MO 
M+'O *M++O .
M<8O ;M<<O ?
O
N+%O +
O5O9O ?OOOO O%$O%(
O54O5c                   [         R                  R                  U 5      n[        US5      (       d   UR                  R                  5       nUR                  5       S   nUR                  5       u  pVUR                  5       n[        US   US   US   US   US9n[        U5        SSKJn	  U	R                  " [        U5      5      n
U
" UR                  5      nU$ U$ ! [        R                    a    [#        S5      ef = f)	zYGiven a COM prog_id, return an object that is using makepy support, building if necessaryCLSIDr   r   r   rR   )r   r   z`This COM object can not automate the makepy process - please run makepy manually for this object)r   clientDispatchhasattr_oleobj_GetTypeInfoGetTypeAttrGetContainingTypeLibr   r   re   rw   r	   rd   rJ   r   ri   	TypeError)prog_idr   dispti
disp_clsidtlbindexr   rg   r	   
disp_classs              r   EnsureDispatchr     s     ??##G,D4!!	**,B)!,J002JC.."Cs1vs1vs1vs1v*UCj)&%..s:?Jdmm,D
 K4K	 "" 	r 	s   B&C  C<c                X  ^	^
 [        XX#5      n[        U5      nSUl        [        U 5      XU4m
Sm	U	U
4S jnU" UR                  5        U" UR
                  5        U" UR                  5        U" UR                  5        T
[        ;   a  [        T
	 U(       a  T	(       a  [        5         ggg)z3Add a newly generated file to the cache dictionary.r   Fc                d   > U  H)  n[         R                  U5      T:w  d  M  T[         U'   SmM+     g )NT)r
   rs   )dictrL   dict_modifiedr   s     r   SetTypelibForAllClsids0AddModuleToCache.<locals>.SetTypelibForAllClsids  s/    E!!%(D0(,u% $ r   N)
rP   r   r   rJ   CLSIDToClassMaprr   VTablesToClassMaprt   r   r*   )typelibclsidrM   rN   rO   verbose	bFlushNowrU   rg   r   r   r   s            @@r   r   r     s     !UBE
U
C C|d50DM% 3../300130013223 !!t$] #yr   c                    [         R                  R                  S5      n U S:  Ga-  SS Kn[         R                  S U S-    n[         R                  U S-   S  R	                  SS5      nUR                  U5      n[        5       nUR                  5        H  nUR                  U5      (       d  M  U[        U5      S-   S  R                  S5      S   n UR                  S5      u  pp[        U	5      n	[        U
5      n
[        U5      n[        R                  " S	U-   S
-   5      nUR!                  XX45        M     UR#                  5         [%        U5      $ [&        R&                  " [         R                  S-   5      n/ nU H  n[(        R*                  R-                  U5      (       d(  [(        R*                  R/                  U5      S   S:X  d  MO  [(        R*                  R/                  [(        R*                  R                  U5      S   5      S   n UR                  S5      u  pp[        R                  " S	U-   S
-   5      n[        U	5      n	[        U
5      n
[        U5      nUR1                  XX45        M     U$ ! [         a     GM  [        R                   a     GM  f = f! [         a     GM3  [        R                   a     GMJ  f = f)Nz.zip\r   rR      \/r   rI   {}z\*r   )r   r   findzipfilereplaceZipFilesetnamelistr/   r0   rT   intr]   r^   
ValueErrorri   addr'   listglobr   r    r   splitextr   )zip_posr   zip_filezip_pathzfinfosnbaserj   rM   rN   rO   filesr   filenames                   r   r   r     sY   ##((2G!|((7Q;7((17??cJ__X&A<<))S]Q&()//4Q7D
*.**S/'54yE
E
 nnS3Y_5 IIs%/0   	
E{ 		(//%78D77==&&rww/?/?/Ea/HE/Q77##BGGMM$$7$:;A>D
*.**S/'5 nnS3Y_54yE
E
 JJ501   
9  '' (  '' s2   AI;AJ$;
J!	J! J!$
K
2K
	K
c                    SU -  n[        U 5         [        U5        SSS5        [        R                  U   $ ! , (       d  f       N!= f)zIGiven the name of a module in the gen_py directory, import and return it.zwin32com.gen_py.%sN)rF   rv   ry   rz   )rU   mod_names     r   r   r     s9    #e+H	U	8 
;;x   
	s	   8
Ac           
        [         R                  5         [        5       nU (       a  [        U5      (       a  [	        S5        U H0  nUu  p4pVU (       a  [	        S[        U6 5         [        X4XVU S5        M2     U (       a  [        U5      (       a  [	        S5        [        5         g!   [	        SR                  U[        R                  " 5       S   [        R                  " 5       S   5      5         M  = f)z/Rebuild the cache indexes from the file system.z6Rebuilding cache of generated files for COM support...Checkingr   z Could not add module {} - {}: {}r   zDone.N)r
   r6   r   r0   r   rP   r   r   ry   exc_infor*   )r   r   r   rj   rM   rN   rO   s          r   r   r     s    E3u::FG"&5*2D9:	SgqA  3u::gL	299#,,.+S\\^A->s   %B$$A
C1c                     [        S[        R                  5        [        [        R                  5       5      n U  H,  u  pp4[        XX45      n[        UR                   SU 35        M.     g )NzCache is in directoryz - )r   r   r   r   r
   valuesrp   __doc__)dr|   rM   rN   rO   rg   s         r   _Dumpr	    sX    	
!8#8#89N!!#$A,-(E!,eCS/0 -.r   c                 J    Sn [        U 5        [        R                  " S5        g )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   )r   ry   exit)usageStrings    r   usager    s    K 
+HHQKr   __main__qrdz-dz-rz-q)r   )Dr  
__future__r   r?   r   r   ry   	importlibr   typesr   typingr   r   r]   r   win32com.clientr=   rw   r	   r   r
   __annotations__r   r   r   r   r-   r   r#   r   r&   r*   r   contextmanagerrF   rP   rV   r"   ra   r_   rk   re   rp   r   r   r   r   r   r   r   r   r   r   r	  r  ru   getoptargvoptsargserrormessager   r0   r   optr   r   r   r   <module>r     s,  . #   	 
           8:4 9 JL F K x6 7< f FH B G  *Z + +A&
!<#."$)X6   AH "&2CRS 9H "&2CRS"J(8 !/ AJ 4 /0{?>/d!.1 	
	 z]]388AB<7
d 388}TegGS$;G$;G$;G  
 << gs   #F G+F??G