some improvement to Libxml2Document cleanup: avoid noisy errors, and make sure both cleaning up functions are called

This commit is contained in:
Pablo Hoffman 2009-07-14 12:41:25 -03:00
parent 7b149d821d
commit 167894661d
1 changed files with 11 additions and 3 deletions

View File

@ -12,11 +12,19 @@ class Libxml2Document(object):
self.xpathContext = self.xmlDoc.xpathNewContext()
def __del__(self):
if hasattr(self, 'xmlDoc'):
# we must call both cleanup functions, so we try/except all exceptions
# to make sure one doesn't prevent the other from being called
# this call sometimes raises a "NoneType is not callable" TypeError
# also, these calls sometimes raise a "NoneType is not callable"
# TypeError, so the try/except block silences them
try:
self.xmlDoc.freeDoc()
if hasattr(self, 'xpathContext'):
except:
pass
try:
self.xpathContext.xpathFreeContext()
except:
pass
def __str__(self):
return "<Libxml2Document %s>" % self.xmlDoc.name