a oef@s<ddlZddlZddlZddlmZmZejejZddddej dfddZ d,ddZ ej fdd Z ej fd d Zddddej fd d Zd-ddZGdddejZd.ddZGdddZeZddZGdddZddZddZddZd d!ZGd"d#d#Zd/d$d%Zd0d&d'ZGd(d)d)ZGd*d+d+eZ dS)1N)dynamicgencachec Cs|dusJd|durVz$|}|dur:t|d}WntjtfyTYn0|durddlm}||}|dur||S|durt }t j |||||dS)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 awayrrrclsctx) GetTypeInfostr GetTypeAttr pythoncom com_errorAttributeErrorrGetClassForCLSID CDispatchrDispatch) dispatchuserName resultCLSIDtypeinfoUnicodeToStringrZ WrapperClassrklassr9C:\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 ValueErrorGetActiveObjectMoniker)PathnameClassrrrr GetObject9s r"cCs0t|}t|}|tj}t||||dS)zL Python friendly version of GetObject's ProgID/CLSID functionality. )rr) pywintypesIIDr rQueryInterface IID_IDispatchr)r!rrrrrrrYs   rcCs.t|\}}}||dtj}t|||dS)zG Python friendly version of GetObject's moniker functionality. Nr)r ZMkParseDisplayNameZ BindToObjectr&r)r rZmonikeriZbindCtxrrrrrcsrcCs4|dusJdt|||\}}t|||||dS)z$Creates a Dispatch based COM object.Nrr)rZ_GetGoodDispatchAndUserNamer)rrrrrrrrrrls rc Cs~|dusJd|dur2tj}|dur2|tj@}|dur@d}n|f}|durR|}t|d||tjfd}t|||||dS)z:Creates a Dispatch based COM object on a specific machine.Nrrr)r CLSCTX_SERVERZ CLSCTX_INPROCZCoCreateInstanceExr&r) clsidmachinerrrrrZ serverInforrrr DispatchExzs  r+c@s"eZdZdZdddZddZdS)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|dusJdt|||dS)Nr)r)selfobrZ returnCLSIDrrrr_wrap_dispatch_szCDispatch._wrap_dispatch_cCs tj|SN)rr__dir__r,rrrr0szCDispatch.__dir__)NNN)__name__ __module__ __qualname____doc__r.r0rrrrrs rcCsd}|durNt|j|jt|jdt|jd}t||std||j fnt|drd|j j vrnt |}d|j j vrtd|j }t|}t|j |j|j|j}|j|}|durtd||ft|}|durt||}t|d|}||StdS) z('Cast' a COM object to another interfaceNzCThe interface name '%s' does not appear in the specified library %rindexCLSIDz-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)ZlcidintmajorminorhasattrrZver_desc __class____dict__EnsureDispatchr8ZGetModuleForCLSIDGetModuleForTypelibLCID MajorVersion MinorVersionZ NamesToIIDMapgetgetattr)r-targetZtypelibmodr)Z target_clsidZ target_classrrrCastTosF          rIc@s eZdZdZddZddZdS) Constantsz(A container for generated COM constants.cCs g|_dSr/) __dicts__r1rrr__init__szConstants.__init__cCs,|jD]}||vr||Sqt|dSr/)rKr)r,adrrr __getattr__s zConstants.__getattr__N)r2r3r4r5rLrOrrrrrJsrJcCs<z|jjd|||Wnty6||j|<Yn0dSNr)r> __bases__ __setattr__rr?r,attrvalrrr_event_setattr_s rVc@s,eZdZddZddZddZddZd S) EventsProxycCs||jd<dS)N_obj_)r?)r,r-rrrrLszEventsProxy.__init__cCs(z|jWntjy"Yn0dSr/)rXcloser r r1rrr__del__szEventsProxy.__del__cCs t|j|Sr/)rFrX)r,rTrrrrO szEventsProxy.__getattr__cCst|j||dSr/)setattrrXrSrrrrRszEventsProxy.__setattr__N)r2r3r4rLrZrOrRrrrrrWsrWc Cs,t|}|jjdsz`|j}|d}|\}}|}t j |d|d|d|dddt t |}Wqt jytdYq0n|j}|j}zddlm} Wntyt} Yn0t|} | d urtd | 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 >>> r8rrZ 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 EnsureModuleGetClassForProgIDr r r TypeErrorr8typesra ImportErrortype geteventsrrVrLr=rW) r)user_event_classdispti disp_clsidtlbr7tla disp_classnew_type events_class result_classinstancerrrDispatchWithEventssH(   $      ryc Cst|}|jjdsz`|j}|d}|\}}|}t j |d|d|d|dddt t |}Wqt jytdYq0n|j}|j}zddlm} Wntyt} Yn0t|} | d urtd | d | |fi} | |} t|d r|| | S) aSimilar 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|jjWYStyXYYdS0Yn0dS)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)rrrrrms+   rmcCsddlm}||}tj|jj}||j|j |j |j }z|j |}Wn"t yltd||fYn0t|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@sysmodulesr>r3rAr8rBrCrDZ RecordMapKeyErrorrr ZGetRecordFromGuids)nameobjectrmodulepackageZ struct_guidrrrRecords    rc@sbeZdZdddZddZddZdd Zd d Zd d ZddZ ddZ dddZ dddZ dS)DispatchBaseClassNc Cs|durt|j}ndt|trzz|j|jtj}WnBtjyx}z(ddl }|j |j kr^|j}WYd}~n d}~00||j d<dS)Nrrd) r newr8 isinstancerrdr%r&r winerrorZhresultZ E_NOINTERFACEr?)r,oobjZdetailsrrrrrLs  zDispatchBaseClass.__init__cCslt|jt|jt|jt|j}z|dd|jD7}Wnty^Yn0tt |S)NcSsg|] }|jqSr)Name).0prrr z-DispatchBaseClass.__dir__..) listr?keysdirr>_prop_map_get__prop_map_put_Z Properties_rset)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_docmod_namerrr__repr__#s   zDispatchBaseClass.__repr__cCst|d|}|j|kSNrdrFrdr,otherrrr__eq__4s zDispatchBaseClass.__eq__cCst|d|}|j|kSrrrrrr__ne__8s zDispatchBaseClass.__ne__cGs&||jj|d|||g|R||SrP)_get_good_object_rdZ InvokeTypes)r,ZdispidZwFlagsZretTypeZargTypesuserrargsrrr _ApplyTypes_<s zDispatchBaseClass._ApplyTypes_cCs2|j|}|dur(tdt||f|j|SNz!'%s' object has no attribute '%s')rrErreprr)r,rTrrrrrOCs  zDispatchBaseClass.__getattr__cCsl||jvr||j|<dSz|j|\}}Wn&tyPtdt||fYn0|jj||f|dSr)r?rr}rrrdZInvoke)r,rTvaluerZdefArgsrrrrRKs    zDispatchBaseClass.__setattr__cCs t|||Sr/)_get_good_single_object_r,obj obUserNamerrrrrWsz*DispatchBaseClass._get_good_single_object_cCs t|||Sr/)rrrrrrZsz#DispatchBaseClass._get_good_object_)N)NN)NN) r2r3r4rLr0rrrrrOrRrrrrrrrs  rcCstt|krt|||S|Sr/)_PyIDispatchTyperlr)rrrrrrr_s  rcCsT|dur dSt|trD|ft|}|ft|}ttt|||St|||SdSr/)rtuplelenmaprr)rrrZobUserNameTupleZresultCLSIDTuplerrrres rc@s^eZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ dS)CoClassBaseClassNcCsV|durt|j}||}|jd<dD]$}t||r,t||t|d|q,dS)N _dispobj_)__call____str____int____iter____len__ __nonzero__Z__maybe)r rr8r9r?r=r[rF)r,rZdispobjmayberrrrLqs   zCoClassBaseClass.__init__cCsdt|jjfS)Nz)r5r>r2r1rrrrszCoClassBaseClass.__repr__cCs(|jd}|durt||St|dSNr)r?rFr)r,rTrNrrrrOs  zCoClassBaseClass.__getattr__cCsb||jvr||j|<dSz(|jd}|dur>|||WdSWntyRYn0||j|<dSr)r?rRr)r,rTrrNrrrrRs      zCoClassBaseClass.__setattr__cOs|jdj|i|Sr)r?r)r,rkwargsrrr__maybe__call__sz CoClassBaseClass.__maybe__call__cGs|jdj|Sr)r?rr,rrrr__maybe__str__szCoClassBaseClass.__maybe__str__cGs|jdj|Sr)r?rrrrr__maybe__int__szCoClassBaseClass.__maybe__int__cCs|jdSr)r?rr1rrr__maybe__iter__sz CoClassBaseClass.__maybe__iter__cCs|jdSr)r?rr1rrr__maybe__len__szCoClassBaseClass.__maybe__len__cCs|jdSr)r?rr1rrr__maybe__nonzero__sz#CoClassBaseClass.__maybe__nonzero__)N) r2r3r4rLrrOrRrrrrrrrrrrrps rc@s@eZdZddZddZddZddZeeeeZd d Z d S) VARIANTcCs||_||_dSr/Z varianttype_value)r,ZvtrrrrrLszVARIANT.__init__cCs|jSr/rr1rrr _get_valueszVARIANT._get_valuecCst||_dSr/)rr)r,Znewvalrrr _set_valueszVARIANT._set_valuecCs|`dSr/rr1rrr _del_valueszVARIANT._del_valuecCsd|j|jfS)Nzwin32com.client.VARIANT(%r, %r)rr1rrrrszVARIANT.__repr__N) r2r3r4rLrrrpropertyrrrrrrrs  r)NNN)NNNNNN)N)NN)NN)!r{r r#rrrZTypeIIDsr&rr(rr"rrrrr+rrIrJZ constantsrVrWryrzrmrrrrrrrrrrr sT  &      4T<9&^  G