summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-13 21:01:29 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-13 21:01:29 (GMT)
commit8fa45677c1833cc0d4ddaa57417c01ee8297eba8 (patch)
treee33c30313a1f60475f2e7b1e5db33901398398ab /Lib/test/test_descr.py
parent561f899d198c74516f0911a415f2914af3890576 (diff)
downloadcpython-8fa45677c1833cc0d4ddaa57417c01ee8297eba8.zip
cpython-8fa45677c1833cc0d4ddaa57417c01ee8297eba8.tar.gz
cpython-8fa45677c1833cc0d4ddaa57417c01ee8297eba8.tar.bz2
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).
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 02ef0ef..f1af5b9 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1717,6 +1717,47 @@ def keywords():
raise TestFailed("expected TypeError from bogus keyword "
"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()
dicts()
@@ -1752,6 +1793,7 @@ def all():
supers()
inherits()
keywords()
+ restricted()
all()