a oe.@sdZddlZddlZddlmZddlmZdddZdd ZGd d d Z Gd d d e Z e ej ddfddZ GdddZ e fddZGdddZdS)z General Server side utilities N)policy) COMExceptioncCsl|durtj}|dkr(ddl}|jjj}|dus8|dkrB||}n |||}t|}|durh||}|S)zWraps 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)obiid usePolicy useDispatcherZwin32comr 5C:\Program Files\Certbot\pkgs\win32com\server\util.pywrap s      rcCs t|}t|dr|j}|jS)zvUnwraps an interface. Given an interface which wraps up a Gateway, return the object behind the gateway. r)rZ UnwrapObjecthasattrrZ_obj_)r r r runwrap%s  rc@sXeZdZdZgdZdejfddZddZdd Z d d Z d d Z ddZ ddZ 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. )NextSkipResetClonercCs||_||_||_dSN)_list_index_iid_)selfdatarr 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)rrrrcountresultr r rrHs zListEnumerator.NextcCs,|j|}|t|jkr"t|j}||_dSr)rlenr)rr endr r rrMs  zListEnumerator.SkipcCs d|_dS)Nr)rrr r rrSszListEnumerator.ResetcCs|||j|jSr)_wrap __class__rrr$r r rrVszListEnumerator.ClonecCst|Srrrr r r rr%YszListEnumerator._wrapN)__name__ __module__ __qualname____doc___public_methods_rIID_IEnumVARIANTrrrrrrr%r r r rr2s rc@seZdZdZddZdS)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)rrrmapr%rr r rrgs zListEnumeratorGateway.NextN)r)r*r+r,rr r r rr/]s r/cCs|||d}t||||dS)aCreates 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')seqclsr r r r r r rNewEnumms r3c@sVeZdZdZgdZdddZddZeZd d Zd d Z d dZ ddZ ddZ dS) CollectionzA collection of VARIANT values.)ItemCountAddRemoveInsertNrcCs$|dur g}||_|r ddg|_dS)Nr5r6)rr-)rrZreadOnlyr r rrs zCollection.__init__c Gsdt|dkrttjdz|j|dWSty^}zttjt|dWYd}~n d}~00dS)Nrscoderr;desc)r"rwinerrorZDISP_E_BADPARAMCOUNTr IndexErrorDISP_E_BADINDEXstr)rargsr=r r rr5s   zCollection.ItemcCs t|jSr)r"rr$r r rr6szCollection.CountcCs|j|dSr)rappend)rvaluer r rr7szCollection.Addc CsHz |j|=Wn6tyB}zttjt|dWYd}~n d}~00dS)Nr<)rr?rr>r@rA)rrr=r r rr8s zCollection.Removec CsBz t|}Wn"ttfy.ttjdYn0|j||dS)Nr:)int ValueError TypeErrorrr>ZDISP_E_TYPEMISMATCHrinsert)rrrDr r rr9s  zCollection.InsertcCs t|jSr)r3rr$r r r_NewEnumszCollection._NewEnum)Nr) r)r*r+r,r-rr5_value_r6r7r8r9rIr r r rr4s  r4cCstt||tjtjS)aCreates 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 NewCollections rKc@sTeZdZgdZejgZddZddZddZ dd Z d d Z d d Z ddZ dS) FileStream)ReadWriterCopyToSeekcCs ||_dSr)file)rrQr r rrszFileStream.__init__cCs |j|Sr)rQread)ramountr r rrMszFileStream.ReadcCs|j|t|Sr)rQwriter")rrr r rrNs zFileStream.WritecCs|||jSr)r%r&rQr$r r rrszFileStream.ClonecCs&|j|}t|}||||fSr)rQrRr"rN)rdestcbrZcbreadr r rrOs  zFileStream.CopyTocCs|j|||jSr)rQseektell)roffsetoriginr r rrPszFileStream.SeekcCst|Srr'r(r r rr%szFileStream._wrapN)r)r*r+r-rZ IID_IStreamZ_com_interfaces_rrMrNrrOrPr%r r r rrLsrL)NNN)r,rr>r exceptionrrrrr/r.r3r4rKrLr r r rs     + 5