Advertisement
lolsalat

[AD] Python Shell

Dec 18th, 2020 (edited)
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. class PythonShellExtension(Extension):
  2.     """Interactive Python shell"""
  3.    
  4.     def __init__(self):
  5.         super().__init__("python shell")
  6.         self.locals = dict()
  7.  
  8.     def exec_command(self, args=""):
  9.          """starts an interactive shell (using exec)"""
  10.          if args:
  11.             try:
  12.                 exec(args, self.locals, globals())
  13.                 self.debugger.log("OK")
  14.             except Exception as e:
  15.                 self.debugger.log(f"Error {e}")
  16.             return
  17.          self.debugger.log("Starting interactive shell. Type 'quit' to exit")
  18.          while True:
  19.             i = input("(exec)")
  20.             if i in "quit" and "quit" in i:
  21.                 return
  22.             try:
  23.                 exec(i, self.locals, globals())
  24.                 self.debugger.log("OK")
  25.             except Exception as e:
  26.                 self.debugger.log(f"Error {e}")
  27.                 self.debugger.log("Type 'quit' to exit interactive shell!")
  28.  
  29.     def shell_command(self, args=""):
  30.         """starts an interactive python shell (using eval)"""
  31.         if args:
  32.             try:
  33.                 self.debugger.log(repr(eval(args, self.locals, globals())))
  34.             except Exception as e:
  35.                 self.debugger.log(f"Error {e}")
  36.             return
  37.         self.debugger.log("Starting interactive shell. Type 'quit' to exit")
  38.         while True:
  39.             i = input("(eval)")
  40.             if i in "quit" and "quit" in i:
  41.                 return
  42.             try:
  43.                 self.debugger.log(repr(eval(i, self.locals, globals())))
  44.             except Exception as e:
  45.                 self.debugger.log(f"Error {e}")
  46.                 self.debugger.log("Type 'quit' to exit interactive shell!")
  47.  
  48. ext = PythonShellExtension()
  49. debugger.extensions[ext.name] = ext
  50. ext.enable(debugger)
  51. debugger.log("[python shell]: Extension loaded successfully!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement