summaryrefslogtreecommitdiff
path: root/python/libxml.py
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@redhat.com>2013-03-29 15:17:40 +0800
committerDaniel Veillard <veillard@redhat.com>2013-03-30 22:33:06 +0800
commit6f18465189dbfdf6efb1e6580243918a4f609d1c (patch)
tree3a68061ac25987ced41e736c4312fc850029f910 /python/libxml.py
parent3798c4adbb91f80bef1e9f1b4b61dae72577a244 (diff)
downloadlibxml2-6f18465189dbfdf6efb1e6580243918a4f609d1c.tar.gz
A few more fixes for python 3 affecting libxml2.py
need a few changes to the generator and the libxml.py stub
Diffstat (limited to 'python/libxml.py')
-rw-r--r--python/libxml.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/python/libxml.py b/python/libxml.py
index 43ad49d0..b6349820 100644
--- a/python/libxml.py
+++ b/python/libxml.py
@@ -5,6 +5,16 @@ import sys
# The root of all libxml2 errors.
class libxmlError(Exception): pass
+# Type of the wrapper class for the C objects wrappers
+def checkWrapper(obj):
+ try:
+ n = type(_obj).__name__
+ if n != 'PyCObject' and n != 'PyCapsule':
+ return 1
+ except:
+ return 0
+ return 0
+
#
# id() is sometimes negative ...
#
@@ -62,9 +72,18 @@ class ioWrapper:
def io_read(self, len = -1):
if self.__io == None:
return(-1)
- if len < 0:
- return(self.__io.read())
- return(self.__io.read(len))
+ try:
+ if len < 0:
+ ret = self.__io.read()
+ else:
+ ret = self.__io.read(len)
+ except Exception as e:
+ print("failed to read from Python:", type(e))
+ print("on IO:", self.__io)
+ self.__io == None
+ return(-1)
+
+ return(ret)
def io_write(self, str, len = -1):
if self.__io == None:
@@ -97,10 +116,17 @@ class ioWriteWrapper(ioWrapper):
if type(_obj) == type(''):
print("write io from a string")
self.o = None
- elif type(_obj) == types.InstanceType:
- print("write io from instance of %s" % (_obj.__class__))
- ioWrapper.__init__(self, _obj)
- self._o = libxml2mod.xmlCreateOutputBuffer(self, enc)
+ elif type(_obj).__name__ == 'PyCapsule':
+ file = libxml2mod.outputBufferGetPythonFile(_obj)
+ if file != None:
+ ioWrapper.__init__(self, file)
+ else:
+ ioWrapper.__init__(self, _obj)
+ self._o = _obj
+# elif type(_obj) == types.InstanceType:
+# print(("write io from instance of %s" % (_obj.__class__)))
+# ioWrapper.__init__(self, _obj)
+# self._o = libxml2mod.xmlCreateOutputBuffer(self, enc)
else:
file = libxml2mod.outputBufferGetPythonFile(_obj)
if file != None: