@@ -67,7 +67,7 @@ class TestFeatures(JailCodeHelpersMixin, TestCase):
67
67
68
68
def test_hello_world (self ):
69
69
res = jailpy (code = """
70
- from __future__ import print_function; print('Hello, world!')
70
+ print('Hello, world!')
71
71
""" )
72
72
self .assertResultOk (res )
73
73
self .assertEqual (res .stdout , b'Hello, world!\n ' )
@@ -76,7 +76,6 @@ def test_argv(self):
76
76
set_limit ('REALTIME' , 2 )
77
77
res = jailpy (
78
78
code = """
79
- from __future__ import print_function
80
79
import sys
81
80
print(':'.join(sys.argv[1:]))
82
81
""" ,
@@ -100,7 +99,6 @@ def test_ends_with_exception(self):
100
99
def test_stdin_is_provided (self ):
101
100
res = jailpy (
102
101
code = """
103
- from __future__ import print_function
104
102
import json, sys
105
103
print(sum(json.load(sys.stdin)))
106
104
""" ,
@@ -112,7 +110,6 @@ def test_stdin_is_provided(self):
112
110
def test_stdin_can_be_large_and_binary (self ):
113
111
res = jailpy (
114
112
code = """
115
- from __future__ import print_function
116
113
import sys
117
114
print(sum(ord(c) for c in sys.stdin.read()))
118
115
""" ,
@@ -152,7 +149,6 @@ def test_stderr_can_be_large_and_binary(self):
152
149
def test_files_are_copied (self ):
153
150
res = jailpy (
154
151
code = """
155
- from __future__ import print_function
156
152
print('Look:', open('hello.txt').read())
157
153
""" ,
158
154
files = [file_here ("hello.txt" )]
@@ -163,7 +159,6 @@ def test_files_are_copied(self):
163
159
def test_directories_are_copied (self ):
164
160
res = jailpy (
165
161
code = """\
166
- from __future__ import print_function
167
162
import os
168
163
res = []
169
164
for path, dirs, files in os.walk("."):
@@ -195,7 +190,6 @@ def test_executing_extra_files(self):
195
190
res = jailpy (
196
191
extra_files = [
197
192
("run.py" , bytes (textwrap .dedent ("""\
198
- from __future__ import print_function
199
193
import os
200
194
print(sorted(os.listdir('.')))
201
195
print(open('also.txt', 'rb').read())
@@ -221,7 +215,6 @@ def test_we_can_remove_tmp_files(self):
221
215
set_limit ('FSIZE' , 1000 )
222
216
res = jailpy (
223
217
code = """\
224
- from __future__ import print_function
225
218
import os, shutil, tempfile
226
219
temp_dir = tempfile.mkdtemp()
227
220
with open("{}/myfile.txt".format(temp_dir), "w") as f:
@@ -246,7 +239,7 @@ def test_we_can_remove_tmp_files(self):
246
239
def test_slugs_get_logged (self , log_log ):
247
240
jailpy (
248
241
code = """
249
- from __future__ import print_function; print('Hello, world!')
242
+ print('Hello, world!')
250
243
""" ,
251
244
slug = "HELLO"
252
245
)
@@ -271,7 +264,6 @@ def test_cant_use_too_much_memory(self):
271
264
set_limit ('VMEM' , 80000000 )
272
265
res = jailpy (
273
266
code = """
274
- from __future__ import print_function
275
267
print(len(bytearray(100000000)))
276
268
"""
277
269
)
@@ -284,7 +276,6 @@ def test_changing_vmem_limit(self):
284
276
set_limit ('VMEM' , 160000000 )
285
277
res = jailpy (
286
278
code = """
287
- from __future__ import print_function
288
279
print(len(bytearray(100000000)))
289
280
"""
290
281
)
@@ -297,7 +288,6 @@ def test_disabling_vmem_limit(self):
297
288
set_limit ('VMEM' , 0 )
298
289
res = jailpy (
299
290
code = """
300
- from __future__ import print_function
301
291
print(len(bytearray(50000000)))
302
292
"""
303
293
)
@@ -310,7 +300,6 @@ def test_cant_use_too_much_cpu(self):
310
300
set_limit ('REALTIME' , 10 )
311
301
res = jailpy (
312
302
code = """
313
- from __future__ import print_function
314
303
from six.moves import range
315
304
print(sum(range(2**31-1)))
316
305
"""
@@ -326,7 +315,6 @@ def test_cant_use_too_much_time(self, log_log):
326
315
set_limit ('REALTIME' , 1 )
327
316
res = jailpy (
328
317
code = """
329
- from __future__ import print_function
330
318
import time
331
319
time.sleep(1.5)
332
320
print('Done!')
@@ -344,7 +332,6 @@ def test_changing_realtime_limit(self):
344
332
set_limit ('REALTIME' , 2 )
345
333
res = jailpy (
346
334
code = """
347
- from __future__ import print_function
348
335
import time
349
336
time.sleep(1.5)
350
337
print('Done!')
@@ -358,7 +345,6 @@ def test_disabling_realtime_limit(self):
358
345
set_limit ('REALTIME' , 0 )
359
346
res = jailpy (
360
347
code = """
361
- from __future__ import print_function
362
348
import time
363
349
time.sleep(1.5)
364
350
print('Done!')
@@ -369,7 +355,6 @@ def test_disabling_realtime_limit(self):
369
355
370
356
def test_cant_write_files (self ):
371
357
res = jailpy (code = """\
372
- from __future__ import print_function
373
358
print("Trying")
374
359
with open("mydata.txt", "w") as f:
375
360
f.write("hello")
@@ -383,7 +368,6 @@ def test_cant_write_files(self):
383
368
def test_can_write_temp_files (self ):
384
369
set_limit ('FSIZE' , 1000 )
385
370
res = jailpy (code = """\
386
- from __future__ import print_function
387
371
import os, tempfile
388
372
print("Trying mkstemp")
389
373
f, path = tempfile.mkstemp()
@@ -399,7 +383,6 @@ def test_can_write_temp_files(self):
399
383
def test_cant_write_large_temp_files (self ):
400
384
set_limit ('FSIZE' , 1000 )
401
385
res = jailpy (code = """\
402
- from __future__ import print_function
403
386
import os, tempfile
404
387
from six.moves import range
405
388
print("Trying mkstemp")
@@ -424,7 +407,6 @@ def test_cant_write_many_small_temp_files(self):
424
407
# pylint: disable=unreachable
425
408
set_limit ('FSIZE' , 1000 )
426
409
res = jailpy (code = """\
427
- from __future__ import print_function
428
410
import os, tempfile
429
411
print("Trying mkstemp 250")
430
412
for i in range(250):
@@ -442,7 +424,6 @@ def test_cant_write_many_small_temp_files(self):
442
424
443
425
def test_cant_use_network (self ):
444
426
res = jailpy (code = """\
445
- from __future__ import print_function
446
427
try:
447
428
from urllib import urlopen
448
429
except ImportError:
@@ -458,7 +439,6 @@ def test_cant_use_network(self):
458
439
459
440
def test_cant_use_raw_network (self ):
460
441
res = jailpy (code = """\
461
- from __future__ import print_function
462
442
try:
463
443
from urllib import urlopen
464
444
except ImportError:
@@ -476,7 +456,6 @@ def test_cant_fork(self):
476
456
set_limit ('NPROC' , 1 )
477
457
res = jailpy (
478
458
code = """\
479
- from __future__ import print_function
480
459
import os
481
460
print("Forking")
482
461
child_ppid = os.fork()
@@ -492,7 +471,6 @@ def test_cant_see_environment_variables(self):
492
471
os .environ ['HONEY_BOO_BOO' ] = 'Look!'
493
472
res = jailpy (
494
473
code = """\
495
- from __future__ import print_function
496
474
import os
497
475
for name, value in os.environ.items():
498
476
print("%s: %r" % (name, value))
@@ -505,7 +483,6 @@ def test_reading_dev_random(self):
505
483
# We can read 10 bytes just fine.
506
484
res = jailpy (
507
485
code = """
508
- from __future__ import print_function
509
486
x = open('/dev/urandom', 'rb').read(10)
510
487
print(len(x))
511
488
"""
@@ -516,7 +493,6 @@ def test_reading_dev_random(self):
516
493
# If we try to read all of it, we'll be killed by the real-time limit.
517
494
res = jailpy (
518
495
code = """
519
- from __future__ import print_function
520
496
x = open('/dev/urandom', 'rb').read()
521
497
print('Done!')
522
498
"""
@@ -556,7 +532,6 @@ def test_symlinks_in_directories_wont_copy_data(self):
556
532
# the symlink.
557
533
res = jailpy (
558
534
code = """\
559
- from __future__ import print_function
560
535
print(open('copied/here.txt').read()) # can read
561
536
print(open('copied/herelink.txt').read()) # can read
562
537
print(open('copied/link.txt').read()) # can't read
@@ -570,7 +545,6 @@ def test_symlinks_wont_copy_data(self):
570
545
# Run some code in the sandbox, with a copied file which is a symlink.
571
546
res = jailpy (
572
547
code = """\
573
- from __future__ import print_function
574
548
print(open('here.txt').read()) # can read
575
549
print(open('herelink.txt').read()) # can read
576
550
print(open('link.txt').read()) # can't read
@@ -593,7 +567,6 @@ def test_crash_cpython(self):
593
567
raise SkipTest ('Not supported in Python 3 yet' )
594
568
# pylint: disable=unreachable
595
569
res = jailpy (code = """\
596
- from __future__ import print_function
597
570
import new, sys
598
571
bad_code = new.code(0,0,0,0,"KABOOM",(),(),(),"","",0,"")
599
572
crash_me = new.function(bad_code, {})
@@ -608,7 +581,6 @@ def test_crash_cpython(self):
608
581
609
582
def test_read_etc_passwd (self ):
610
583
res = jailpy (code = """\
611
- from __future__ import print_function
612
584
bytes = len(open('/etc/passwd').read())
613
585
print('Gotcha', bytes)
614
586
""" )
@@ -618,7 +590,6 @@ def test_read_etc_passwd(self):
618
590
619
591
def test_find_other_sandboxes (self ):
620
592
res = jailpy (code = """
621
- from __future__ import print_function
622
593
import os
623
594
places = [
624
595
"..", "/tmp", "/", "/home", "/etc", "/var"
@@ -651,7 +622,7 @@ def setUp(self):
651
622
def run_ok (self ):
652
623
"""Run some code to see that it works."""
653
624
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 )
655
626
self .assertResultOk (res )
656
627
self .assertEqual (res .stdout , b'Look: %d\n ' % num )
657
628
0 commit comments