<commit_before>import os
from cptbox import CHROOTSecurity, SecurePopen
from executors.utils import test_executor
from .resource_proxy import ResourceProxy
from judgeenv import env

PYTHON_FS = ['/dev/urandom', '.*\.[so|py]', '.*/lib(?:32|64)?/python[\d.]+/.*',
             '.*/lib/locale/.*', '/usr/lib64', '.*/pyvenv.cfg', '/proc/meminfo']
if 'python3dir' in env:
    PYTHON_FS += [str(env['python3dir']) + '.*']


class Executor(ResourceProxy):
    def __init__(self, problem_id, source_code):
        super(ResourceProxy, self).__init__()
        source_code_file = str(problem_id) + '.py'
        customize = '''\
# encoding: utf-8
__import__('sys').stdout = __import__('os').fdopen(1, 'w', 65536)
__import__('sys').stdin = __import__('os').fdopen(0, 'r', 65536)
'''
        with open(source_code_file, 'wb') as fo:
            fo.write(customize)
            fo.write(source_code)
        self._files = [source_code_file]

    def launch(self, *args, **kwargs):
        return SecurePopen(['python', '-BS', self._files[0]] + list(args),
                           executable=env['runtime']['python3'],
                           security=CHROOTSecurity(PYTHON_FS + [os.getcwd() + '$']),
                           time=kwargs.get('time'),
                           memory=kwargs.get('memory'),
                           address_grace=131072,
                           env={'LANG': 'C'})


def initialize():
    if not 'python3' in env['runtime']:
        return False
    return test_executor('PY3', Executor, 'print("Hello, World!")')
<commit_msg>Added exception for pyvenv.cfg which python 3 really likes<commit_after>import os
from cptbox import CHROOTSecurity, SecurePopen
from executors.utils import test_executor
from .resource_proxy import ResourceProxy
from judgeenv import env

PYTHON_FS = ['/dev/urandom', '.*\.[so|py]', '.*/lib(?:32|64)?/python[\d.]+/.*',
             '.*/lib/locale/.*', '/usr/lib64', '.*/?pyvenv.cfg', '/proc/meminfo']
if 'python3dir' in env:
    PYTHON_FS += [str(env['python3dir']) + '.*']


class Executor(ResourceProxy):
    def __init__(self, problem_id, source_code):
        super(ResourceProxy, self).__init__()
        source_code_file = str(problem_id) + '.py'
        customize = '''\
# encoding: utf-8
__import__('sys').stdout = __import__('os').fdopen(1, 'w', 65536)
__import__('sys').stdin = __import__('os').fdopen(0, 'r', 65536)
'''
        with open(source_code_file, 'wb') as fo:
            fo.write(customize)
            fo.write(source_code)
        self._files = [source_code_file]

    def launch(self, *args, **kwargs):
        return SecurePopen(['python', '-BS', self._files[0]] + list(args),
                           executable=env['runtime']['python3'],
                           security=CHROOTSecurity(PYTHON_FS + [os.getcwd() + '$']),
                           time=kwargs.get('time'),
                           memory=kwargs.get('memory'),
                           address_grace=131072,
                           env={'LANG': 'C'})


def initialize():
    if not 'python3' in env['runtime']:
        return False
    return test_executor('PY3', Executor, 'print("Hello, World!")')

{'fraction_non_alphanumeric': 0.17077798861480076, 'fraction_numerical': 0.019924098671726755, 'mean_word_length': 2.5861678004535147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3988263', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1002, 'n_words': 198}