Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PythonShellExtension(Extension):
- """Interactive Python shell"""
- def __init__(self):
- super().__init__("python shell")
- self.locals = dict()
- def exec_command(self, args=""):
- """starts an interactive shell (using exec)"""
- if args:
- try:
- exec(args, self.locals, globals())
- self.debugger.log("OK")
- except Exception as e:
- self.debugger.log(f"Error {e}")
- return
- self.debugger.log("Starting interactive shell. Type 'quit' to exit")
- while True:
- i = input("(exec)")
- if i in "quit" and "quit" in i:
- return
- try:
- exec(i, self.locals, globals())
- self.debugger.log("OK")
- except Exception as e:
- self.debugger.log(f"Error {e}")
- self.debugger.log("Type 'quit' to exit interactive shell!")
- def shell_command(self, args=""):
- """starts an interactive python shell (using eval)"""
- if args:
- try:
- self.debugger.log(repr(eval(args, self.locals, globals())))
- except Exception as e:
- self.debugger.log(f"Error {e}")
- return
- self.debugger.log("Starting interactive shell. Type 'quit' to exit")
- while True:
- i = input("(eval)")
- if i in "quit" and "quit" in i:
- return
- try:
- self.debugger.log(repr(eval(i, self.locals, globals())))
- except Exception as e:
- self.debugger.log(f"Error {e}")
- self.debugger.log("Type 'quit' to exit interactive shell!")
- ext = PythonShellExtension()
- debugger.extensions[ext.name] = ext
- ext.enable(debugger)
- debugger.log("[python shell]: Extension loaded successfully!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement