idZddlZddlZddlmZddlmZddZdZGdd Z Gd d e Z e ej ddfd Z Gd dZ e fdZGddZdS)zGeneral Server side utilitiesN)policy) COMExceptionc| tj}|dkrddl}|jjj}||dkr ||}n |||}t j|}|||}|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 DefaultPolicywin32com.server.dispatcherserver dispatcherDefaultDebugDispatcher pythoncom WrapObjectQueryInterface)obiid usePolicy useDispatcherwin32coms BC:\PYTHON\_runtimes\venv\Lib\site-packages\win32com/server/util.pywrapr s( )))) 2I   2 2 Yr]] ]9b ) )  b ! !B    s # # Icftj|}t|dr|j}|jS)zvUnwraps an interface. Given an interface which wraps up a Gateway, return the object behind the gateway. r)r UnwrapObjecthasattrr_obj_)rs runwrapr%s4   # #Br8 Y 8OrcTeZdZdZgdZdejfdZdZdZ dZ dZ d Z d Z d S) 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. )NextSkipResetClonerc0||_||_||_dSN)_list_index_iid_)selfdatar%rs r__init__zListEnumerator.__init__?s   rc ||jkrdSdS)Nr)r&)r'rs r_query_interface_z ListEnumerator._query_interface_Ds $*  1  rch|j|j|j|z}|||Sr#)r$r%rr'countresults rrzListEnumerator.NextHs3TZ$*u*<<= % rc|j|z}|t|jkrt|j}||_dSr#)r%lenr$)r'r.ends rrzListEnumerator.SkipMs=j5  T[!! ! !dk""C rcd|_dSNr)r%r's rr zListEnumerator.ResetSs  rch|||j|jSr#)_wrap __class__r$r%r5s rr!zListEnumerator.CloneVs&zz$..djAABBBrc t|Sr#rr'rs rr7zListEnumerator._wrapY BxxrN)__name__ __module__ __qualname____doc___public_methods_r IID_IEnumVARIANTr)r+rrr r!r7rrrr2s:99#$)*D   CCCrrceZdZdZdZdS)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. c|j|j|j|z}||t|j|Sr#)r$r%rmapr7r-s rrzListEnumeratorGateway.Nextgs@TZ$*u*<<= %4:v&&&rN)r=r>r?r@rrCrrrErE]s-'''''rrEcB|||}t||||S)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)rrr:)seqclsrrrrs rNewEnumrKms/$ Sc   B C9M J J JJrcJeZdZdZgdZd dZdZeZdZdZ d Z d Z d Z dS) CollectionzA collection of VARIANT values.)ItemCountAddRemoveInsertNrc6|g}||_|r ddg|_dSdS)NrNrO)r(rA)r'r(readOnlys rr)zCollection.__init__s: <D   6%+W$5D ! ! ! 6 6rct|dkrttj |j|dS#t $r-}ttjt|d}~wwxYw)NrscoderrWdesc)r1rwinerrorDISP_E_BADPARAMCOUNTr( IndexErrorDISP_E_BADINDEXstr)r'argsrYs rrNzCollection.Items{ t99>>X%BCCC C O9T!W% % O O OX%=CIINNN N OsA A9 (A44A9c*t|jSr#)r1r(r5s rrOzCollection.Counts49~~rc:|j|dSr#)r(append)r'values rrPzCollection.Adds rc |j|=dS#t$r-}ttjt |d}~wwxYw)NrX)r(r\rrZr]r^)r'r%rYs rrQzCollection.RemovesW O %    O O OX%=CIINNN N Os A(>Ac t|}n/#ttf$rttjwxYw|j||dS)NrV)int ValueError TypeErrorrrZDISP_E_TYPEMISMATCHr(insert)r'r%rcs rrRzCollection.Insertsk CJJEEI& C C CX%ABBB B C &&&&&s,>c*t|jSr#)rKr(r5s r_NewEnumzCollection._NewEnumsty!!!rr4) r=r>r?r@rAr)rN_value_rOrPrQrRrlrCrrrMrMs%%CCC6666OOOG   OOO '''"""""rrMctjtj||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@). )r r rr IID_IDispatch)rIrJs r NewCollectionrps9  SSXX&& (?AX  rcPeZdZgdZejgZdZdZdZ dZ dZ dZ dZ d S) FileStream)ReadWriter!CopyToSeekc||_dSr#)file)r'rxs rr)zFileStream.__init__s  rc6|j|Sr#)rxread)r'amounts rrszFileStream.Readsy~~f%%%rcT|j|t|Sr#)rxwriter1)r'r(s rrtzFileStream.Writes" 4yyrc\|||jSr#)r7r8rxr5s rr!zFileStream.Clones"zz$..33444rc|j|}t|}||||fSr#)rxrzr1rt)r'destcbr(cbreads rruzFileStream.CopyTos<y~~b!!T 4v~rcj|j|||jSr#)rxseektell)r'offsetorigins rrvzFileStream.Seeks* vv&&&y~~rc t|Sr#r:r;s rr7zFileStream._wrapr<rN)r=r>r?rAr IID_IStream_com_interfaces_r)rsrtr!rurvr7rCrrrrrrsCCC!-.&&&555    rrr)NNN)r@r rZr exceptionrrrrrErBrKrMrprrrCrrrsW########6   ((((((((V ' ' ' ' 'N ' ' '$ " KKKK,2"2"2"2"2"2"2"2"j&     r