Re: [xslt] python saveResultToFile



On Sun, Mar 31, 2002 at 06:24:30AM -0500, Sam Brauer wrote:
> out = cStringIO.StringIO()
> style.saveResultToFile(out, result)

  This gives the following at the wrapper level:

Breakpoint 3, libxslt_xsltSaveResultToFile (self=0x0, args=0x80e65b8)
    at libxslt-py.c:1257
warning: Source file is more recent than executable.

1257	    PyObject *pyobj_style;
(gdb) n
1259	    if (!PyArg_ParseTuple(args, (char *)"OOO:xsltSaveResultToFile", &pyobj_file, &pyobj_result, &pyobj_style))
(gdb) 
1260	        return(NULL);
(gdb) 
1261	    file = (FILE *) PyFile_Get(pyobj_file);
(gdb) 
1263	    style = (xsltStylesheetPtr) Pystylesheet_Get(pyobj_style);
(gdb) 
1264	
(gdb) 
1265	    c_retval = xsltSaveResultToFile(file, result, style);
(gdb) p file
$1 = (FILE *) 0x0
(gdb) n 
1266	    py_retval = libxml_intWrap((int) c_retval);
(gdb) p c_retval
$2 = -1
(gdb) 


> 
> I also tried saving to a "normal" file (out = open("foo", "w")), and the 
> same thing happens. 

  Right and that I can't understand:

Breakpoint 3, libxslt_xsltSaveResultToFile (self=0x0, args=0x80e6648)
    at libxslt-py.c:1257
warning: Source file is more recent than executable.

1257	    PyObject *pyobj_style;
(gdb) n
1259	    if (!PyArg_ParseTuple(args, (char *)"OOO:xsltSaveResultToFile", &pyobj_file, &pyobj_result, &pyobj_style))
(gdb) 
1260	        return(NULL);
(gdb) 
1261	    file = (FILE *) PyFile_Get(pyobj_file);
(gdb) 
1263	    style = (xsltStylesheetPtr) Pystylesheet_Get(pyobj_style);
(gdb) p file
$3 = (FILE *) 0x0
(gdb) 

  PyFile_Get() consistently returns NULL, I have no idea why, because in
that case it is really a file based access. Use saveResultToFilename()
instead.

>  In other words, saveResultToFile() doesn't raise an 
> exception, but the file is empty.

  Well it returns -1 which is the error code as documented.


> Am I doing something wrong, or is this a bug?

  Seems a problem with PyFile_Get() in the Python interface.
The clean way would be to do an output driver for a Python File passed
to those interfaces and make callbacks at the Python level instead of
trying to access directly the object.

  You can try to use result.serialize() to get the string at the
python level. It may not be perfect from an XSLT standpoint though.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard@redhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]