[pywin32-checkins] pywin32/com/win32com/client dynamic.py,1.18,1.19
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <mha...@us...> - 2003-10-23 07:26:51
|
Update of /cvsroot/pywin32/pywin32/com/win32com/client In directory sc8-pr-cvs1:/tmp/cvs-serv30563 Modified Files: dynamic.py Log Message: Previously, dynamic objects only supported enumeration if there was a method named _NewEnum() - now we always try and invoke with DISPID_NEWENUM. Also add __iter__ support for these objects Index: dynamic.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/dynamic.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dynamic.py 2 Jul 2003 03:43:13 -0000 1.18 --- dynamic.py 23 Oct 2003 07:21:53 -0000 1.19 *************** *** 188,196 **** def _NewEnum(self): ! invkind, dispid = self._find_dispatch_type_("_NewEnum") ! if invkind is None: ! return None ! ! enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,LCID,invkind,(13, 10),()) import util return util.WrapEnum(enum, None) --- 188,196 ---- def _NewEnum(self): ! try: ! invkind = pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET ! enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,LCID,invkind,(13, 10),()) ! except pythoncom.com_error: ! return None # no enumerator for this object. import util return util.WrapEnum(enum, None) *************** *** 396,399 **** --- 396,416 ---- def __getattr__(self, attr): + if attr=='__iter__': + # We can't handle this as a normal method, as if the attribute + # exists, then it must return an iterable object. + try: + invkind = pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET + enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,LCID,invkind,(13, 10),()) + except pythoncom.com_error: + raise AttributeError, "This object can not function as an iterator" + # We must return a callable object. + class Factory: + def __init__(self, ob): + self.ob = ob + def __call__(self): + import win32com.client.util + return win32com.client.util.Iterator(self.ob) + return Factory(enum) + if attr[0]=='_' and attr[-1]=='_': # Fast-track. raise AttributeError, attr |