Skip to content

Commit 94b4398

Browse files
authored
fix: remove future usages (#149)
* fix: remove future usages from code * fix: remove future package dependency
1 parent 10ff86c commit 94b4398

File tree

5 files changed

+5
-37
lines changed

5 files changed

+5
-37
lines changed

apparmor-profiles/home.sandbox.codejail_sandbox-python3.8.bin.python

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ profile apparmor_profile /home/sandbox/codejail_sandbox-python3.8/bin/python {
1919
/usr/lib/python3.8/lib-dynload/datetime.so mr,
2020
/usr/lib/python3.8/lib-dynload/_elementtree.so mr,
2121
/usr/lib/python3.8/lib-dynload/pyexpat.so mr,
22-
/usr/lib/python3.8/lib-dynload/future_builtins.so mr,
2322
#
2423
# Allow access to selections from /proc
2524
#

codejail/tests/test_jail_code.py

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TestFeatures(JailCodeHelpersMixin, TestCase):
6767

6868
def test_hello_world(self):
6969
res = jailpy(code="""
70-
from __future__ import print_function; print('Hello, world!')
70+
print('Hello, world!')
7171
""")
7272
self.assertResultOk(res)
7373
self.assertEqual(res.stdout, b'Hello, world!\n')
@@ -76,7 +76,6 @@ def test_argv(self):
7676
set_limit('REALTIME', 2)
7777
res = jailpy(
7878
code="""
79-
from __future__ import print_function
8079
import sys
8180
print(':'.join(sys.argv[1:]))
8281
""",
@@ -100,7 +99,6 @@ def test_ends_with_exception(self):
10099
def test_stdin_is_provided(self):
101100
res = jailpy(
102101
code="""
103-
from __future__ import print_function
104102
import json, sys
105103
print(sum(json.load(sys.stdin)))
106104
""",
@@ -112,7 +110,6 @@ def test_stdin_is_provided(self):
112110
def test_stdin_can_be_large_and_binary(self):
113111
res = jailpy(
114112
code="""
115-
from __future__ import print_function
116113
import sys
117114
print(sum(ord(c) for c in sys.stdin.read()))
118115
""",
@@ -152,7 +149,6 @@ def test_stderr_can_be_large_and_binary(self):
152149
def test_files_are_copied(self):
153150
res = jailpy(
154151
code="""
155-
from __future__ import print_function
156152
print('Look:', open('hello.txt').read())
157153
""",
158154
files=[file_here("hello.txt")]
@@ -163,7 +159,6 @@ def test_files_are_copied(self):
163159
def test_directories_are_copied(self):
164160
res = jailpy(
165161
code="""\
166-
from __future__ import print_function
167162
import os
168163
res = []
169164
for path, dirs, files in os.walk("."):
@@ -195,7 +190,6 @@ def test_executing_extra_files(self):
195190
res = jailpy(
196191
extra_files=[
197192
("run.py", bytes(textwrap.dedent("""\
198-
from __future__ import print_function
199193
import os
200194
print(sorted(os.listdir('.')))
201195
print(open('also.txt', 'rb').read())
@@ -221,7 +215,6 @@ def test_we_can_remove_tmp_files(self):
221215
set_limit('FSIZE', 1000)
222216
res = jailpy(
223217
code="""\
224-
from __future__ import print_function
225218
import os, shutil, tempfile
226219
temp_dir = tempfile.mkdtemp()
227220
with open("{}/myfile.txt".format(temp_dir), "w") as f:
@@ -246,7 +239,7 @@ def test_we_can_remove_tmp_files(self):
246239
def test_slugs_get_logged(self, log_log):
247240
jailpy(
248241
code="""
249-
from __future__ import print_function; print('Hello, world!')
242+
print('Hello, world!')
250243
""",
251244
slug="HELLO"
252245
)
@@ -271,7 +264,6 @@ def test_cant_use_too_much_memory(self):
271264
set_limit('VMEM', 80000000)
272265
res = jailpy(
273266
code="""
274-
from __future__ import print_function
275267
print(len(bytearray(100000000)))
276268
"""
277269
)
@@ -284,7 +276,6 @@ def test_changing_vmem_limit(self):
284276
set_limit('VMEM', 160000000)
285277
res = jailpy(
286278
code="""
287-
from __future__ import print_function
288279
print(len(bytearray(100000000)))
289280
"""
290281
)
@@ -297,7 +288,6 @@ def test_disabling_vmem_limit(self):
297288
set_limit('VMEM', 0)
298289
res = jailpy(
299290
code="""
300-
from __future__ import print_function
301291
print(len(bytearray(50000000)))
302292
"""
303293
)
@@ -310,7 +300,6 @@ def test_cant_use_too_much_cpu(self):
310300
set_limit('REALTIME', 10)
311301
res = jailpy(
312302
code="""
313-
from __future__ import print_function
314303
from six.moves import range
315304
print(sum(range(2**31-1)))
316305
"""
@@ -326,7 +315,6 @@ def test_cant_use_too_much_time(self, log_log):
326315
set_limit('REALTIME', 1)
327316
res = jailpy(
328317
code="""
329-
from __future__ import print_function
330318
import time
331319
time.sleep(1.5)
332320
print('Done!')
@@ -344,7 +332,6 @@ def test_changing_realtime_limit(self):
344332
set_limit('REALTIME', 2)
345333
res = jailpy(
346334
code="""
347-
from __future__ import print_function
348335
import time
349336
time.sleep(1.5)
350337
print('Done!')
@@ -358,7 +345,6 @@ def test_disabling_realtime_limit(self):
358345
set_limit('REALTIME', 0)
359346
res = jailpy(
360347
code="""
361-
from __future__ import print_function
362348
import time
363349
time.sleep(1.5)
364350
print('Done!')
@@ -369,7 +355,6 @@ def test_disabling_realtime_limit(self):
369355

370356
def test_cant_write_files(self):
371357
res = jailpy(code="""\
372-
from __future__ import print_function
373358
print("Trying")
374359
with open("mydata.txt", "w") as f:
375360
f.write("hello")
@@ -383,7 +368,6 @@ def test_cant_write_files(self):
383368
def test_can_write_temp_files(self):
384369
set_limit('FSIZE', 1000)
385370
res = jailpy(code="""\
386-
from __future__ import print_function
387371
import os, tempfile
388372
print("Trying mkstemp")
389373
f, path = tempfile.mkstemp()
@@ -399,7 +383,6 @@ def test_can_write_temp_files(self):
399383
def test_cant_write_large_temp_files(self):
400384
set_limit('FSIZE', 1000)
401385
res = jailpy(code="""\
402-
from __future__ import print_function
403386
import os, tempfile
404387
from six.moves import range
405388
print("Trying mkstemp")
@@ -424,7 +407,6 @@ def test_cant_write_many_small_temp_files(self):
424407
# pylint: disable=unreachable
425408
set_limit('FSIZE', 1000)
426409
res = jailpy(code="""\
427-
from __future__ import print_function
428410
import os, tempfile
429411
print("Trying mkstemp 250")
430412
for i in range(250):
@@ -442,7 +424,6 @@ def test_cant_write_many_small_temp_files(self):
442424

443425
def test_cant_use_network(self):
444426
res = jailpy(code="""\
445-
from __future__ import print_function
446427
try:
447428
from urllib import urlopen
448429
except ImportError:
@@ -458,7 +439,6 @@ def test_cant_use_network(self):
458439

459440
def test_cant_use_raw_network(self):
460441
res = jailpy(code="""\
461-
from __future__ import print_function
462442
try:
463443
from urllib import urlopen
464444
except ImportError:
@@ -476,7 +456,6 @@ def test_cant_fork(self):
476456
set_limit('NPROC', 1)
477457
res = jailpy(
478458
code="""\
479-
from __future__ import print_function
480459
import os
481460
print("Forking")
482461
child_ppid = os.fork()
@@ -492,7 +471,6 @@ def test_cant_see_environment_variables(self):
492471
os.environ['HONEY_BOO_BOO'] = 'Look!'
493472
res = jailpy(
494473
code="""\
495-
from __future__ import print_function
496474
import os
497475
for name, value in os.environ.items():
498476
print("%s: %r" % (name, value))
@@ -505,7 +483,6 @@ def test_reading_dev_random(self):
505483
# We can read 10 bytes just fine.
506484
res = jailpy(
507485
code="""
508-
from __future__ import print_function
509486
x = open('/dev/urandom', 'rb').read(10)
510487
print(len(x))
511488
"""
@@ -516,7 +493,6 @@ def test_reading_dev_random(self):
516493
# If we try to read all of it, we'll be killed by the real-time limit.
517494
res = jailpy(
518495
code="""
519-
from __future__ import print_function
520496
x = open('/dev/urandom', 'rb').read()
521497
print('Done!')
522498
"""
@@ -556,7 +532,6 @@ def test_symlinks_in_directories_wont_copy_data(self):
556532
# the symlink.
557533
res = jailpy(
558534
code="""\
559-
from __future__ import print_function
560535
print(open('copied/here.txt').read()) # can read
561536
print(open('copied/herelink.txt').read()) # can read
562537
print(open('copied/link.txt').read()) # can't read
@@ -570,7 +545,6 @@ def test_symlinks_wont_copy_data(self):
570545
# Run some code in the sandbox, with a copied file which is a symlink.
571546
res = jailpy(
572547
code="""\
573-
from __future__ import print_function
574548
print(open('here.txt').read()) # can read
575549
print(open('herelink.txt').read()) # can read
576550
print(open('link.txt').read()) # can't read
@@ -593,7 +567,6 @@ def test_crash_cpython(self):
593567
raise SkipTest('Not supported in Python 3 yet')
594568
# pylint: disable=unreachable
595569
res = jailpy(code="""\
596-
from __future__ import print_function
597570
import new, sys
598571
bad_code = new.code(0,0,0,0,"KABOOM",(),(),(),"","",0,"")
599572
crash_me = new.function(bad_code, {})
@@ -608,7 +581,6 @@ def test_crash_cpython(self):
608581

609582
def test_read_etc_passwd(self):
610583
res = jailpy(code="""\
611-
from __future__ import print_function
612584
bytes = len(open('/etc/passwd').read())
613585
print('Gotcha', bytes)
614586
""")
@@ -618,7 +590,6 @@ def test_read_etc_passwd(self):
618590

619591
def test_find_other_sandboxes(self):
620592
res = jailpy(code="""
621-
from __future__ import print_function
622593
import os
623594
places = [
624595
"..", "/tmp", "/", "/home", "/etc", "/var"
@@ -651,7 +622,7 @@ def setUp(self):
651622
def run_ok(self):
652623
"""Run some code to see that it works."""
653624
num = int(time.time()*100000)
654-
res = jailpy(code="from __future__ import print_function; print('Look: %d')" % num)
625+
res = jailpy(code="print('Look: %d')" % num)
655626
self.assertResultOk(res)
656627
self.assertEqual(res.stdout, b'Look: %d\n' % num)
657628

codejail/tests/test_safe_exec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def g():
9494

9595
def test_printing_stuff_when_you_shouldnt(self):
9696
globs = {}
97-
self.safe_exec("from __future__ import print_function; a = 17; print('hi!')", globs)
97+
self.safe_exec("a = 17; print('hi!')", globs)
9898
self.assertEqual(globs['a'], 17)
9999

100100
def test_importing_lots_of_crap(self):

requirements/sandbox.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
# of sandboxes used for testing codejail
44

55
django
6-
future
76
numpy
87
six

requirements/sandbox.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#
2-
# This file is autogenerated by pip-compile with python 3.8
2+
# This file is autogenerated by pip-compile with Python 3.8
33
# To update, run:
44
#
55
# make upgrade
66
#
77
asgiref==3.5.2 # via django
88
django==3.2.17 # via -c requirements/common_constraints.txt, -c requirements/constraints.txt, -r requirements/sandbox.in
9-
future==0.18.2 # via -r requirements/sandbox.in
109
numpy==1.22.4 # via -r requirements/sandbox.in
1110
pytz==2022.1 # via django
1211
six==1.16.0 # via -r requirements/sandbox.in

0 commit comments

Comments
 (0)