[pypy-svn] r46419 - pypy/dist/pypy/translator/sandbox

arigo at codespeak.net arigo at codespeak.net
Sat Sep 8 12:20:24 CEST 2007


Author: arigo
Date: Sat Sep  8 12:20:23 2007
New Revision: 46419

Modified:
   pypy/dist/pypy/translator/sandbox/pypy_interact.py
   pypy/dist/pypy/translator/sandbox/sandlib.py
Log:
An option to log all interactive input sent to the sandboxed process.


Modified: pypy/dist/pypy/translator/sandbox/pypy_interact.py
==============================================================================
--- pypy/dist/pypy/translator/sandbox/pypy_interact.py	(original)
+++ pypy/dist/pypy/translator/sandbox/pypy_interact.py	Sat Sep  8 12:20:23 2007
@@ -12,6 +12,7 @@
                   with the 'k', 'm' or 'g' suffix respectively.
                   ATM this only works with PyPy translated with Boehm.
     --timeout=N   limit execution time to N (real-time) seconds.
+    --log=FILE    log all user input into the FILE
 
 Note that you can get readline-like behavior with a tool like 'ledit',
 provided you use enough -u options:
@@ -64,9 +65,11 @@
 if __name__ == '__main__':
     from getopt import getopt      # and not gnu_getopt!
     options, arguments = getopt(sys.argv[1:], 't:h', 
-                                ['tmp=', 'heapsize=', 'timeout=', 'help'])
+                                ['tmp=', 'heapsize=', 'timeout=', 'log=',
+                                 'help'])
     tmpdir = None
     timeout = None
+    logfile = None
     extraoptions = []
 
     def help():
@@ -96,6 +99,8 @@
             extraoptions[:0] = ['--heapsize', str(bytes)]
         elif option == '--timeout':
             timeout = int(value)
+        elif option == '--log':
+            logfile = value
         elif option in ['-h', '--help']:
             help()
         else:
@@ -108,6 +113,8 @@
                                  tmpdir=tmpdir)
     if timeout is not None:
         sandproc.settimeout(timeout, interrupt_main=True)
+    if logfile is not None:
+        sandproc.setlogfile(logfile)
     try:
         sandproc.interact()
     finally:

Modified: pypy/dist/pypy/translator/sandbox/sandlib.py
==============================================================================
--- pypy/dist/pypy/translator/sandbox/sandlib.py	(original)
+++ pypy/dist/pypy/translator/sandbox/sandlib.py	Sat Sep  8 12:20:23 2007
@@ -277,6 +277,7 @@
     _input = None
     _output = None
     _error = None
+    inputlogfile = None
 
     def communicate(self, input=None):
         """Send data to stdin. Read data from stdout and stderr,
@@ -316,6 +317,9 @@
         self._error = None
         return returncode
 
+    def setlogfile(self, filename):
+        self.inputlogfile = open(filename, 'a')
+
     def do_ll_os__ll_os_read(self, fd, size):
         if fd == 0:
             if self._input is None:
@@ -329,11 +333,14 @@
                 # only time that counts as idle.
                 self.enter_idle()
                 try:
-                    return self._input.readline(size)
+                    inputdata = self._input.readline(size)
                 finally:
                     self.leave_idle()
             else:
-                return self._input.read(size)
+                inputdata = self._input.read(size)
+            if self.inputlogfile is not None:
+                self.inputlogfile.write(inputdata)
+            return inputdata
         raise OSError("trying to read from fd %d" % (fd,))
 
     def do_ll_os__ll_os_write(self, fd, data):



More information about the Pypy-commit mailing list