1. stephan preeker
  2. gevent

Commits

Ralf Schmitt  committed 25b0ccb

make 'locals()' not spew out __builtin__.__dict__ in backdoor

__builtins__ may either be the __builtin__ module or
__builtin__.__dict__. in the latter case typing locals() at the
backdoor prompt spews out lots of useless stuff. In the former case it
just prints "{'__builtins__': <module '__builtin__' (built-in)>,..."

  • Participants
  • Parent commits a6da624
  • Branches default

Comments (0)

Files changed (2)

File gevent/backdoor.py

View file
         try:
             try:
                 console = InteractiveConsole(self.locals)
+                # __builtins__ may either be the __builtin__ module or
+                # __builtin__.__dict__ in the latter case typing
+                # locals() at the backdoor prompt spews out lots of
+                # useless stuff
+                import __builtin__
+                console.locals["__builtins__"] = __builtin__
                 console.interact(banner=self.banner)
             except SystemExit:  # raised by quit()
                 sys.exc_clear()

File greentest/test__backdoor.py

View file
         finally:
             server.stop()
 
+    def test_builtins(self):
+        server = backdoor.BackdoorServer(('127.0.0.1', 0))
+        server.start()
+        try:
+            conn = socket.create_connection(('127.0.0.1', server.server_port))
+            read_until(conn, '>>> ')
+            conn.sendall('locals()["__builtins__"]\r\n')
+            response = read_until(conn, '>>> ')
+            self.assertTrue(len(response) < 300, msg="locals() unusable: %s..." % response[:100])
+        finally:
+            server.stop()
+
 
 if __name__ == '__main__':
     greentest.main()