<commit_before>from django.conf import settings

import socket
import json
import logging

logger = logging.getLogger('judge.judgeapi')


def judge_request(packet):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((settings.BRIDGED_DJANGO_HOST, settings.BRIDGED_DJANGO_PORT))

    output = json.dumps(packet, separators=(',', ':'))
    output = output.encode('zlib')
    sock.sendall(output)
    sock.shutdown(socket.SHUT_WR)

    reader = sock.makefile('r', -1)
    input = reader.read()
    reader.close()
    sock.shutdown(socket.SHUT_RD)
    sock.close()

    input = input.decode('zlib')
    result = json.loads(input)
    return result


def judge_submission(submission):<commit_msg>Read and write files instead of direct socket operation. Hopes to prevent the judgeapi from causing a swallowed exception.<commit_after>from django.conf import settings

import socket
import json
import logging

logger = logging.getLogger('judge.judgeapi')


def judge_request(packet):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((settings.BRIDGED_DJANGO_HOST, settings.BRIDGED_DJANGO_PORT))

    output = json.dumps(packet, separators=(',', ':'))
    output = output.encode('zlib')
    writer = sock.makefile('w', 0)
    writer.write(output)
    writer.close()

    reader = sock.makefile('r', -1)
    input = reader.read()
    reader.close()
    sock.close()

    input = input.decode('zlib')
    result = json.loads(input)
    return result


def judge_submission(submission):
{'fraction_non_alphanumeric': 0.12279555845852384, 'fraction_numerical': 0.001959503592423253, 'mean_word_length': 4.140939597315437, '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': '6566187', 'n_tokens_mistral': 507, 'n_tokens_neox': 485, 'n_words': 103}