a „oe.ã@sœdZddlZddlZddlmZddlmZddd„Zdd „ZGd d „d ƒZ Gd d „d e ƒZ e ej ddfdd„Z Gdd„dƒZ e fdd„ZGdd„dƒZdS)z General Server side utilities éNé)Úpolicy)Ú COMExceptioncCsl|durtj}|dkr(ddl}|jjj}|dus8|dkrB||ƒ}n |||ƒ}t |¡}|durh| |¡}|S)zÏWraps an object in a PyGDispatch gateway. Returns a client side PyI{iid} interface. Interface and gateway support must exist for the specified IID, as the QueryInterface() method is used. Nrr) rÚ DefaultPolicyZwin32com.server.dispatcherZserverÚ dispatcherZDefaultDebugDispatcherÚ pythoncomÚ WrapObjectZQueryInterface)ÚobÚiidÚ usePolicyÚ useDispatcherZwin32com©r ú5C:\Program Files\Certbot\pkgs\win32com\server\util.pyÚwrap s      rcCs t |¡}t|dƒr|j}|jS)zvUnwraps an interface. Given an interface which wraps up a Gateway, return the object behind the gateway. r)rZ UnwrapObjectÚhasattrrZ_obj_)r r r rÚunwrap%s  rc@sXeZdZdZgd¢Zdejfdd„Zdd„Zdd „Z d d „Z d d „Z dd„Z dd„Z dS)ÚListEnumeratoranA class to expose a Python sequence as an EnumVARIANT. Create an instance of this class passing a sequence (list, tuple, or any sequence protocol supporting object) and it will automatically support the EnumVARIANT interface for the object. See also the @NewEnum@ function, which can be used to turn the instance into an actual COM server. )ÚNextÚSkipÚResetÚClonercCs||_||_||_dS©N)Ú_list_ÚindexÚ_iid_)ÚselfÚdatarr r r rÚ__init__?szListEnumerator.__init__cCs||jkrdSdS)Nr)r)rr r r rÚ_query_interface_Ds z ListEnumerator._query_interface_cCs$|j|j|j|…}| |¡|Sr)rrr©rÚcountÚresultr r rrHs zListEnumerator.NextcCs,|j|}|t|jƒkr"t|jƒ}||_dSr)rÚlenr)rr Úendr r rrMs  zListEnumerator.SkipcCs d|_dS)Nr)r©rr r rrSszListEnumerator.ResetcCs| | |j|j¡¡Sr)Ú_wrapÚ __class__rrr$r r rrVszListEnumerator.ClonecCst|ƒSr©r©rr r r rr%YszListEnumerator._wrapN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú_public_methods_rÚIID_IEnumVARIANTrrrrrrr%r r r rr2s rc@seZdZdZdd„ZdS)ÚListEnumeratorGatewayafA List Enumerator which wraps a sequence's items in gateways. If a sequence contains items (objects) that have not been wrapped for return through the COM layers, then a ListEnumeratorGateway can be used to wrap those items before returning them (from the Next() method). See also the @ListEnumerator@ class and the @NewEnum@ function. cCs,|j|j|j|…}| |¡t|j|ƒSr)rrrÚmapr%rr r rrgs zListEnumeratorGateway.NextN)r)r*r+r,rr r r rr/]s r/cCs|||d�}t||||d�S)a°Creates a new enumerator COM server. This function creates a new COM Server that implements the IID_IEnumVARIANT interface. A COM server that can enumerate the passed in sequence will be created, then wrapped up for return through the COM framework. Optionally, a custom COM server for enumeration can be passed (the default is @ListEnumerator@), and the specific IEnum interface can be specified. )r )r r r')ÚseqÚclsr r r r r r rÚNewEnumms r3c@sVeZdZdZgd¢Zddd„Zdd„ZeZd d „Zd d „Z d d„Z dd„Z dd„Z dS)Ú CollectionzA collection of VARIANT values.)ÚItemÚCountÚAddÚRemoveÚInsertNrcCs$|dur g}||_|r ddg|_dS)Nr5r6)rr-)rrZreadOnlyr r rrˆs zCollection.__init__c Gsdt|ƒdkrttjd�‚z|j|dWSty^}zttjt|ƒd�‚WYd}~n d}~00dS)Nr©Úscoder©r;Údesc)r"rÚwinerrorZDISP_E_BADPARAMCOUNTrÚ IndexErrorÚDISP_E_BADINDEXÚstr)rÚargsr=r r rr5–s   zCollection.ItemcCs t|jƒSr)r"rr$r r rr6¡szCollection.CountcCs|j |¡dSr)rÚappend)rÚvaluer r rr7¤szCollection.Addc CsHz |j|=Wn6tyB}zttjt|ƒd�‚WYd}~n d}~00dS)Nr<)rr?rr>r@rA)rrr=r r rr8§s zCollection.Removec CsBz t|ƒ}Wn"ttfy.ttjd�‚Yn0|j ||¡dS)Nr:)ÚintÚ ValueErrorÚ TypeErrorrr>ZDISP_E_TYPEMISMATCHrÚinsert)rrrDr r rr9­s  zCollection.InsertcCs t|jƒSr)r3rr$r r rÚ_NewEnum´szCollection._NewEnum)Nr) r)r*r+r,r-rr5Ú_value_r6r7r8r9rIr r r rr4ƒs  r4cCst t ||ƒ¡tjtj¡S)a—Creates a new COM collection object This function creates a new COM Server that implements the common collection protocols, including enumeration. (_NewEnum) A COM server that can enumerate the passed in sequence will be created, then wrapped up for return through the COM framework. Optionally, a custom COM server for enumeration can be passed (the default is @Collection@). )rrrrZ IID_IDispatch)r1r2r r rÚ NewCollection¸s ÿrKc@sTeZdZgd¢ZejgZdd„Zdd„Zdd„Z dd „Z d d „Z d d „Z dd„Z dS)Ú FileStream)ÚReadÚWriterÚCopyToÚSeekcCs ||_dSr)Úfile)rrQr r rrÌszFileStream.__init__cCs |j |¡Sr)rQÚread)rÚamountr r rrMÏszFileStream.ReadcCs|j |¡t|ƒSr)rQÚwriter")rrr r rrNÒs zFileStream.WritecCs| | |j¡¡Sr)r%r&rQr$r r rrÖszFileStream.ClonecCs&|j |¡}t|ƒ}| |¡||fSr)rQrRr"rN)rÚdestÚcbrZcbreadr r rrOÙs  zFileStream.CopyTocCs|j ||¡|j ¡Sr)rQÚseekÚtell)rÚoffsetÚoriginr r rrPßszFileStream.SeekcCst|ƒSrr'r(r r rr%äszFileStream._wrapN)r)r*r+r-rZ IID_IStreamZ_com_interfaces_rrMrNrrOrPr%r r r rrLÈsrL)NNN)r,rr>ÚrÚ exceptionrrrrr/r.r3r4rKrLr r r rÚs     +û 5