def recover(self):
        logger.warning('Trying to recover invalid XML...')
        originalXML = None
        fixedXML = None
        try:
            originalXML = tempfile.NamedTemporaryFile(suffix='.xml', delete=False) #bunzipped tmp
            fixedXML = tempfile.NamedTemporaryFile(suffix='.xml', delete=False) #fixed tmp
            fixedXML.close()

            #Fetch uncompressed file data to recover
            bzf = self._input.getByteStream()
            bzf.seek(0)
            shutil.copyfileobj(bzf, originalXML)
            originalXML.close()

            cmd = ['tidy', '-xml', '-o', fixedXML.name, originalXML.name]
            logger.warning('Running: %s', ' '.join(cmd))
            ret = subprocess.call(cmd)
            if ret:
                #raise Exception('Failed to fix XML data, ret=%s' % ret)
                pass

            #ready to load
            self.close()
            self._file = file(fixedXML.name, 'r')
            self._input = InputSource(fixedXML.name)
            self._input.setByteStream(self._file)
            self._cursor = self._conn.cursor()
            self.success = self._closed = False
            self.reset()
            self._add_rules()
            self.load()
        finally:
            for f in [originalXML, fixedXML]:
                if f and not f.closed:
                    f.close()
                if f and os.path.exists(f.name):
                    os.unlink(f.name)
Help for defer.
dataset/ETHPy150Open lalinsky/acoustid-server/scripts/acoustid_sync.py/DataImporter.recover--crossover with--dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/web/test/test_xmlrpc.py/Test.xmlrpc_defer