def cli(container, no_name, pretty, stdin): # TODO: -i, -t, -d as added options that override the inspection if container: ins = Inspector(container, no_name, pretty) ins.inspect() print(ins.format_cli()) elif stdin: ins = Inspector() ins.pretty = pretty raw_json = click.get_text_stream('stdin').read() ins.set_facts(raw_json) print(ins.format_cli()) else: raise click.UsageError("usage error")
class Tracer: """ Traces python source and analyses its state after each instruction. """ def __init__(self, trace: dict): self._filename = '<script>' self._source = trace['source'] self._input = trace['input'].splitlines() self._steps = trace['steps'] self._inspector = Inspector() self._result = None self._current_step = 0 self._input_index = 0 self._missing_input = False self._exec_call_frame = None # base frame (exec function call) self._print_cache = [] def run(self): self._result = {"steps": []} globals = scope.sandbox_globals(self._filename) globals['__builtins__']['input'] = HookedInput(self._input_hook) globals['__builtins__']['print'] = HookedPrint(self._print_hook) try: compiled = compile(self._source, self._filename, 'exec') sys.settrace(self._trace) exec(compiled, globals) except TracerStopException as e: # UserWarning is generated by the tracer to stop (the only way to stop it) # These exceptions are not caused by the application, hence they use the cause field instead of exception self._result["steps"].append({'threw': {'cause': str(e)}}) pass except Exception as e: # Exceptions that caused the source program stop or the tracer program # They can be clearly distincted by their tracebacks self._result["steps"].append({'threw': {'exception': dump_exception(e, remove_lines=(1,))}}) finally: sys.settrace(None) return self._result def _trace(self, frame: types.FrameType, event: str, args): if not frame.f_code.co_filename == self._filename or not event in {'call', 'line', 'exception', 'return'}: return self._trace if self._exec_call_frame is None: self._exec_call_frame = frame.f_back self._current_step += 1 if self._current_step > self._steps: raise TracerStopException(f'reached maximum step: {self._steps}') if self._missing_input: raise TracerStopException('input not enough') self._result["steps"].append({ 'snapshot': self._inspector.inspect(frame, event, args, self._exec_call_frame), 'prints': self._print_cache }) self._print_cache = [] return self._trace def _input_hook(self, prompt: str): self._print_cache.append(prompt) if self._input_index < len(self._input): self._input_index += 1 return self._input[self._input_index - 1] self._missing_input = True return None def _print_hook(self, text: str): self._print_cache.append(text)
def cli(container, no_name, pretty, publish_all, memory_limit): # TODO: -i, -t, -d as added options that override the inspection ins = Inspector(container, no_name, pretty, publish_all, memory_limit) ins.inspect() print(ins.format_cli())
def cli(container, no_name, pretty): # TODO: -i, -t, -d as added options that override the inspection ins = Inspector(container, no_name, pretty) ins.inspect() print(ins.format_cli())
import sys import os from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * sys.path.append( os.path.dirname(os.path.realpath(__file__)) + '/../../anki-web-browser') sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/../src') import anki_web_browser.browser as brw from controller import Controller from inspector import Inspector def wiki(self): print('Load') self.load(QUrl('https://en.wikipedia.org')) if __name__ == '__main__': print('Running Qt App') app = QApplication(sys.argv) web = brw.AwBrowser(None) # ctr = Controller(None) web.open('https://www.google.com/?q={}', 'my app test') # ctr.setupBindings(web._web) insp = Inspector(web) insp.inspect(web._web) web.show() sys.exit(app.exec_())