Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76420 > unrolled thread

Pythoncom IEnum weird behaviour

Started byGregory Ewing <greg.ewing@canterbury.ac.nz>
First post2014-08-17 23:03 +1200
Last post2014-08-17 23:03 +1200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Pythoncom IEnum weird behaviour Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-08-17 23:03 +1200

#76420 — Pythoncom IEnum weird behaviour

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2014-08-17 23:03 +1200
SubjectPythoncom IEnum weird behaviour
Message-ID<c5bgg0Fr3qcU1@mid.individual.net>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web