<commit_before># Copyright: 2013 <NAME> <<EMAIL>>
# License: BSD 2-clause, see LICENSE for details.

import errno
import time

from flask import Response, current_app, render_template, stream_with_context, abort
from flask.views import MethodView
from werkzeug.exceptions import NotFound

from ..utils.name import ItemName
from ..utils.permissions import *
from . import blueprint


class DownloadView(MethodView):
    content_disposition = 'attachment'  # to trigger download

    def get(self, name):
        try:
            item = current_app.storage.openwrite(name)
        except OSError as e:
            if e.errno == errno.ENOENT:
                raise NotFound()
            raise

        if not item.meta.get('complete'):
            error = 'Upload incomplete. Try again later.'
        else:
            error = None
        if error:
            try:
                return render_template('display_error.html', name=name, item=item, error=error), 409
            finally:
                item.close()

        if item.meta.get('locked') and not may(ADMIN):
            abort(403)

        def stream():
            with item as _item:<commit_msg>download view: add check for READ permission<commit_after># Copyright: 2013 <NAME> <<EMAIL>>
# License: BSD 2-clause, see LICENSE for details.

import errno
import time

from flask import Response, current_app, render_template, stream_with_context, abort
from flask.views import MethodView
from werkzeug.exceptions import NotFound

from ..utils.name import ItemName
from ..utils.permissions import *
from . import blueprint


class DownloadView(MethodView):
    content_disposition = 'attachment'  # to trigger download

    def get(self, name):
        if not may(READ):
            abort(403)
        try:
            item = current_app.storage.openwrite(name)
        except OSError as e:
            if e.errno == errno.ENOENT:
                raise NotFound()
            raise

        if not item.meta.get('complete'):
            error = 'Upload incomplete. Try again later.'
        else:
            error = None
        if error:
            try:
                return render_template('display_error.html', name=name, item=item, error=error), 409
            finally:
                item.close()

        if item.meta.get('locked') and not may(ADMIN):
            abort(403)

        def stream():
            with item as _item:
{'fraction_non_alphanumeric': 0.08735440931780367, 'fraction_numerical': 0.010399334442595673, 'mean_word_length': 2.193891102257636, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1327283', 'n_tokens_mistral': 680, 'n_tokens_neox': 636, 'n_words': 209}