<commit_before>import os
import http
import asyncio

from tornado import web

from waterbutler.core.streams import RequestStreamReader

from waterbutler.server import utils
from waterbutler.server import settings
from waterbutler.server.handlers import core


TRUTH_MAP = {
    'true': True,
    'false': False,
}

@web.stream_request_body
class CRUDHandler(core.BaseHandler):

    ACTION_MAP = {
        'GET': 'download',
        'PUT': 'upload',
        'DELETE': 'delete',
    }
    STREAM_METHODS = ('PUT', )

    @utils.coroutine
    def prepare(self):
        yield from super().prepare()
        self.prepare_stream()

    def prepare_stream(self):
        if self.request.method in self.STREAM_METHODS:
            self.stream = RequestStreamReader(self.request)
            self.uploader = asyncio.async(
                self.provider.upload(self.stream, **self.arguments)
            )
        else:
            self.stream = None

    @utils.coroutine
    def data_received(self, chunk):
        """Note: Only called during uploads."""
        if self.stream:
            self.stream.feed_data(chunk)

    @utils.coroutine
    def get(self):
        """Download a file."""
        try:
            self.arguments['accept_url'] = TRUTH_MAP[self.arguments.get('accept_url', 'true').lower()]
        except KeyError:
            raise web.HTTPError(status_code=400)

        result = yield from self.provider.download(**self.arguments)

        if isinstance(result, str):
            return self.redirect(result)

        try:
            headers = result.response.headers
        except AttributeError:
            headers = {}

        display_name = (
            self.arguments.get('displayName') or
            utils.parse_disposition_name(headers.get('content-disposition')) or
            os.path.split(self.arguments['path'])[-1]
        )
        self.set_header('Content-Type', result.content_type)

        if result.size:
            self.set_header('Content-Length', str(result.size))
        self.set_header('Content-Disposition', 'attachment; filename=' + display_name)

        while True:
            chunk = yield from result.read(settings.CHUNK_SIZE)
            if not chunk:
                break
            self.write(chunk)
            yield from utils.future_wrapper(self.flush())

    @utils.coroutine
    def put(self):
        """Upload a file."""
        self.stream.feed_eof()
        metadata, created = yield from self.uploader
        if created:
            self.set_status(201)
        self.write(metadata)
<commit_msg>Fixes Duplicate header error on Crome<commit_after>import os
import http
import asyncio

from tornado import web

from waterbutler.core.streams import RequestStreamReader

from waterbutler.server import utils
from waterbutler.server import settings
from waterbutler.server.handlers import core


TRUTH_MAP = {
    'true': True,
    'false': False,
}

@web.stream_request_body
class CRUDHandler(core.BaseHandler):

    ACTION_MAP = {
        'GET': 'download',
        'PUT': 'upload',
        'DELETE': 'delete',
    }
    STREAM_METHODS = ('PUT', )

    @utils.coroutine
    def prepare(self):
        yield from super().prepare()
        self.prepare_stream()

    def prepare_stream(self):
        if self.request.method in self.STREAM_METHODS:
            self.stream = RequestStreamReader(self.request)
            self.uploader = asyncio.async(
                self.provider.upload(self.stream, **self.arguments)
            )
        else:
            self.stream = None

    @utils.coroutine
    def data_received(self, chunk):
        """Note: Only called during uploads."""
        if self.stream:
            self.stream.feed_data(chunk)

    @utils.coroutine
    def get(self):
        """Download a file."""
        try:
            self.arguments['accept_url'] = TRUTH_MAP[self.arguments.get('accept_url', 'true').lower()]
        except KeyError:
            raise web.HTTPError(status_code=400)

        result = yield from self.provider.download(**self.arguments)

        if isinstance(result, str):
            return self.redirect(result)

        try:
            headers = result.response.headers
        except AttributeError:
            headers = {}

        display_name = (
            self.arguments.get('displayName') or
            utils.parse_disposition_name(headers.get('content-disposition')) or
            os.path.split(self.arguments['path'])[-1]
        )
        self.set_header('Content-Type', result.content_type)

        if result.size:
            self.set_header('Content-Length', str(result.size))
        self.set_header('Content-Disposition', 'attachment; filename=' + '"' + display_name + '"')

        while True:
            chunk = yield from result.read(settings.CHUNK_SIZE)
            if not chunk:
                break
            self.write(chunk)
            yield from utils.future_wrapper(self.flush())

    @utils.coroutine
    def put(self):
        """Upload a file."""
        self.stream.feed_eof()
        metadata, created = yield from self.uploader
        if created:
            self.set_status(201)
        self.write(metadata)

{'fraction_non_alphanumeric': 0.10999225406661503, 'fraction_numerical': 0.002711076684740511, 'mean_word_length': 2.224094881398252, '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': '3813662', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1433, 'n_words': 309}