|
Packit |
21b7a2 |
/*
|
|
Packit |
21b7a2 |
* types.c: converter functions between the internal representation
|
|
Packit |
21b7a2 |
* and the Python objects
|
|
Packit |
21b7a2 |
*
|
|
Packit |
21b7a2 |
* See Copyright for the status of this software.
|
|
Packit |
21b7a2 |
*
|
|
Packit |
21b7a2 |
* daniel@veillard.com
|
|
Packit |
21b7a2 |
*/
|
|
Packit |
21b7a2 |
#include "libxml_wrap.h"
|
|
Packit |
21b7a2 |
#include <libxml/xpathInternals.h>
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#if PY_MAJOR_VERSION >= 3
|
|
Packit |
21b7a2 |
#define PY_IMPORT_STRING_SIZE PyUnicode_FromStringAndSize
|
|
Packit |
21b7a2 |
#define PY_IMPORT_STRING PyUnicode_FromString
|
|
Packit |
21b7a2 |
#define PY_IMPORT_INT PyLong_FromLong
|
|
Packit |
21b7a2 |
#else
|
|
Packit |
21b7a2 |
#define PY_IMPORT_STRING_SIZE PyString_FromStringAndSize
|
|
Packit |
21b7a2 |
#define PY_IMPORT_STRING PyString_FromString
|
|
Packit |
21b7a2 |
#define PY_IMPORT_INT PyInt_FromLong
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#if PY_MAJOR_VERSION >= 3
|
|
Packit |
21b7a2 |
#include <stdio.h>
|
|
Packit |
21b7a2 |
#include <unistd.h>
|
|
Packit |
21b7a2 |
#include <fcntl.h>
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
FILE *
|
|
Packit |
21b7a2 |
libxml_PyFileGet(PyObject *f) {
|
|
Packit |
21b7a2 |
int fd, flags;
|
|
Packit |
21b7a2 |
FILE *res;
|
|
Packit |
21b7a2 |
const char *mode;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
fd = PyObject_AsFileDescriptor(f);
|
|
Packit |
21b7a2 |
if (!_PyVerify_fd(fd))
|
|
Packit |
21b7a2 |
return(NULL);
|
|
Packit |
21b7a2 |
/*
|
|
Packit |
21b7a2 |
* Get the flags on the fd to understand how it was opened
|
|
Packit |
21b7a2 |
*/
|
|
Packit |
21b7a2 |
flags = fcntl(fd, F_GETFL, 0);
|
|
Packit |
21b7a2 |
switch (flags & O_ACCMODE) {
|
|
Packit |
21b7a2 |
case O_RDWR:
|
|
Packit |
21b7a2 |
if (flags & O_APPEND)
|
|
Packit |
21b7a2 |
mode = "a+";
|
|
Packit |
21b7a2 |
else
|
|
Packit |
21b7a2 |
mode = "rw";
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
case O_RDONLY:
|
|
Packit |
21b7a2 |
if (flags & O_APPEND)
|
|
Packit |
21b7a2 |
mode = "r+";
|
|
Packit |
21b7a2 |
else
|
|
Packit |
21b7a2 |
mode = "r";
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
case O_WRONLY:
|
|
Packit |
21b7a2 |
if (flags & O_APPEND)
|
|
Packit |
21b7a2 |
mode = "a";
|
|
Packit |
21b7a2 |
else
|
|
Packit |
21b7a2 |
mode = "w";
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
default:
|
|
Packit |
21b7a2 |
return(NULL);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
/*
|
|
Packit |
21b7a2 |
* the FILE struct gets a new fd, so that it can be closed
|
|
Packit |
21b7a2 |
* independently of the file descriptor given. The risk though is
|
|
Packit |
21b7a2 |
* lack of sync. So at the python level sync must be implemented
|
|
Packit |
21b7a2 |
* before and after a conversion took place. No way around it
|
|
Packit |
21b7a2 |
* in the Python3 infrastructure !
|
|
Packit |
21b7a2 |
* The duplicated fd and FILE * will be released in the subsequent
|
|
Packit |
21b7a2 |
* call to libxml_PyFileRelease() which must be genrated accodingly
|
|
Packit |
21b7a2 |
*/
|
|
Packit |
21b7a2 |
fd = dup(fd);
|
|
Packit |
21b7a2 |
if (fd == -1)
|
|
Packit |
21b7a2 |
return(NULL);
|
|
Packit |
21b7a2 |
res = fdopen(fd, mode);
|
|
Packit |
21b7a2 |
if (res == NULL) {
|
|
Packit |
21b7a2 |
close(fd);
|
|
Packit |
21b7a2 |
return(NULL);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
return(res);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
void libxml_PyFileRelease(FILE *f) {
|
|
Packit |
21b7a2 |
if (f != NULL)
|
|
Packit |
21b7a2 |
fclose(f);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_intWrap(int val)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_intWrap: val = %d\n", val);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_INT((long) val);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_longWrap(long val)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_longWrap: val = %ld\n", val);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
ret = PyLong_FromLong(val);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_doubleWrap(double val)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_doubleWrap: val = %f\n", val);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
ret = PyFloat_FromDouble((double) val);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_charPtrWrap(char *str)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlcharPtrWrap: str = %s\n", str);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (str == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_STRING(str);
|
|
Packit |
21b7a2 |
xmlFree(str);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_charPtrConstWrap(const char *str)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlcharPtrWrap: str = %s\n", str);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (str == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_STRING(str);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlCharPtrWrap(xmlChar * str)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlCharPtrWrap: str = %s\n", str);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (str == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_STRING((char *) str);
|
|
Packit |
21b7a2 |
xmlFree(str);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlCharPtrConstWrap(const xmlChar * str)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlCharPtrWrap: str = %s\n", str);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (str == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_STRING((char *) str);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_constcharPtrWrap(const char *str)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlcharPtrWrap: str = %s\n", str);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (str == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_STRING(str);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_constxmlCharPtrWrap(const xmlChar * str)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlCharPtrWrap: str = %s\n", str);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (str == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_STRING((char *) str);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlDocPtrWrap(xmlDocPtr doc)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlDocPtrWrap: doc = %p\n", doc);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (doc == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
/* TODO: look at deallocation */
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) doc, (char *) "xmlDocPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlNodePtrWrap(xmlNodePtr node)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlNodePtrWrap: node = %p\n", node);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (node == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) node, (char *) "xmlNodePtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlURIPtrWrap(xmlURIPtr uri)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlURIPtrWrap: uri = %p\n", uri);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (uri == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) uri, (char *) "xmlURIPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlNsPtrWrap(xmlNsPtr ns)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlNsPtrWrap: node = %p\n", ns);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (ns == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) ns, (char *) "xmlNsPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlAttrPtrWrap(xmlAttrPtr attr)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlAttrNodePtrWrap: attr = %p\n", attr);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (attr == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) attr, (char *) "xmlAttrPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlAttributePtrWrap(xmlAttributePtr attr)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlAttributePtrWrap: attr = %p\n", attr);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (attr == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) attr, (char *) "xmlAttributePtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlElementPtrWrap(xmlElementPtr elem)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlElementNodePtrWrap: elem = %p\n", elem);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (elem == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) elem, (char *) "xmlElementPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlXPathContextPtrWrap: ctxt = %p\n", ctxt);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (ctxt == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) ctxt, (char *) "xmlXPathContextPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlXPathParserContextPtrWrap: ctxt = %p\n", ctxt);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (ctxt == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *)ctxt, (char *)"xmlXPathParserContextPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlParserCtxtPtrWrap: ctxt = %p\n", ctxt);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (ctxt == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) ctxt, (char *) "xmlParserCtxtPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
/**
|
|
Packit |
21b7a2 |
* libxml_xmlXPathDestructNsNode:
|
|
Packit |
21b7a2 |
* cap: xmlNsPtr namespace node capsule object
|
|
Packit |
21b7a2 |
*
|
|
Packit |
21b7a2 |
* This function is called if and when a namespace node returned in
|
|
Packit |
21b7a2 |
* an XPath node set is to be destroyed. That's the only kind of
|
|
Packit |
21b7a2 |
* object returned in node set not directly linked to the original
|
|
Packit |
21b7a2 |
* xmlDoc document, see xmlXPathNodeSetDupNs.
|
|
Packit |
21b7a2 |
*/
|
|
Packit |
21b7a2 |
#if PY_VERSION_HEX < 0x02070000
|
|
Packit |
21b7a2 |
static void
|
|
Packit |
21b7a2 |
libxml_xmlXPathDestructNsNode(void *cap, void *desc ATTRIBUTE_UNUSED)
|
|
Packit |
21b7a2 |
#else
|
|
Packit |
21b7a2 |
static void
|
|
Packit |
21b7a2 |
libxml_xmlXPathDestructNsNode(PyObject *cap)
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
fprintf(stderr, "libxml_xmlXPathDestructNsNode called %p\n", cap);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
#if PY_VERSION_HEX < 0x02070000
|
|
Packit |
21b7a2 |
xmlXPathNodeSetFreeNs((xmlNsPtr) cap);
|
|
Packit |
21b7a2 |
#else
|
|
Packit |
21b7a2 |
xmlXPathNodeSetFreeNs((xmlNsPtr) PyCapsule_GetPointer(cap, "xmlNsPtr"));
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlXPathObjectPtrWrap: ctxt = %p\n", obj);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (obj == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
switch (obj->type) {
|
|
Packit |
21b7a2 |
case XPATH_XSLT_TREE: {
|
|
Packit |
21b7a2 |
if ((obj->nodesetval == NULL) ||
|
|
Packit |
21b7a2 |
(obj->nodesetval->nodeNr == 0) ||
|
|
Packit |
21b7a2 |
(obj->nodesetval->nodeTab == NULL)) {
|
|
Packit |
21b7a2 |
ret = PyList_New(0);
|
|
Packit |
21b7a2 |
} else {
|
|
Packit |
21b7a2 |
int i, len = 0;
|
|
Packit |
21b7a2 |
xmlNodePtr node;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
node = obj->nodesetval->nodeTab[0]->children;
|
|
Packit |
21b7a2 |
while (node != NULL) {
|
|
Packit |
21b7a2 |
len++;
|
|
Packit |
21b7a2 |
node = node->next;
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyList_New(len);
|
|
Packit |
21b7a2 |
node = obj->nodesetval->nodeTab[0]->children;
|
|
Packit |
21b7a2 |
for (i = 0;i < len;i++) {
|
|
Packit |
21b7a2 |
PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node));
|
|
Packit |
21b7a2 |
node = node->next;
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
/*
|
|
Packit |
21b7a2 |
* Return now, do not free the object passed down
|
|
Packit |
21b7a2 |
*/
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
case XPATH_NODESET:
|
|
Packit |
21b7a2 |
if ((obj->nodesetval == NULL)
|
|
Packit |
21b7a2 |
|| (obj->nodesetval->nodeNr == 0)) {
|
|
Packit |
21b7a2 |
ret = PyList_New(0);
|
|
Packit |
21b7a2 |
} else {
|
|
Packit |
21b7a2 |
int i;
|
|
Packit |
21b7a2 |
xmlNodePtr node;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
ret = PyList_New(obj->nodesetval->nodeNr);
|
|
Packit |
21b7a2 |
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
|
Packit |
21b7a2 |
node = obj->nodesetval->nodeTab[i];
|
|
Packit |
21b7a2 |
if (node->type == XML_NAMESPACE_DECL) {
|
|
Packit |
21b7a2 |
PyObject *ns = PyCapsule_New((void *) node,
|
|
Packit |
21b7a2 |
(char *) "xmlNsPtr",
|
|
Packit |
21b7a2 |
libxml_xmlXPathDestructNsNode);
|
|
Packit |
21b7a2 |
PyList_SetItem(ret, i, ns);
|
|
Packit |
21b7a2 |
/* make sure the xmlNsPtr is not destroyed now */
|
|
Packit |
21b7a2 |
obj->nodesetval->nodeTab[i] = NULL;
|
|
Packit |
21b7a2 |
} else {
|
|
Packit |
21b7a2 |
PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node));
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
case XPATH_BOOLEAN:
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_INT((long) obj->boolval);
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
case XPATH_NUMBER:
|
|
Packit |
21b7a2 |
ret = PyFloat_FromDouble(obj->floatval);
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
case XPATH_STRING:
|
|
Packit |
21b7a2 |
ret = PY_IMPORT_STRING((char *) obj->stringval);
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
case XPATH_POINT:
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *node;
|
|
Packit |
21b7a2 |
PyObject *indexIntoNode;
|
|
Packit |
21b7a2 |
PyObject *tuple;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
node = libxml_xmlNodePtrWrap(obj->user);
|
|
Packit |
21b7a2 |
indexIntoNode = PY_IMPORT_INT((long) obj->index);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
tuple = PyTuple_New(2);
|
|
Packit |
21b7a2 |
PyTuple_SetItem(tuple, 0, node);
|
|
Packit |
21b7a2 |
PyTuple_SetItem(tuple, 1, indexIntoNode);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
ret = tuple;
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
case XPATH_RANGE:
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
unsigned short bCollapsedRange;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
bCollapsedRange = ( (obj->user2 == NULL) ||
|
|
Packit |
21b7a2 |
((obj->user2 == obj->user) && (obj->index == obj->index2)) );
|
|
Packit |
21b7a2 |
if ( bCollapsedRange ) {
|
|
Packit |
21b7a2 |
PyObject *node;
|
|
Packit |
21b7a2 |
PyObject *indexIntoNode;
|
|
Packit |
21b7a2 |
PyObject *tuple;
|
|
Packit |
21b7a2 |
PyObject *list;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
list = PyList_New(1);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
node = libxml_xmlNodePtrWrap(obj->user);
|
|
Packit |
21b7a2 |
indexIntoNode = PY_IMPORT_INT((long) obj->index);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
tuple = PyTuple_New(2);
|
|
Packit |
21b7a2 |
PyTuple_SetItem(tuple, 0, node);
|
|
Packit |
21b7a2 |
PyTuple_SetItem(tuple, 1, indexIntoNode);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyList_SetItem(list, 0, tuple);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
ret = list;
|
|
Packit |
21b7a2 |
} else {
|
|
Packit |
21b7a2 |
PyObject *node;
|
|
Packit |
21b7a2 |
PyObject *indexIntoNode;
|
|
Packit |
21b7a2 |
PyObject *tuple;
|
|
Packit |
21b7a2 |
PyObject *list;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
list = PyList_New(2);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
node = libxml_xmlNodePtrWrap(obj->user);
|
|
Packit |
21b7a2 |
indexIntoNode = PY_IMPORT_INT((long) obj->index);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
tuple = PyTuple_New(2);
|
|
Packit |
21b7a2 |
PyTuple_SetItem(tuple, 0, node);
|
|
Packit |
21b7a2 |
PyTuple_SetItem(tuple, 1, indexIntoNode);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyList_SetItem(list, 0, tuple);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
node = libxml_xmlNodePtrWrap(obj->user2);
|
|
Packit |
21b7a2 |
indexIntoNode = PY_IMPORT_INT((long) obj->index2);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
tuple = PyTuple_New(2);
|
|
Packit |
21b7a2 |
PyTuple_SetItem(tuple, 0, node);
|
|
Packit |
21b7a2 |
PyTuple_SetItem(tuple, 1, indexIntoNode);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyList_SetItem(list, 1, tuple);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
ret = list;
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
case XPATH_LOCATIONSET:
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
xmlLocationSetPtr set;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
set = obj->user;
|
|
Packit |
21b7a2 |
if ( set && set->locNr > 0 ) {
|
|
Packit |
21b7a2 |
int i;
|
|
Packit |
21b7a2 |
PyObject *list;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
list = PyList_New(set->locNr);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
for (i=0; i<set->locNr; i++) {
|
|
Packit |
21b7a2 |
xmlXPathObjectPtr setobj;
|
|
Packit |
21b7a2 |
PyObject *pyobj;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
setobj = set->locTab[i]; /*xmlXPathObjectPtr setobj*/
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
pyobj = libxml_xmlXPathObjectPtrWrap(setobj);
|
|
Packit |
21b7a2 |
/* xmlXPathFreeObject(setobj) is called */
|
|
Packit |
21b7a2 |
set->locTab[i] = NULL;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyList_SetItem(list, i, pyobj);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
set->locNr = 0;
|
|
Packit |
21b7a2 |
ret = list;
|
|
Packit |
21b7a2 |
} else {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
ret = Py_None;
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
break;
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
default:
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("Unable to convert XPath object type %d\n", obj->type);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
ret = Py_None;
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
xmlXPathFreeObject(obj);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
xmlXPathObjectPtr
|
|
Packit |
21b7a2 |
libxml_xmlXPathObjectPtrConvert(PyObject *obj)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
xmlXPathObjectPtr ret = NULL;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlXPathObjectPtrConvert: obj = %p\n", obj);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (obj == NULL) {
|
|
Packit |
21b7a2 |
return (NULL);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
if PyFloat_Check (obj) {
|
|
Packit |
21b7a2 |
ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
|
|
Packit |
21b7a2 |
} else if PyLong_Check(obj) {
|
|
Packit |
21b7a2 |
#ifdef PyLong_AS_LONG
|
|
Packit |
21b7a2 |
ret = xmlXPathNewFloat((double) PyLong_AS_LONG(obj));
|
|
Packit |
21b7a2 |
#else
|
|
Packit |
21b7a2 |
ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
#ifdef PyBool_Check
|
|
Packit |
21b7a2 |
} else if PyBool_Check (obj) {
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
if (obj == Py_True) {
|
|
Packit |
21b7a2 |
ret = xmlXPathNewBoolean(1);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
else {
|
|
Packit |
21b7a2 |
ret = xmlXPathNewBoolean(0);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
} else if PyBytes_Check (obj) {
|
|
Packit |
21b7a2 |
xmlChar *str;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
str = xmlStrndup((const xmlChar *) PyBytes_AS_STRING(obj),
|
|
Packit |
21b7a2 |
PyBytes_GET_SIZE(obj));
|
|
Packit |
21b7a2 |
ret = xmlXPathWrapString(str);
|
|
Packit |
21b7a2 |
#ifdef PyUnicode_Check
|
|
Packit |
21b7a2 |
} else if PyUnicode_Check (obj) {
|
|
Packit |
21b7a2 |
#if PY_VERSION_HEX >= 0x03030000
|
|
Packit |
21b7a2 |
xmlChar *str;
|
|
Packit |
21b7a2 |
const char *tmp;
|
|
Packit |
21b7a2 |
Py_ssize_t size;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
/* tmp doesn't need to be deallocated */
|
|
Packit |
21b7a2 |
tmp = PyUnicode_AsUTF8AndSize(obj, &size);
|
|
Packit |
21b7a2 |
str = xmlStrndup((const xmlChar *) tmp, (int) size);
|
|
Packit |
21b7a2 |
ret = xmlXPathWrapString(str);
|
|
Packit |
21b7a2 |
#else
|
|
Packit |
21b7a2 |
xmlChar *str = NULL;
|
|
Packit |
21b7a2 |
PyObject *b;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
b = PyUnicode_AsUTF8String(obj);
|
|
Packit |
21b7a2 |
if (b != NULL) {
|
|
Packit |
21b7a2 |
str = xmlStrndup((const xmlChar *) PyBytes_AS_STRING(b),
|
|
Packit |
21b7a2 |
PyBytes_GET_SIZE(b));
|
|
Packit |
21b7a2 |
Py_DECREF(b);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = xmlXPathWrapString(str);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
} else if PyList_Check (obj) {
|
|
Packit |
21b7a2 |
int i;
|
|
Packit |
21b7a2 |
PyObject *node;
|
|
Packit |
21b7a2 |
xmlNodePtr cur;
|
|
Packit |
21b7a2 |
xmlNodeSetPtr set;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
set = xmlXPathNodeSetCreate(NULL);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
for (i = 0; i < PyList_Size(obj); i++) {
|
|
Packit |
21b7a2 |
node = PyList_GetItem(obj, i);
|
|
Packit |
21b7a2 |
if ((node == NULL) || (node->ob_type == NULL))
|
|
Packit |
21b7a2 |
continue;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
cur = NULL;
|
|
Packit |
21b7a2 |
if (PyCapsule_CheckExact(node)) {
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("Got a Capsule\n");
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
cur = PyxmlNode_Get(node);
|
|
Packit |
21b7a2 |
} else if ((PyObject_HasAttrString(node, (char *) "_o")) &&
|
|
Packit |
21b7a2 |
(PyObject_HasAttrString(node, (char *) "get_doc"))) {
|
|
Packit |
21b7a2 |
PyObject *wrapper;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
wrapper = PyObject_GetAttrString(node, (char *) "_o");
|
|
Packit |
21b7a2 |
if (wrapper != NULL)
|
|
Packit |
21b7a2 |
cur = PyxmlNode_Get(wrapper);
|
|
Packit |
21b7a2 |
} else {
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("Unknown object in Python return list\n");
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
if (cur != NULL) {
|
|
Packit |
21b7a2 |
xmlXPathNodeSetAdd(set, cur);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = xmlXPathWrapNodeSet(set);
|
|
Packit |
21b7a2 |
} else {
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("Unable to convert Python Object to XPath");
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlValidCtxtPtrWrap: valid = %p\n", valid);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (valid == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) valid,
|
|
Packit |
21b7a2 |
(char *) "xmlValidCtxtPtr", NULL);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlCatalogPtrWrap(xmlCatalogPtr catal)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlNodePtrWrap: catal = %p\n", catal);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (catal == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) catal,
|
|
Packit |
21b7a2 |
(char *) "xmlCatalogPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlOutputBufferPtrWrap: buffer = %p\n", buffer);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (buffer == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) buffer,
|
|
Packit |
21b7a2 |
(char *) "xmlOutputBufferPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlParserInputBufferPtrWrap: buffer = %p\n", buffer);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (buffer == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) buffer,
|
|
Packit |
21b7a2 |
(char *) "xmlParserInputBufferPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef LIBXML_REGEXP_ENABLED
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlRegexpPtrWrap: regexp = %p\n", regexp);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (regexp == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) regexp,
|
|
Packit |
21b7a2 |
(char *) "xmlRegexpPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
#endif /* LIBXML_REGEXP_ENABLED */
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef LIBXML_READER_ENABLED
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlTextReaderPtrWrap: reader = %p\n", reader);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (reader == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) reader,
|
|
Packit |
21b7a2 |
(char *) "xmlTextReaderPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlTextReaderLocatorPtrWrap: locator = %p\n", locator);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (locator == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) locator,
|
|
Packit |
21b7a2 |
(char *) "xmlTextReaderLocatorPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
#endif /* LIBXML_READER_ENABLED */
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef LIBXML_SCHEMAS_ENABLED
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlRelaxNGPtrWrap: ctxt = %p\n", ctxt);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (ctxt == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) ctxt,
|
|
Packit |
21b7a2 |
(char *) "xmlRelaxNGPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlRelaxNGParserCtxtPtrWrap: ctxt = %p\n", ctxt);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (ctxt == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) ctxt,
|
|
Packit |
21b7a2 |
(char *) "xmlRelaxNGParserCtxtPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlRelaxNGValidCtxtPtrWrap: valid = %p\n", valid);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (valid == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) valid,
|
|
Packit |
21b7a2 |
(char *) "xmlRelaxNGValidCtxtPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlSchemaPtrWrap: ctxt = %p\n", ctxt);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (ctxt == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) ctxt,
|
|
Packit |
21b7a2 |
(char *) "xmlSchemaPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlSchemaParserCtxtPtrWrap: ctxt = %p\n", ctxt);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (ctxt == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) ctxt,
|
|
Packit |
21b7a2 |
(char *) "xmlSchemaParserCtxtPtr", NULL);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlSchemaValidCtxtPtrWrap: valid = %p\n", valid);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (valid == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
ret =
|
|
Packit |
21b7a2 |
PyCapsule_New((void *) valid,
|
|
Packit |
21b7a2 |
(char *) "xmlSchemaValidCtxtPtr", NULL);
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
#endif /* LIBXML_SCHEMAS_ENABLED */
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
PyObject *
|
|
Packit |
21b7a2 |
libxml_xmlErrorPtrWrap(xmlErrorPtr error)
|
|
Packit |
21b7a2 |
{
|
|
Packit |
21b7a2 |
PyObject *ret;
|
|
Packit |
21b7a2 |
|
|
Packit |
21b7a2 |
#ifdef DEBUG
|
|
Packit |
21b7a2 |
printf("libxml_xmlErrorPtrWrap: error = %p\n", error);
|
|
Packit |
21b7a2 |
#endif
|
|
Packit |
21b7a2 |
if (error == NULL) {
|
|
Packit |
21b7a2 |
Py_INCREF(Py_None);
|
|
Packit |
21b7a2 |
return (Py_None);
|
|
Packit |
21b7a2 |
}
|
|
Packit |
21b7a2 |
ret = PyCapsule_New((void *) error, (char *) "xmlErrorPtr", NULL);
|
|
Packit |
21b7a2 |
return (ret);
|
|
Packit |
21b7a2 |
}
|