[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.54,1.55
Tim Peters
tim_one@users.sourceforge.net
Thu, 13 Sep 2001 14:01:31 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv5024/python/Lib/test
Modified Files:
test_descr.py
Log Message:
Now that file objects are subclassable, you can get at the file constructor
just by doing type(f) where f is any file object. This left a hole in
restricted execution mode that rexec.py can't plug by itself (although it
can plug part of it; the rest is plugged in fileobject.c now).
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** test_descr.py 2001/09/13 19:36:36 1.54
--- test_descr.py 2001/09/13 21:01:29 1.55
***************
*** 1718,1721 ****
--- 1718,1762 ----
"argument to %r" % constructor)
+ def restricted():
+ import rexec
+ if verbose:
+ print "Testing interaction with restricted execution ..."
+
+ sandbox = rexec.RExec()
+
+ code1 = """f = open(%r, 'w')""" % TESTFN
+ code2 = """f = file(%r, 'w')""" % TESTFN
+ code3 = """\
+ f = open(%r)
+ t = type(f) # a sneaky way to get the file() constructor
+ f.close()
+ f = t(%r, 'w') # rexec can't catch this by itself
+ """ % (TESTFN, TESTFN)
+
+ f = open(TESTFN, 'w') # Create the file so code3 can find it.
+ f.close()
+
+ try:
+ for code in code1, code2, code3:
+ try:
+ sandbox.r_exec(code)
+ except IOError, msg:
+ if str(msg).find("restricted") >= 0:
+ outcome = "OK"
+ else:
+ outcome = "got an exception, but not an expected one"
+ else:
+ outcome = "expected a restricted-execution exception"
+
+ if outcome != "OK":
+ raise TestFailed("%s, in %r" % (outcome, code))
+
+ finally:
+ try:
+ import os
+ os.unlink(TESTFN)
+ except:
+ pass
+
def all():
lists()
***************
*** 1753,1756 ****
--- 1794,1798 ----
inherits()
keywords()
+ restricted()
all()