[PyKDE] KHTML method returning null

Jim Bublitz jbublitz at nwinternet.com
Tue Mar 6 01:00:59 GMT 2007


On Monday 05 March 2007 08:29, Paul Giannaros wrote:
> The documentation for KHTML's DOM::Document::getElementById (
> http://api.kde.org/3.5-api/kdelibs-apidocs/khtml/html/classDOM_1_1Document.
>html#a20 ) show's that the method returns null when an element in the
> webpage by the given ID hasn't been found. I would have thought that would
> have mapped to Python's None, but instead I'm getting a khtml.DOM.Element.

If the underlying C++ call returns null, the PyKDE call should return None 
(see sip_api_return_from_new_instance in siplib/siplib.c)

> Whenever I try to call a method on it, my application crashes with
> "terminate called after throwing an instance of 'DOM::DOMException'".
> Firstly, is this intended behaviour? 

I don't think so.

> Secondly, is there any way that I can 
> check if the return value from that call is a valid object? 

Try accessing some method of the object, I suppose (you can also check its 
Python type, of course, but that only tells you what Python thinks the object 
is).

I'd suggest posting a short example program that demonstrates the problem 
(include the html necessary to cause it too).

Most of this stuff is straightforward sip wrappers - meaning sip generates the 
code the same as for any other C++ class, and there isn't anything unusual or 
customized that I can see. That suggests the most likely problem is in the 
implementation you're doing - the commonest problem is not keeping a Python 
reference to an object you're trying to access, for example.

However the khtml, and especially DOM, stuff hasn't gotten a lot of use, and I 
have no application code to test it with, so problems either in PyKDE or the 
underlying KDE code are quite possible too.

Either way, an example would be useful to see what's happening.

Jim


> Maybe there is 
> something you can do with the sip module? (though I can't see anything in
> the docs)
>
> Thanks,
> Paul
>
> _______________________________________________
> PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde




More information about the PyQt mailing list