def handle_runQuickAnalysis(self): results = '' results_io = StringIO() if not self.qlock.tryLock(): self.framework.debug_log( 'failed to acquire lock for quick analysis') else: original_stdout = sys.stdout sys.stdout = results_io try: python_code = str(self.python_code) scriptLoader = ScriptLoader() global_ns = local_ns = {} script_env = scriptLoader.load_from_string( python_code, global_ns, local_ns) begin_method = script_env.functions.get('begin') if begin_method: res = begin_method() if res: self.append_results(results_io, res) process_request_method = script_env.functions.get( 'process_request') if not process_request_method: raise Exception( 'The "process_request" method is not implemented and is required.' ) factory = RequestResponseFactory.RequestResponseFactory( self.framework, None) for row in self.Data.read_all_responses(self.read_cursor): try: rr = factory.fill_by_row(row) res = process_request_method(rr) if res: self.append_results(results_io, res) except Exception as e: results += '\nEncountered processing error: %s' % (e) end_method = script_env.functions.get('end') if end_method: res = end_method() if res: self.append_results(results_io, res) except Exception as error: self.framework.report_exception(error) results += '\nEncountered processing error: %s' % (error) finally: sys.stdout = original_stdout self.qlock.unlock() if self.callback_object: if results: results += '\n' results += results_io.getvalue() self.callback_object.emit( SIGNAL('runQuickAnalysisFinished(QString)'), results)
def handle_runQuickAnalysis(self): results = '' results_io = StringIO() if not self.qlock.tryLock(): self.framework.debug_log('failed to acquire lock for quick analysis') else: original_stdout = sys.stdout sys.stdout = results_io try: python_code = str(self.python_code) scriptLoader = ScriptLoader() global_ns = local_ns = {} script_env = scriptLoader.load_from_string(python_code, global_ns, local_ns) begin_method = script_env.functions.get('begin') if begin_method: res = begin_method() if res: self.append_results(results_io, res) process_request_method = script_env.functions.get('process_request') if not process_request_method: raise Exception('The "process_request" method is not implemented and is required.') factory = RequestResponseFactory.RequestResponseFactory(self.framework, None) for row in self.Data.read_all_responses(self.read_cursor): try: rr = factory.fill_by_row(row) res = process_request_method(rr) if res: self.append_results(results_io, res) except Exception as e: results += '\nEncountered processing error: %s' % (e) end_method = script_env.functions.get('end') if end_method: res = end_method() if res: self.append_results(results_io, res) except Exception as error: self.framework.report_exception(error) results += '\nEncountered processing error: %s' % (error) finally: sys.stdout = original_stdout self.qlock.unlock() if self.callback_object: if results: results += '\n' results += results_io.getvalue() self.callback_object.emit(SIGNAL('runQuickAnalysisFinished(QString)'), results)