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

arigo at codespeak.net arigo at codespeak.net
Fri Sep 7 09:58:33 CEST 2007


Author: arigo
Date: Fri Sep  7 09:58:32 2007
New Revision: 46381

Modified:
   pypy/dist/pypy/translator/sandbox/sandlib.py
Log:
Enable by default sanboxed usage of the three time.*() functions
of the simple 'time' module of PyPy.



Modified: pypy/dist/pypy/translator/sandbox/sandlib.py
==============================================================================
--- pypy/dist/pypy/translator/sandbox/sandlib.py	(original)
+++ pypy/dist/pypy/translator/sandbox/sandlib.py	Fri Sep  7 09:58:32 2007
@@ -5,7 +5,7 @@
 """
 
 import py
-import marshal, sys, os, posixpath, errno, stat
+import marshal, sys, os, posixpath, errno, stat, time
 from pypy.rpython.module.ll_os_stat import s_StatResult
 from pypy.tool.ansi_print import AnsiLog
 from pypy.rlib.rarithmetic import r_longlong
@@ -231,6 +231,24 @@
             return len(data)
         raise OSError("trying to write to fd %d" % (fd,))
 
+    # let's allow access to the real time
+    def do_ll_time__ll_time_sleep(self, seconds):
+        time.sleep(seconds)
+
+    def do_ll_time__ll_time_time(self):
+        return time.time()
+
+    def do_ll_time__ll_time_clock(self):
+        # measuring the CPU time of the controller process has
+        # not much meaning, so let's emulate this and return
+        # the real time elapsed since the first call to clock()
+        # (this is one of the behaviors allowed by the docs)
+        try:
+            starttime = self.starttime
+        except AttributeError:
+            starttime = self.starttime = time.time()
+        return time.time() - starttime
+
 
 class VirtualizedSandboxedProc(SandboxedProc):
     """Control a virtualized sandboxed process, which is given a custom



More information about the Pypy-commit mailing list