List Info

Thread: help! python wrapper for the xslt loader API




help! python wrapper for the xslt loader API
user name
2006-09-06 00:38:06
I've knocked up a patch for python wrapping the xslt loader
API. 

My patch facilitates writing loaders in python.

But I'm having problems getting the xmlDocPtr back from a
python
function.

The task is more complex than it would first appear because
it is
necessary to have python use the current parserContext so
the intern
dictionaries can be retained. 

The trouble is the parserContext functions handling context
attached
parsing clear the document from the parserContext after
they've parsed
it. So the python has to _return_ the doc.


I've got code like this:

        ctxtobj = libxml_xmlParserCtxtPtrWrap(pctxt);
        result =
PyObject_CallFunction(pythonDocLoaderObject, 
                                       (char *)
"(sO)", URI, ctxtobj);
	Py_XDECREF(ctxtobj);

        // The return value should be the document
        // 
        // libxml2/parser.c:mlDoR
ead sets the parserContext's doc member to NULL
        // otherwise we could simply use that.
        if (result != NULL) {
            doc = PyxmlNode_Get(result);
        }


When I do this I don't seem to get a valid doc.

The python I'm using is:

 def fn(url, ctx):
    try:
        # print url
        ctxt = libxml2.parserCtxt(_obj=ctx)
        doc = ctxt.ctxtReadDoc("""<?xml
version='1.0'?><b/>""", url,
"UTF-8", 0)
        return doc
    except Exception, e:
        print >>sys.stderr, "something went
wrong:", e
        return None

The return value of ctxtReadDoc is a PyCObject wrapped
xmlDocPtr so I
presumed that I'd just be able to access it with
PyxmlNode_Get. But as
I say... this is not so.


Anybody know what mantra I need to get at the doc object
returned from
python in this instance?

-- 
Nic Ferrier
http://www.tapsellfer
rier.co.uk   for all your tapsell ferrier needs
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
help! python wrapper for the xslt loader API
user name
2006-09-06 02:11:13
On Wed, Sep 06, 2006 at 01:38:06AM +0100, Nic James Ferrier
wrote:
> I've knocked up a patch for python wrapping the xslt
loader API. 
> 
> My patch facilitates writing loaders in python.
> 
> But I'm having problems getting the xmlDocPtr back
from a python
> function.
[...]
> When I do this I don't seem to get a valid doc.
> 
> The python I'm using is:
> 
>  def fn(url, ctx):
>     try:
>         # print url
>         ctxt = libxml2.parserCtxt(_obj=ctx)
>         doc =
ctxt.ctxtReadDoc("""<?xml
version='1.0'?><b/>""", url,
"UTF-8", 0)
>         return doc

  The C object wrapper is in doc._o, maybe you don't want
to have the function
return it, in that case at the C level you may have to grab
the _o 
>     except Exception, e:
>         print >>sys.stderr, "something went
wrong:", e
>         return None
> 
> The return value of ctxtReadDoc is a PyCObject wrapped
xmlDocPtr so I
> presumed that I'd just be able to access it with
PyxmlNode_Get. But as
> I say... this is not so.

  I think there is one more layer  sorry for
the complexity ...

> 
> Anybody know what mantra I need to get at the doc
object returned from
> python in this instance?

  lookup the _o, see libxml2.py especially the xmlDoc
constructor.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/v
irtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillardredhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ |
Rpmfind RPM search engine  http://rpmfind.net/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
help! python wrapper for the xslt loader API
user name
2006-09-06 11:23:13
Daniel Veillard <veillardredhat.com> writes:

>   The C object wrapper is in doc._o, maybe you don't
want to have the function
> return it, in that case at the C level you may have to
grab the _o 

Ok. That works. Thanks.


-- 
Nic Ferrier
http://www.tapsellfer
rier.co.uk   for all your tapsell ferrier needs
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )