a „oeoã@s€dZddlZddlZddlZddlmZmZddlmZmZddl m Z ddlm Z Gdd„dej ƒZ d d „Zed kr|eƒdS) 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_METHODÚDISPATCH_PROPERTYGET)ÚpolicyÚutil)Ú COMException)ÚS_OKc@sTeZdZgZejejddœZdZdZ dZ dZ dZ dd „Z d d „Zd d „Zdd„ZdS)ÚDictionaryPolicyé)ÚitemZ_newenumÚcountzPython Dictionaryz&{39b61048-c755-11d0-86fa-00c04fc2e03e}zPython.DictionaryzPython.Dictionary.1z,win32com.servers.dictionary.DictionaryPolicycCs| i¡t ||¡S©N)Ú_wrap_Ú pythoncomZ WrapObject)ÚselfZclsidZreqIID©rús z!DictionaryPolicy._CreateInstance_cCs ||_dSr )Ú_obj_)rÚobrrrr BszDictionaryPolicy._wrap_c Cs^|dkrêt|ƒ}|dkr&tdtjd�‚|d}t|ƒttfvrLtdtjd�‚| ¡}|tt B@r–|dkrtttjd�‚z |j |WSt y”YdS0|dkrªttjd�‚|ddurØz |j |=Wqæt yÔYqæ0n|d|j |<t S|dk�r.|t @�s ttj d�‚t|ƒdk�r$ttjd�‚t|j ƒS|tjk�rNt t|j  ¡ƒ¡Sttj d�‚dS)Nrr znot enough parameters)ÚdescÚscodezKey must be a string)ré)ÚlenrÚwinerrorZDISP_E_BADPARAMCOUNTÚtypeÚstrZDISP_E_TYPEMISMATCHÚlowerrrrÚKeyErrorrÚDISP_E_MEMBERNOTFOUNDrÚDISPID_NEWENUMrZNewEnumÚlistÚkeys) rZdispidÚlcidZwFlagsÚargsÚkwargsZserviceProviderÚlÚkeyrrrÚ _invokeex_EsJÿÿ              zDictionaryPolicy._invokeex_cCs@|d ¡}z|j|fWSty:ttjdd�‚Yn0dS)NrzMember not found)rr)rÚ_name_to_dispid_rrrr)rÚnamesr"Ú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,sý1rcCsddlm}|tƒS)Nr©ÚUseCommandLine)Zwin32com.server.registerr0rr/rrrÚRegister‚s r1Ú__main__)Ú__doc__rZ pywintypesrrrZwin32com.serverrrZwin32com.server.exceptionrrZBasicWrapPolicyrr1r,rrrrÚs"  V