a „oeÛfã@s<ddlZddlZddlZddlmZmZejejZddddej dfdd„Z d,dd„Z ej fdd „Z ej fd d „Zddddej fd d „Zd-dd„ZGdd„dejƒZd.dd„ZGdd„dƒZeƒZdd„ZGdd„dƒZdd„Zdd„Zdd„Zd d!„ZGd"d#„d#ƒZd/d$d%„Zd0d&d'„ZGd(d)„d)ƒZGd*d+„d+eƒZ dS)1éNé)ÚdynamicÚgencachec Cs¤|dusJdƒ‚|durVz$| ¡}|dur:t| ¡dƒ}WntjtfyTYn0|dur„ddlm}| |¡}|dur„||ƒS|dur�t }t j |||||d�S)z} Helper function to return a makepy generated class for a CLSID if it exists, otherwise cope by using CDispatch. Nú#this is deprecated and will go awayrr©r©Úclsctx) Ú GetTypeInfoÚstrÚ GetTypeAttrÚ pythoncomÚ com_errorÚAttributeErrorÚrÚGetClassForCLSIDÚ CDispatchrÚDispatch) ÚdispatchÚuserNameÚ resultCLSIDÚtypeinfoÚUnicodeToStringrZ WrapperClassrÚklass©rú9C:\Program Files\Certbot\pkgs\win32com\client\__init__.pyÚ__WrapDispatchs" ÿ  rcCsV|durtj}|dur|dus.|dur6|dur6tdƒ‚|durHt||ƒSt||ƒSdS)a: Mimic VB's GetObject() function. ob = GetObject(Class = "ProgID") or GetObject(Class = clsid) will connect to an already running instance of the COM object. ob = GetObject(r"c:lahlah oo.xls") (aka the COM moniker syntax) will return a ready to use Python wrapping of the required COM object. Note: You must specifiy one or the other of these arguments. I know this isn't pretty, but it is what VB does. Blech. If you don't I'll throw ValueError at you. :) This will most likely throw pythoncom.com_error if anything fails. Nz=You must specify a value for Pathname or Class, but not both.)r Ú CLSCTX_ALLÚ ValueErrorÚGetActiveObjectÚMoniker)ÚPathnameÚClassrrrrÚ GetObject9sÿÿÿ r"cCs0t |¡}t |¡}| tj¡}t||||d�S)zL Python friendly version of GetObject's ProgID/CLSID functionality. )rr)Ú pywintypesÚIIDr rÚQueryInterfaceÚ IID_IDispatchr)r!rrrrrrrYs   rcCs.t |¡\}}}| |dtj¡}t|||d�S)zG Python friendly version of GetObject's moniker functionality. Nr)r ZMkParseDisplayNameZ BindToObjectr&r)r rZmonikerÚiZbindCtxrrrrrcsrcCs4|dusJdƒ‚t |||¡\}}t|||||d�S)z$Creates a Dispatch based COM object.Nrr)rZ_GetGoodDispatchAndUserNamer)rrrrrrrrrrls rc Cs~|dusJdƒ‚|dur2tj}|dur2|tj@}|dur@d}n|f}|durR|}t |d||tjf¡d}t|||||d�S)z:Creates a Dispatch based COM object on a specific machine.Nrrr)r Ú CLSCTX_SERVERZ CLSCTX_INPROCZCoCreateInstanceExr&r) ÚclsidÚmachinerrrrrZ serverInforrrrÚ DispatchExzs  ÿþr+c@s"eZdZdZddd„Zdd„ZdS)rzð The dynamic class used as a last resort. The purpose of this overriding of dynamic.CDispatch is to perpetuate the policy of using the makepy generated wrapper Python class instead of dynamic.CDispatch if/when possible. NcCs|dusJdƒ‚t|||dƒS)Nr)r)ÚselfÚobrZ returnCLSIDrrrrÚ_wrap_dispatch_ szCDispatch._wrap_dispatch_cCs tj |¡S©N)rrÚ__dir__©r,rrrr0¦szCDispatch.__dir__)NNN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r.r0rrrrr˜sÿ rcCsd}|durNt |j|jt|jdƒt|jdƒ¡}t||ƒsØtd||j fƒ‚nŠt|dƒrØd|j j vrnt  |¡}d|j j vr‚tdƒ‚|j }t |¡}t |j |j|j|j¡}|j |¡}|durÎtd||fƒ‚t |¡}|durþt||ƒ}t|d|ƒ}||ƒSt‚dS) z('Cast' a COM object to another interfaceNézCThe interface name '%s' does not appear in the specified library %rÚindexÚCLSIDz-Must be a makepy-able object for this to workzJThe interface name '%s' does not appear in the same library as object '%r'Údefault_interface)rZMakeModuleForTypelibr)ZlcidÚintÚmajorÚminorÚhasattrrZver_descÚ __class__Ú__dict__ÚEnsureDispatchr8ZGetModuleForCLSIDÚGetModuleForTypelibÚLCIDÚ MajorVersionÚ MinorVersionZ NamesToIIDMapÚgetÚgetattr)r-ÚtargetZtypelibÚmodr)Z target_clsidZ target_classrrrÚCastToªsFÿÿ ÿÿ     ÿ ÿÿ   rIc@s eZdZdZdd„Zdd„ZdS)Ú Constantsz(A container for generated COM constants.cCs g|_dSr/)Ú __dicts__r1rrrÚ__init__ászConstants.__init__cCs,|jD]}||vr||Sqt|ƒ‚dSr/)rKr)r,ÚaÚdrrrÚ __getattr__äs zConstants.__getattr__N)r2r3r4r5rLrOrrrrrJÞsrJcCs<z|jjd |||¡Wnty6||j|<Yn0dS©Nr)r>Ú __bases__Ú __setattr__rr?©r,ÚattrÚvalrrrÚ_event_setattr_ñs rVc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú EventsProxycCs||jd<dS)NÚ_obj_)r?)r,r-rrrrLszEventsProxy.__init__cCs(z|j ¡Wntjy"Yn0dSr/)rXÚcloser r r1rrrÚ__del__szEventsProxy.__del__cCs t|j|ƒSr/)rFrX)r,rTrrrrO szEventsProxy.__getattr__cCst|j||ƒdSr/)ÚsetattrrXrSrrrrRszEventsProxy.__setattr__N)r2r3r4rLrZrOrRrrrrrWÿsrWc Cs,t|ƒ}|jj d¡s–z`|j ¡}| ¡d}| ¡\}}| ¡}t j |d|d|d|ddd�t   t |ƒ¡}Wqœt jy’tdƒ‚Yqœ0n|j}|j}zddlm} WntyÈt} Yn0t|ƒ} | d urâtd ƒ‚| d || |fd tiƒ} | |jƒ} |  | | ¡t|d ƒ�r$| | ¡t| ƒS)aCreate a COM object that can fire events to a user defined class. clsid -- The ProgID or CLSID of the object to create. user_event_class -- A Python class object that responds to the events. This requires makepy support for the COM object being created. If this support does not exist it will be automatically generated by this function. If the object does not support makepy, a TypeError exception will be raised. The result is a class instance that both represents the COM object and handles events from the COM object. It is important to note that the returned instance is not a direct instance of the user_event_class, but an instance of a temporary class object that derives from three classes: * The makepy generated class for the COM object * The makepy generated class for the COM events * The user_event_class as passed to this function. If this is not suitable, see the getevents function for an alternative technique of handling events. Object Lifetimes: Whenever the object returned from this function is cleaned-up by Python, the events will be disconnected from the COM object. This is almost always what should happen, but see the documentation for getevents() for more details. Example: >>> class IEEvents: ... def OnVisible(self, visible): ... print "Visible changed:", visible ... >>> ie = DispatchWithEvents("InternetExplorer.Application", IEEvents) >>> ie.Visible = 1 Visible changed: 1 >>> r8rréé©Z bValidateFileú`This COM object can not automate the makepy process - please run makepy manually for this object©Ú ClassTypeNú(This COM object does not support events.Ú COMEventClassrRrL)rr>r?rEÚ_oleobj_r r ÚGetContainingTypeLibÚ GetLibAttrrÚ EnsureModuleÚGetClassForProgIDr r r Ú TypeErrorr8ÚtypesraÚ ImportErrorÚtypeÚ geteventsrrVrLr=rW) r)Úuser_event_classÚdispÚtiÚ disp_clsidÚtlbr7ÚtlaÚ disp_classÚnew_typeÚ events_classÚ result_classÚinstancerrrÚDispatchWithEventssH(ÿ   $ÿ   ýÿ   ryc Cst|ƒ}|jj d¡s–z`|j ¡}| ¡d}| ¡\}}| ¡}t j |d|d|d|ddd�t   t |ƒ¡}Wqœt jy’tdƒ‚Yqœ0n|j}|j}zddlm} WntyÈt} Yn0t|ƒ} | d urâtd ƒ‚| d | |fiƒ} | |ƒ} t|d ƒ�r| | ¡| S) a‚Similar to DispatchWithEvents - except that the returned object is *not* also usable as the original Dispatch object - that is the returned object is not dispatchable. The difference is best summarised by example. >>> class IEEvents: ... def OnVisible(self, visible): ... print "Visible changed:", visible ... >>> ie = Dispatch("InternetExplorer.Application") >>> ie_events = WithEvents(ie, IEEvents) >>> ie.Visible = 1 Visible changed: 1 Compare with the code sample for DispatchWithEvents, where you get a single object that is both the interface and the event handler. Note that the event handler instance will *not* be able to use 'self.' to refer to IE's methods and properties. This is mainly useful where using DispatchWithEvents causes circular reference problems that the simple proxy doesn't deal with r8rrr\r]r^r_r`NrbrcrL)rr>r?rErdr r rerfrrgrhr r r rir8rjrarkrlrmrr=rL) rornrprqrrr7rsrtr)rurvrwrxrrrÚ WithEventsfs:ÿ   $ÿ     rzc Csdtt |¡ƒ}t |¡}z|jWSty^zt |j¡jWYStyXYYdS0Yn0dS)a>Determine the default outgoing interface for a class, given either a clsid or progid. It returns a class - you can conveniently derive your own handler from this class and implement the appropriate methods. This method relies on the classes produced by makepy. You must use either makepy or the gencache module to ensure that the appropriate support classes have been generated for the com server that you will be handling events from. Beware of COM circular references. When the Events class is connected to the COM object, the COM object itself keeps a reference to the Python events class. Thus, neither the Events instance or the COM object will ever die by themselves. The 'close' method on the events instance must be called to break this chain and allow standard Python collection rules to manage object lifetimes. Note that DispatchWithEvents() does work around this problem by the use of a proxy object, but if you use the getevents() function yourself, you must make your own arrangements to manage this circular reference issue. Beware of creating Python circular references: this will happen if your handler has a reference to an object that has a reference back to the event source. Call the 'close' method to break the chain. Example: >>>win32com.client.gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}',0,1,1) >> >>> class InternetExplorerEvents(win32com.client.getevents("InternetExplorer.Application.1")): ... def OnVisible(self, Visible): ... print "Visibility changed: ", Visible ... >>> >>> ie=win32com.client.Dispatch("InternetExplorer.Application.1") >>> events=InternetExplorerEvents(ie) >>> ie.Visible=1 Visibility changed: 1 >>> N)r r#r$rrZdefault_sourcerZ coclass_clsid)r)rrrrrm¢s+   rmcCsˆddlm}| |¡}tj|jj}| |j|j |j |j ¡}z|j |}Wn"t yltd||fƒ‚Yn0t |j|j |j |j |¡S)a9Creates a new record object, given the name of the record, and an object from the same type library. Example usage would be: app = win32com.client.Dispatch("Some.Application") point = win32com.client.Record("SomeAppPoint", app) point.x = 0 point.y = 0 app.MoveTo(point) rrz0The structure '%s' is not defined in module '%s')rrr@ÚsysÚmodulesr>r3rAr8rBrCrDZ RecordMapÚKeyErrorrr ZGetRecordFromGuids)ÚnameÚobjectrÚmoduleÚpackageZ struct_guidrrrÚRecordÛs  ÿ  ÿ ÿr‚c@sbeZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z ddd„Z ddd„Z dS)ÚDispatchBaseClassNc Csˆ|durt |j¡}ndt|tƒrzz|j |jtj¡}WnBtjyx}z(ddl }|j |j kr^‚|j}WYd}~n d}~00||j d<dS)Nrrd) r Únewr8Ú isinstancerƒrdr%r&r ÚwinerrorZhresultZ E_NOINTERFACEr?)r,ÚoobjZdetailsr†rrrrLs ÿ zDispatchBaseClass.__init__cCslt|j ¡ƒt|jƒt|j ¡ƒt|j ¡ƒ}z|dd„|jDƒ7}Wnty^Yn0tt |ƒƒS)NcSsg|] }|j‘qSr)ÚName)Ú.0ÚprrrÚ óz-DispatchBaseClass.__dir__..) Úlistr?ÚkeysÚdirr>Ú_prop_map_get_Ú_prop_map_put_Z Properties_rÚset)r,Zlstrrrr0s ÿ þ ýÿ zDispatchBaseClass.__dir__cCs`z2tj|jjj}|r d|}ntj|jjj}WntyHd}Yn0d||jjt|ƒfS)Nzwin32com.gen_py.zwin32com.gen_py.unknownz<%s.%s instance at 0x%s>)r{r|r>r3r5r2r}Úid)r,Zmod_docÚmod_namerrrÚ__repr__#s   ýzDispatchBaseClass.__repr__cCst|d|ƒ}|j|kS©Nrd©rFrd©r,ÚotherrrrÚ__eq__4s zDispatchBaseClass.__eq__cCst|d|ƒ}|j|kSr–r—r˜rrrÚ__ne__8s zDispatchBaseClass.__ne__cGs&| |jj|d|||g|¢RŽ||¡SrP)Ú_get_good_object_rdZ InvokeTypes)r,ZdispidZwFlagsZretTypeZargTypesÚuserrÚargsrrrÚ _ApplyTypes_<s ýzDispatchBaseClass._ApplyTypes_cCs2|j |¡}|dur(tdt|ƒ|fƒ‚|j|ŽS©Nz!'%s' object has no attribute '%s')r�rErÚreprrŸ)r,rTržrrrrOCs  ÿzDispatchBaseClass.__getattr__cCsl||jvr||j|<dSz|j|\}}Wn&tyPtdt|ƒ|fƒ‚Yn0|jj||f|ŽdSr )r?r‘r}rr¡rdZInvoke)r,rTÚvalueržZdefArgsrrrrRKs   ÿ zDispatchBaseClass.__setattr__cCs t|||ƒSr/)Ú_get_good_single_object_©r,ÚobjÚ obUserNamerrrrr£Wsz*DispatchBaseClass._get_good_single_object_cCs t|||ƒSr/)rœr¤rrrrœZsz#DispatchBaseClass._get_good_object_)N)NN)NN) r2r3r4rLr0r•ršr›rŸrOrRr£rœrrrrrƒs  rƒcCstt|ƒkrt|||ƒS|Sr/)Ú_PyIDispatchTyperlr)r¥r¦rrrrr£_s  r£cCsT|dur dSt|tƒrD|ft|ƒ}|ft|ƒ}ttt|||ƒƒSt|||ƒSdSr/)r…ÚtupleÚlenÚmaprœr£)r¥r¦rZobUserNameTupleZresultCLSIDTuplerrrrœes rœc@s^eZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dS)ÚCoClassBaseClassNcCsV|durt |j¡}| |¡}|jd<dD]$}t||ƒr,t||t|d|ƒƒq,dS)NÚ _dispobj_)Ú__call__Ú__str__Ú__int__Ú__iter__Ú__len__Ú __nonzero__Z__maybe)r r„r8r9r?r=r[rF)r,r‡ZdispobjÚmayberrrrLqs   zCoClassBaseClass.__init__cCsdt|jjfS)Nz)r5r>r2r1rrrr•�szCoClassBaseClass.__repr__cCs(|jd}|durt||ƒSt|ƒ‚dS©Nr¬)r?rFr)r,rTrNrrrrO„s  zCoClassBaseClass.__getattr__cCsb||jvr||j|<dSz(|jd}|dur>| ||¡WdSWntyRYn0||j|<dSr´)r?rRr)r,rTr¢rNrrrrRŠs      zCoClassBaseClass.__setattr__cOs|jdj|i|¤ŽSr´)r?r­)r,ržÚkwargsrrrÚ__maybe__call__Ÿsz CoClassBaseClass.__maybe__call__cGs|jdj|ŽSr´)r?r®©r,ržrrrÚ__maybe__str__¢szCoClassBaseClass.__maybe__str__cGs|jdj|ŽSr´)r?r¯r·rrrÚ__maybe__int__¥szCoClassBaseClass.__maybe__int__cCs|jd ¡Sr´)r?r°r1rrrÚ__maybe__iter__¨sz CoClassBaseClass.__maybe__iter__cCs|jd ¡Sr´)r?r±r1rrrÚ__maybe__len__«szCoClassBaseClass.__maybe__len__cCs|jd ¡Sr´)r?r²r1rrrÚ__maybe__nonzero__®sz#CoClassBaseClass.__maybe__nonzero__)N) r2r3r4rLr•rOrRr¶r¸r¹rºr»r¼rrrrr«ps r«c@s@eZdZdd„Zdd„Zdd„Zdd„ZeeeeƒZd d „Z d S) ÚVARIANTcCs||_||_dSr/©Z varianttypeÚ_value)r,Zvtr¢rrrrL¸szVARIANT.__init__cCs|jSr/©r¿r1rrrÚ _get_value¾szVARIANT._get_valuecCst|ƒ|_dSr/)rœr¿)r,ZnewvalrrrÚ _set_valueÁszVARIANT._set_valuecCs|`dSr/rÀr1rrrÚ _del_valueÄszVARIANT._del_valuecCsd|j|jfS)Nzwin32com.client.VARIANT(%r, %r)r¾r1rrrr•ÉszVARIANT.__repr__N) r2r3r4rLrÁrÂrÃÚpropertyr¢r•rrrrr½·s  r½)NNN)NNNNNN)N)NN)NN)!r{r r#rrrZTypeIIDsr&r§r(rr"rrrrr+rrIrJZ constantsrVrWryrzrmr‚rƒr£rœr«rr½rrrrÚ sT ù &   ú ù  4T<9&^  G