mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
A few more fixes for python 3 affecting libxml2.py
need a few changes to the generator and the libxml.py stub
This commit is contained in:
@ -1038,10 +1038,9 @@ def buildWrappers():
|
|||||||
classes.write(" def __init__(self, _obj=None):\n")
|
classes.write(" def __init__(self, _obj=None):\n")
|
||||||
if classes_ancestor[classname] == "xmlCore" or \
|
if classes_ancestor[classname] == "xmlCore" or \
|
||||||
classes_ancestor[classname] == "xmlNode":
|
classes_ancestor[classname] == "xmlNode":
|
||||||
classes.write(" if type(_obj).__name__ != ")
|
classes.write(" if checkWrapper(_obj) != 0:")
|
||||||
classes.write("'PyCObject':\n")
|
classes.write(" raise TypeError")
|
||||||
classes.write(" raise TypeError, ")
|
classes.write("('%s got a wrong wrapper object type')\n" % \
|
||||||
classes.write("'%s needs a PyCObject argument'\n" % \
|
|
||||||
classname)
|
classname)
|
||||||
if classname in reference_keepers:
|
if classname in reference_keepers:
|
||||||
rlist = reference_keepers[classname]
|
rlist = reference_keepers[classname]
|
||||||
@ -1054,7 +1053,7 @@ def buildWrappers():
|
|||||||
classes_ancestor[classname] == "xmlNode":
|
classes_ancestor[classname] == "xmlNode":
|
||||||
classes.write(" def __repr__(self):\n")
|
classes.write(" def __repr__(self):\n")
|
||||||
format = "<%s (%%s) object at 0x%%x>" % (classname)
|
format = "<%s (%%s) object at 0x%%x>" % (classname)
|
||||||
classes.write(" return \"%s\" %% (self.name, long(pos_id (self)))\n\n" % (
|
classes.write(" return \"%s\" %% (self.name, int(pos_id (self)))\n\n" % (
|
||||||
format))
|
format))
|
||||||
else:
|
else:
|
||||||
txt.write("Class %s()\n" % (classname))
|
txt.write("Class %s()\n" % (classname))
|
||||||
|
@ -5,6 +5,16 @@ import sys
|
|||||||
# The root of all libxml2 errors.
|
# The root of all libxml2 errors.
|
||||||
class libxmlError(Exception): pass
|
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 ...
|
# id() is sometimes negative ...
|
||||||
#
|
#
|
||||||
@ -62,9 +72,18 @@ class ioWrapper:
|
|||||||
def io_read(self, len = -1):
|
def io_read(self, len = -1):
|
||||||
if self.__io == None:
|
if self.__io == None:
|
||||||
return(-1)
|
return(-1)
|
||||||
|
try:
|
||||||
if len < 0:
|
if len < 0:
|
||||||
return(self.__io.read())
|
ret = self.__io.read()
|
||||||
return(self.__io.read(len))
|
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):
|
def io_write(self, str, len = -1):
|
||||||
if self.__io == None:
|
if self.__io == None:
|
||||||
@ -97,10 +116,17 @@ class ioWriteWrapper(ioWrapper):
|
|||||||
if type(_obj) == type(''):
|
if type(_obj) == type(''):
|
||||||
print("write io from a string")
|
print("write io from a string")
|
||||||
self.o = None
|
self.o = None
|
||||||
elif type(_obj) == types.InstanceType:
|
elif type(_obj).__name__ == 'PyCapsule':
|
||||||
print("write io from instance of %s" % (_obj.__class__))
|
file = libxml2mod.outputBufferGetPythonFile(_obj)
|
||||||
|
if file != None:
|
||||||
|
ioWrapper.__init__(self, file)
|
||||||
|
else:
|
||||||
ioWrapper.__init__(self, _obj)
|
ioWrapper.__init__(self, _obj)
|
||||||
self._o = libxml2mod.xmlCreateOutputBuffer(self, enc)
|
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:
|
else:
|
||||||
file = libxml2mod.outputBufferGetPythonFile(_obj)
|
file = libxml2mod.outputBufferGetPythonFile(_obj)
|
||||||
if file != None:
|
if file != None:
|
||||||
|
Reference in New Issue
Block a user