Pythoncom IEnum weird behaviour
Gregory Ewing
greg.ewing at canterbury.ac.nz
Sun Aug 17 07:03:26 EDT 2014
I have a COM server implemented in Python. I've created
the following object implementing IEnum to automatically
wrap the sequence elements in PyIDispatch objects:
from win32com.server.util import ListEnumerator
class Iterator(ListEnumerator):
def Next(self, count):
items = ListEnumerator.Next(self, count)
print "Server.Iterator: items =", items
result = map(autowrap, items)
print "Server.Iterator: result =", result
return result
where autowrap() is a function that uses various
strategies to wrap different types of objects.
When I try to iterate over one of these, I get this:
Server.Iterator: items = [<Duck.Leg object at 0x01803AF0>]
Server.Iterator: result = [<PyIDispatch at 0x0149BBB0 with obj at 0x01403058>]
PyGEnumVariant::Next got a bad return value
Traceback (most recent call last):
File "F:\AFICom\AFICom2\Tests\test_nesting.py", line 14, in <module>
for leg in legs:
File "E:\Python27\lib\site-packages\win32com\client\util.py", line 84, in next
return _get_good_object_(self._iter_.next(), resultCLSID = self.resultCLSID)
TypeError: Cant convert vectors!
I don't understand what's happening here. The "Next got a bad return value"
message seems to be coming from PyGEnumVARIANT::Next in PyGEnumVariant.cpp.
The only ways to get there seem to be if your Next() method doesn't
return a sequence, or getting its length fails, or getting an item from
it fails. But as far as I can tell, I'm returning a perfectly good
list object, so I can't see how any of those things can happen.
I also don't know why I'm not getting the COMError exception set by
that branch of the code:
error:
PyErr_Clear(); // just in case
PyCom_LogF("PyGEnumVariant::Next got a bad return value");
Py_DECREF(result);
return PyCom_SetCOMErrorFromSimple(E_FAIL, IID_IEnumVARIANT, "Next() did not
return a sequence of objects");
The "Cant convert vectors" message is puzzling as well. That comes from
the following piece of code in PyCom_PyObjectFromVariant in oleargs.cpp:
/* ### note: we shouldn't see this, it is illegal in a VARIANT */
if (V_ISVECTOR(var)) {
return OleSetTypeError(_T("Cant convert vectors!"));
}
Anyone have any idea what's happening? Is there something wrong with
my Next() method? Is there a bug in the win32com C++ code?
--
Greg
More information about the Python-list
mailing list