<commit_before>from flask import current_app as app
from flask.helpers import send_from_directory
from flask.views import MethodView


class StaticView(MethodView):
    def __init__(self, root, cache_timeout=0):
        self.root = root
        self.cache_timeout = app.config['SEND_FILE_MAX_AGE_DEFAULT']

    def get(self, filename):
        return send_from_directory(
            self.root, filename, cache_timeout=self.cache_timeout)
<commit_msg>Fix static file serving in dev by serving manually in controller<commit_after>from flask import current_app as app, Response
from flask.helpers import send_from_directory
from flask.views import MethodView
import mimetypes


class StaticView(MethodView):
    def __init__(self, root, cache_timeout=0):
        self.root = root
        self.cache_timeout = app.config['SEND_FILE_MAX_AGE_DEFAULT']

    def get(self, filename):
        # We do this in debug to work around http://stackoverflow.com/q/17460463/871202
        # By reading the file into memory ourselves, we seem to avoid hitting that
        # VirtualBox issue in dev. In prod, it's unchanged and we just send_from_directory
        if app.debug:
            full_name = self.root + "/" + filename

            if filename:
                mimetype = mimetypes.guess_type(filename)[0]
            else:
                mimetype = 'application/octet-stream'
            return Response(
                open(full_name),
                mimetype=mimetype,
                headers={
                    "Content-Disposition": "filename=" + filename
                }
            )
        else:
            return send_from_directory(
                self.root, filename, cache_timeout=self.cache_timeout)

{'fraction_non_alphanumeric': 0.0722189866045428, 'fraction_numerical': 0.009900990099009901, 'mean_word_length': 2.463709677419355, 'pattern_counts': {'":': 1, '<': 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': '5963829', 'n_tokens_mistral': 483, 'n_tokens_neox': 453, 'n_words': 132}