<commit_before>import StringIO
import os
import zipfile

from django.contrib.auth.decorators import login_required, permission_required
from django.http.response import HttpResponse
from django.shortcuts import render
from django.template.defaultfilters import filesizeformat

from WhatManager2.utils import build_url, get_user_token, auth_username_token
from bibliotik.models import BibliotikTransTorrent
from home.models import TransTorrent, ReplicaSet, LogEntry
from player.player_utils import get_playlist_files, get_metadata_dict


def download_zip_handler(download_filename, paths):
    buffer = StringIO.StringIO()
    with zipfile.ZipFile(buffer, "w", zipfile.ZIP_STORED, True) as zip:
        for rel_path, file in paths:
            zip.write(file, rel_path, zipfile.ZIP_STORED)
    buffer.flush()

    response = HttpResponse(mimetype='application/zip')
    response['Content-Disposition'] = 'attachment; filename="' + download_filename + '"'
    response['Content-Length'] = buffer.len

    response.write(buffer.getvalue())
    buffer.close()

    return response


@login_required<commit_msg>Fix no longer existing mimetype in HttpResponse.<commit_after>import StringIO
import os
import zipfile

from django.contrib.auth.decorators import login_required, permission_required
from django.http.response import HttpResponse
from django.shortcuts import render
from django.template.defaultfilters import filesizeformat

from WhatManager2.utils import build_url, get_user_token, auth_username_token
from bibliotik.models import BibliotikTransTorrent
from home.models import TransTorrent, ReplicaSet, LogEntry
from player.player_utils import get_playlist_files, get_metadata_dict


def download_zip_handler(download_filename, paths):
    buffer = StringIO.StringIO()
    with zipfile.ZipFile(buffer, "w", zipfile.ZIP_STORED, True) as zip:
        for rel_path, file in paths:
            zip.write(file, rel_path, zipfile.ZIP_STORED)
    buffer.flush()

    response = HttpResponse(content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename="' + download_filename + '"'
    response['Content-Length'] = buffer.len

    response.write(buffer.getvalue())
    buffer.close()

    return response


@login_required
{'fraction_non_alphanumeric': 0.08040870724122612, 'fraction_numerical': 0.000888494002665482, 'mean_word_length': 5.325842696629214, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '869674', 'n_tokens_mistral': 642, 'n_tokens_neox': 632, 'n_words': 161}