
    %
is                    f   U d Z ddlmZ ddl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mZ ddlZddlZddlZddlZddlZddlmZ dZi ad	ed
<   i Zded<    eed          o eej        d          xZZi Zded<   ddlZd ZdZd Z d Z!ej"        d             Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+dedfdZ,dedfdZ-dedfdZ.d  Z/de edfd!Z0	 d.d"Z1de fd#Z2d$ Z3d% Z4d.d&Z5d' Z6 e             d( Z7e8d)k    rddl9Z9	  e9j9        ej:        dd         d*          \  Z;Z<n,# e9j=        $ rZ> e?e>            e7             Y dZ>[>ndZ>[>ww xY w e@ej:                  dk    se<r e? e7                       dZAe;D ]0\  ZBZCeBd+k    r
 e6             eBd,k    r e5eA           eBd-k    rdZA/dS dS )/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                 b    	 t                       d S # t          $ r t                       Y d S w xY w)N)
_LoadDictsOSErrorRebuild     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\win32com/client/gencache.py__init__r   D   s>       						s    ..c                    t           rt          dt          j        z            t	          t
          j                            t                      d          d          } 	 t          j
        |           }|                    t                     |                    t                     |                                  d S # |                                  w xY w)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
 
 	
 	RW\\/++[994@@AN1	}	~										s   AB= =Cc                    t           rdd l} t          j        }|j        }t
          j                            t          j        d          }|	                    |          r|t          |          dz   d          }nd S 	 |                    |          }n# t          $ r Y d S t          $ r Y d S w xY w|                     |          }n8t          t
          j                            t          j        d          d          }	 t!          j        |          }|                                }|                                at(                                           |                                 d S # |                                 w xY w)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   ]   sg     I			$>W\\("7EE
  ** 	#CMMA$5$7$78JJ F	??:..DD 	 	 	FF 	 	 	 FF	 JJt h3[AA4HHQ&&((  """										s%   <B 
B,	B,+B,>AE) )E?c              #  6  K   t          j        dd|           }t          j        |          5  t          j        |t           j                   	 dV  t          j        |           n# t          j        |           w xY w	 ddd           dS # 1 swxY w Y   dS )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      s       "4<<E		E	"	" + +&uj.ABBB	+EEE#E****J#E*****+ + + + + + + + + + + + + + + + + +s)    BA'B'A==BBBc                l    t          |                                           dd         d| d| d| z   S )z|Given 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      sC     u::ad#&@$&@&@&@&@&@&@@@r   c                H    t          |                     dd                    S )z!Reverse of GetGeneratedFileName()rI      )tuplesplit)fnames    r   SplitGeneratedFileNamerV      s    S!$$%%%r   c                    t           r
J d            	 t          j        t          j                   n# t
          $ r Y nw xY w	 t          j                            t          j        d          } t          j        |            ns# t
          $ rf t          | d          }|
                    d           |
                    d           |
                    d           |                                 Y nw xY wt          j        S )zQReturns 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OO?
H)****   X2MBB
 	 	 		Z	
 	
 	
 	
#$$$	a	
 	
 	
 	
						   s   2 
??>B A-C21C2c                H    t          j        |           }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")
    )
pywintypesIIDGetClassForCLSID)progidrL   s     r   GetClassForProgIDra      s!     N6""EE"""r   c                    t          |           } t          j        |           rt          j        |           S t	          |           }|dS 	 t          j        |           S # t
          $ r Y dS w xY w)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_      s     JJEU## ,$U+++
E
"
"C
{t$U+++   tts   A   
A.-A.c                x    	 t          j        |           }n# t           j        $ r Y dS w xY wt          |          S )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      sK    nV$$   ttS!!!s    **c                   t          |           }	 t          |         \  }}}}n# t          $ r Y dS w xY w	 t          ||||          }n# t          $ r d}Y nw xY w||j                            |          }||j                            |          }||j        dz   |z   }	 t          |j        
                    d          d                   5  t          |           ddd           n# 1 swxY w Y   nH# t          $ r; ||||f}	|	t          v rt          |	         }	ddlm}
 |
                    ||	           Y nw xY wt           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.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      s    E

I+9)+D(dE55   tt!,eUCC   
'++I66?-11)<<G<#-7LC !3!3C!8!8!<== - -|,,,- - - - - - - - - - - - - - - C C C#T5%7 7777=D$$$$$$33GTBBBBBC +l+CJsT   $ 
22A	 	AA#-C8 C, C8 ,C00C8 3C04C8 8AD=<D=c                    t          | |||          }t          |          }d|j        vrt          | |||           d|j        v sJ |S )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   '  s_     #<ueDDG
W

C cl**tUE:::#,....Jr   c                l    ddl m} |                    | |||f|||           t          | |||          S )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 
""	tUE*)!	 #    |T5%@@@r   c                   ddl m} 	 |                    | |t          |           n# t          j        $ r Y dS w xY w|                                 }|d         }|d         }|d         }|d         }	t          ||||	          S )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      &&-(%	 	' 	
 	
 	
 	
    tt



!
!Cq6Dq6DFEFEtT5%888s   ' ::c                   |                                  }|d         }|d         }|d         }|d         }|r| t          t          |          |||f<   	 t          ||||          S # t          $ r Y nw xY wt          | |||          S )a3  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  SHR$c$iiue%DE"4ue<<<    )$j,  s   A% %
A21A2c                f   |                                  }|d         }|d         }|d         }|d         }t          |          |||f}	 t          |= n2# t          $ r% t	          d                    |                     Y nw xY wt                                          D ]\  }}||k    rt          |= dS )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t99dE5(D
(.. 
 
 
hoo 	
 	
 	
 	
 	

 ',,.. ( (S$;;"3'( (s   	A ,B Bc           	     	   d}	 	 t          | |||          }	n# t          $ r d}		 t          j        | |||                                          }
|
d         |k    s|
d         |k    r>	 t          | |
d         |
d         |
d                   }	n# t          $ r |
d         }Y nw xY wn# t          j        $ r Y nw xY wY nw xY w|	|rt          r
J d            	 t          j        | |||          }|d         dk    r
|dd         }t          t          j
        d	d          }|sG	 |                    t          j                              }n# t          $ r t          |          }Y nw xY wt          j        | |||                                          }n# t          j        $ r d}Y nw xY w|	|rt          r
J d            d
                    t#                      t%          | |||                    }|dz   }|dz   }	 |dz  }ddlm} |	j        |d         k    s|j        |	j        k    r	 t          j        |           n# t0          $ r Y nw xY w	 t          j        |           n# t0          $ r Y nw xY wt          j
                            |          rddl}|                    |           |d         }d}	d}n|	j        }d
                    t#                      t%          | |||                    }|dz   }|dz   }d}	 t          j        |          d         }d}nL# t0          $ r?}	 t          j        |          d         }d}n# t0          $ r
}Y d}~nd}~ww xY wY d}~nd}~ww xY wt          j        |          d         }|r
||k    rd}d}	n# t          t0          f$ r d}	Y nw xY w|	t          rt          |           |||f}	 t:          |         S # t<          $ r Y nw xY wg }t?                      D ]M}|d         |d         k    r9|d         |d         k    r'|d         |d         k    r|                     |           N|r5|!                                 |d         d         }t          | |||          }nd}|t:          |<   |S tE          | ||||||          }	|r!tG          |	          }	tI          | |||           |	S )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{}\{}.pyTco)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	(tUEJJFF 	 	 	
 F#2 % *,, 
 1:%%u)<)<+!4('!*gaj'!*" " ' + + + !(
+
 &   /	4 -"LL$LLL?"&< % 

 b>T))!+CRCJbg'CQGG 55%/%6%6s7P7R7R%S%S

) 5 5 5%(__


5 ) 8 %! !*,,  & " " " !"	"
 -"LL$LLL?%__!!$\4FF N &-H(50K#s"
   #}Q'777'6+@@@Ih''''   DIk****   D7==00 2!MMMMM.111%a( !+!)#%%(tUEJJ" " *E1,v5
 " 1 1! 4I"#KK   $&GK$8$8$;	&'"    !#
 3 3A 6 "MI$=$=$%M!F!   ~  	l##T5%7C)#..    E)++ ' 'q6T!W$$Q47):):s1va?P?PLL&&&  

!"IaL	),eYOO&)s#J%!%
 
 
  	?F^^F\4>>>Msa   N B=AB%'$BB%B!B% B!!B%$B=%B74B=6B77B=:N <B==N A
F !&E F E$!F #E$$,F N F%"N $F%%BN )H> =N >
IN 
IN I$ #N $
I1.N 0I11BN ?L N 
M%'MM 
MM MM N  M%%)N N%$N%O 
O O c                D   t           j                            |           }t          |d          s	 |j                                        }|                                d         }|                                \  }}|                                }t          |d         |d         |d         |d         |          }t          |           ddlm}	  |	j        t          |                    }
 |
|j                  }n"# t          j        $ r t#          d          w xY w|S )	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22JC..""Cs1vs1vs1vs1v*UUUCj)))&&&&&&..s:??J:dm,,DD" 	 	 	r  	 Ks   CC> >Dc                ^  	
 t          | |||          }t          |          }d|_        t          |           |||f
d		
fd} ||j                    ||j                    ||j                    ||j                   
t          v rt          
= |r	rt                       dS dS dS )z3Add a newly generated file to the cache dictionary.r   Fc                f    | D ],}t                               |          k    rt           |<   d-d S )NT)r
   rs   )dictrL   dict_modifiedr   s     r   SetTypelibForAllClsidsz0AddModuleToCache.<locals>.SetTypelibForAllClsids  sE     	% 	%E!!%((D0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    !tUEBBE
U

C C|dE50DM% % % % % % 3.///301113011132333 !!!t$ ]    r   c                    t           j                            d          } | dk    rdd l}t           j        d | dz            }t           j        | dz   d                              dd          }|                    |          }t                      }|                                D ]}|                    |          s|t          |          dz   d          
                    d          d         }	 |
                    d          \  }}	}
}t          |	          }	t          |
          }
t          |          }t          j        d	|z   d
z             }n # t          $ r Y t          j        $ r Y w xY w|                    ||	|
|f           |                                 t%          |          S t'          j        t           j        dz             }g }|D ]2}t(          j                            |          s*t(          j                            |          d         dk    sLt(          j                            t(          j        
                    |          d                   d         }	 |
                    d          \  }}	}
}t          j        d	|z   d
z             }t          |	          }	t          |
          }
t          |          }n"# t          $ r Y t          j        $ r Y w xY w|                    ||	|
|f           4|S )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     s   #((22G!||(7Q;7(17??cJJ__X&& 	1 	1A<<)) S]]Q&(()//44Q7D
*.**S//'T5%4yyE

E

 nS3Y_55   '    IIsD%/0000



E{{ 	(/%788 	2 	2D7==&& rw/?/?/E/Ea/HE/Q/Q7##BGMM$$7$7$:;;A>D
*.**S//'T5% nS3Y_554yyE

E

   '    JJT5%01111
s2   0A!E
E/E/.E/)A!K
K*K*)K*c                    d| z  }t          |           5  t          |           ddd           n# 1 swxY w Y   t          j        |         S )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     s    #e+H	U		  8              ;x  s   155c           
        t                                            t                      }| rt          |          rt	          d           |D ]}|\  }}}}| rt	          dt          |            	 t          ||||| d           8#  t	          d                    |t          j	                    d         t          j	                    d                              Y xY w| rt          |          rt	          d           t                       dS )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 H3u:: HFGGG  "&T5% 	;*2D9:::	S$ugqAAAA	299#,..+S\^^A->     
  3u:: gLLLLLs   -BACc                     t          dt          j                   t          t                                                    } | D ]2\  }}}}t          ||||          }t          |j         d|            3d S )NzCache is in directoryz - )r   r   r   r   r
   valuesrp   __doc__)dr|   rM   rN   rO   rg   s         r   _Dumpr	    s    	
!8#8999N!!##$$A,- 1 1(dE5!,eUCC////00001 1r   c                 P    d} t          |            t          j        d           d S )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 
+HQKKKKKr   __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     si    . # " " " " "      				 



                                           8: 9 9 9 9 JL  K K K K wx66 77< < f FH  G G G G      * * *Z + + +A A A& & &
! ! !<# # #  ." " "$) ) )X  6   A  A  A  AH "&2CRS 9  9  9  9H "&2CRS" " " "J( ( (8 !/ A A A AJ    4 /0{?   >/ / /d! ! !   .1 1 1 	


	 	 	 zMMM"V]38ABB<77
dd<   g
 s38}}TeeggG  S$;;EGGG$;;GG$;;G)  s   !D' '
E1EE