<commit_before>import re

from django.http import HttpResponse, HttpResponseBadRequest

from .forms import CommandForm
from .models import Disk, File, Memory

memory = {}
for cell in Memory.objects.all():
    memory[cell.address] = cell.value

load_re = re.compile(r'^load( )?"((\$|[a-z0-9]+))"')
peek_re = re.compile(r'^peek ([0-9]+)')


def validate_command(request):
    form = CommandForm(request.POST)
    if not form.is_valid():
        print form.errors
        return HttpResponseBadRequest('syntax error') 

    disk = Disk.objects.get(pk=1)

    print form.cleaned_data['command']
    cmd = form.cleaned_data['command'].lower()
    if cmd.startswith('load'):
        filename = load_re.match(cmd).groups()[1]
        if filename == '$':
            request.session['disk_loaded'] = True
            return HttpResponse('')
        try:
            fil = disk.load_file(name=filename)
            request.session['file_loaded'] = fil.pk
        except File.DoesNotExists:
            return HttpResponse('file not found'.upper())

    if cmd.startswith('list') and request.session.get('disk_loaded', False):
        return HttpResponse(disk.content)
    if cmd.startswith('run'):
        if not request.session.get('file_loaded'):
            return HttpResponse('syntax error')
        fil = disk.files.get(pk=request.session['file_loaded'])
        return HttpResponse(fil.content.upper())
    if cmd.startswith('peek'):
        address = int(peek_re.match(cmd).groups()[0])
        return HttpResponse(memory.get(address, '').upper())

    return HttpResponse('syntax error')<commit_msg>moving stuff<commit_after>import re

from django.http import HttpResponse, HttpResponseBadRequest

from .forms import CommandForm
from .models import Disk, File, Memory

memory = {}
for cell in Memory.objects.all():
    memory[cell.address] = cell.value

load_re = re.compile(r'^load( )?"((\$|[a-z0-9]+))",8')
peek_re = re.compile(r'^peek ([0-9]+)')


def validate_command(request):
    form = CommandForm(request.POST)
    if not form.is_valid():
        print form.errors
        return HttpResponseBadRequest('syntax error') 

    disk = Disk.objects.get(pk=1)

    print form.cleaned_data['command']
    cmd = form.cleaned_data['command'].lower()
    if cmd.startswith('load'):
        filename = load_re.match(cmd).groups()[1]
        if filename == '$':
            request.session['disk_loaded'] = True
            return HttpResponse('')
        try:
            fil = disk.load_file(name=filename)
            request.session['file_loaded'] = fil.pk
        except File.DoesNotExist:
            return HttpResponse('file not found'.upper())

    if cmd.startswith('list') and request.session.get('disk_loaded', False):
        return HttpResponse(disk.content)
    if cmd.startswith('run'):
        if not request.session.get('file_loaded'):
            return HttpResponse('syntax error')
        fil = disk.files.get(pk=request.session['file_loaded'])
        return HttpResponse(fil.content.upper())
    if cmd.startswith('peek'):
        address = int(peek_re.match(cmd).groups()[0])
        return HttpResponse(memory.get(address, '').upper())

    return HttpResponse('syntax error')
{'fraction_non_alphanumeric': 0.14415259537210756, 'fraction_numerical': 0.004690431519699813, 'mean_word_length': 3.1653645833333335, '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': '4116791', 'n_tokens_mistral': 975, 'n_tokens_neox': 945, 'n_words': 196}