* by default erase the doc, with keepDoc argument you can keep self.doc
* try to make sure self.doc is deleted after self.unlink()
This commit is contained in:
+4
-4
@@ -378,7 +378,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
cls.__ne__ = notequal
|
cls.__ne__ = notequal
|
||||||
|
|
||||||
if xmlfile_support:
|
if xmlfile_support:
|
||||||
def read(self, filename, eraseDoc = False):
|
def read(self, filename, keepDoc = False):
|
||||||
"read XML file and decode it into a python object"
|
"read XML file and decode it into a python object"
|
||||||
self.readxml(filename)
|
self.readxml(filename)
|
||||||
errs = []
|
errs = []
|
||||||
@@ -389,7 +389,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
errs.append(_("autoxml.read: File '%s' has errors") % filename)
|
errs.append(_("autoxml.read: File '%s' has errors") % filename)
|
||||||
raise Error(*errs)
|
raise Error(*errs)
|
||||||
|
|
||||||
if eraseDoc:
|
if not keepDoc:
|
||||||
self.unlink() # get rid of the tree
|
self.unlink() # get rid of the tree
|
||||||
|
|
||||||
errs = self.errors()
|
errs = self.errors()
|
||||||
@@ -397,7 +397,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
errs.append(_("autoxml.read: File '%s' has errors") % filename)
|
errs.append(_("autoxml.read: File '%s' has errors") % filename)
|
||||||
raise Error(*errs)
|
raise Error(*errs)
|
||||||
|
|
||||||
def write(self, filename, eraseDoc = False):
|
def write(self, filename, keepDoc = False):
|
||||||
"encode the contents of the python object into an XML file"
|
"encode the contents of the python object into an XML file"
|
||||||
errs = self.errors()
|
errs = self.errors()
|
||||||
if errs:
|
if errs:
|
||||||
@@ -412,7 +412,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
errs.append(_("autoxml.write: File encoding '%s' has errors") % filename)
|
errs.append(_("autoxml.write: File encoding '%s' has errors") % filename)
|
||||||
raise Error(*errs)
|
raise Error(*errs)
|
||||||
self.writexml(filename)
|
self.writexml(filename)
|
||||||
if eraseDoc:
|
if not keepDoc:
|
||||||
self.unlink() # get rid of the tree
|
self.unlink() # get rid of the tree
|
||||||
|
|
||||||
cls.read = read
|
cls.read = read
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class XmlFile(object):
|
|||||||
def unlink(self):
|
def unlink(self):
|
||||||
"""deallocate DOM structure"""
|
"""deallocate DOM structure"""
|
||||||
self.doc.unlink()
|
self.doc.unlink()
|
||||||
|
del self.doc
|
||||||
|
|
||||||
def rootNode(self):
|
def rootNode(self):
|
||||||
"""returns root document element"""
|
"""returns root document element"""
|
||||||
|
|||||||
Reference in New Issue
Block a user