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


Groups > comp.lang.python > #76420

Pythoncom IEnum weird behaviour

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Pythoncom IEnum weird behaviour
Date Sun, 17 Aug 2014 23:03:26 +1200
Lines 60
Message-ID <c5bgg0Fr3qcU1@mid.individual.net> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net IXbl+0HvYMqPpiWdX0ctpQF3Oe4d6kQPZOiJ4IIO76YKglr6BY
Cancel-Lock sha1:OUkzPYySTCLWVcGchF/RLen653Y=
User-Agent Mozilla Thunderbird 1.0.5 (Macintosh/20050711)
X-Accept-Language en-us, en
Xref csiph.com comp.lang.python:76420

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web