def libxml2debug(testfunction):
 try:
  import libxml2
 except ImportError:
  return testfunction
 def newfunc(*args, **kwargs):
  libxml2.debugMemory(1)
  testfunction(*args, **kwargs)
  libxml2.cleanupParser()
  leaked_bytes = libxml2.debugMemory(0)
  assert (leaked_bytes == 0), ('libxml2 memory leak detected: %d bytes' % leaked_bytes)
 if ('LIBXML2_DEBUGLEAKS' in os.environ):
  return newfunc
 else:
  return testfunction

def libxml2debug ( testfunction ) : try : import libxml2 except ImportError : return testfunction def newfunc ( * args , ** kwargs ) : libxml2 . debugMemory ( 1 ) testfunction ( * args , ** kwargs ) libxml2 . cleanupParser ( ) leaked_bytes = libxml2 . debugMemory ( 0 ) assert ( leaked_bytes == 0 ) , ( 'libxml2 memory leak detected: %d bytes' % leaked_bytes ) if ( 'LIBXML2_DEBUGLEAKS' in os . environ ) : return newfunc else : return testfunction
decorator for debugging libxml2 memory leaks inside a function .