a oeo@sdZddlZddlZddlZddlmZmZddlmZmZddl m Z ddlm Z Gdddej Z d d Zed kr|edS) a<Python.Dictionary COM Server. This module implements a simple COM server that acts much like a Python dictionary or as a standard string-keyed VB Collection. The keys of the dictionary are strings and are case-insensitive. It uses a highly customized policy to fine-tune the behavior exposed to the COM client. The object exposes the following properties: int Count (readonly) VARIANT Item(BSTR key) (propget for Item) Item(BSTR key, VARIANT value) (propput for Item) Note that 'Item' is the default property, so the following forms of VB code are acceptable: set ob = CreateObject("Python.Dictionary") ob("hello") = "there" ob.Item("hi") = ob("HELLO") All keys are defined, returning VT_NULL (None) if a value has not been stored. To delete a key, simply assign VT_NULL to the key. The object responds to the _NewEnum method by returning an enumerator over the dictionary's keys. This allows for the following type of VB code: for each name in ob debug.print name, ob(name) next N)DISPATCH_METHODDISPATCH_PROPERTYGET)policyutil) COMException)S_OKc@sTeZdZgZejejddZdZdZ dZ dZ dZ dd Z d d Zd d ZddZdS)DictionaryPolicy)itemZ_newenumcountzPython Dictionaryz&{39b61048-c755-11d0-86fa-00c04fc2e03e}zPython.DictionaryzPython.Dictionary.1z,win32com.servers.dictionary.DictionaryPolicycCs|it||SN)_wrap_ pythoncomZ WrapObject)selfZclsidZreqIIDrs z!DictionaryPolicy._CreateInstance_cCs ||_dSr )_obj_)robrrrr BszDictionaryPolicy._wrap_c Cs^|dkrt|}|dkr&tdtjd|d}t|ttfvrLtdtjd|}|tt B@r|dkrtttjdz |j |WSt yYdS0|dkrttjd|ddurz |j |=Wqt yYq0n|d|j |<t S|dkr.|t @s ttj dt|dkr$ttjdt|j S|tjkrNtt|j Sttj ddS)Nrr znot enough parameters)descscodezKey must be a string)r)lenrwinerrorZDISP_E_BADPARAMCOUNTtypestrZDISP_E_TYPEMISMATCHlowerrrrKeyErrorrDISP_E_MEMBERNOTFOUNDrDISPID_NEWENUMrZNewEnumlistkeys) rZdispidlcidZwFlagsargskwargsZserviceProviderlkeyrrr _invokeex_EsJ              zDictionaryPolicy._invokeex_cCs@|d}z|j|fWSty:ttjddYn0dS)NrzMember not found)rr)r_name_to_dispid_rrrr)rnamesr"namerrr_getidsofnames_vs  z DictionaryPolicy._getidsofnames_N)__name__ __module__ __qualname__Z_com_interfaces_rZ DISPID_VALUErr(Z _reg_desc_Z _reg_clsid_Z _reg_progid_Z_reg_verprogid_Z_reg_policy_spec_rr r'r+rrrrr,s1rcCsddlm}|tS)NrUseCommandLine)Zwin32com.server.registerr0rr/rrrRegisters r1__main__)__doc__rZ pywintypesrrrZwin32com.serverrrZwin32com.server.exceptionrrZBasicWrapPolicyrr1r,rrrrs"  V