<commit_before># We Are Forests
# http://weareforests.com/
#
# a project by <NAME> and <NAME>
# -----------------------------------------------
#
# supported by Nederlands Instituut voor de Mediakunst - http://www.nimk.nl/
#
# Source code (c) 2011 <NAME> <<EMAIL>>
# This code is released under the MIT license. See LICENSE for details.

from twisted.internet import reactor
from twisted.web import static, resource, server, resource
from epsilon.extime import Time

from sparked.web.io import listen

import glob
import os
import tempfile
from email.Parser import Parser
import shutil

from weareforests import telephony


class UploadResource(resource.Resource):

    def __init__(self, app):
        self.app = app


    def render_POST(self, request):
        referer = "/"
        body = ""
        for k, vs in request.requestHeaders.getAllRawHeaders():
            for v in vs:
                if k.lower() == "referer":
                    referer = v
                body += k + ": " + v + "\r\n"
        body += "\r\n"
        body += "".join(request.content.readlines())

        p = Parser()
        msg = p.parsestr(body)
        audiopart = None
        for part in msg.walk():
            if part.is_multipart():
                continue
            if part.get_content_type() == "audio/mp3":
                audiopart = part
                break

        if not audiopart:
            request.redirect(referer+"#uploadFailure")
            return "FAIL"

        print audiopart.get_filename()

        payload = audiopart.get_payload()
        fp, fn = tempfile.mkstemp()
        os.write(fp, payload)
        os.close(fp)

        self.app.fileUploaded(fn, audiopart.get_filename())

        request.redirect(referer+"#uploadOK")
        return "OK"





class WebMixIn:

    def started(self):
        root = resource.Resource()<commit_msg>MIME type for MP3 is really audio/mpeg, though webkit/chrome uses audio/mp3<commit_after># We Are Forests
# http://weareforests.com/
#
# a project by <NAME> and <NAME>
# -----------------------------------------------
#
# supported by Nederlands Instituut voor de Mediakunst - http://www.nimk.nl/
#
# Source code (c) 2011 <NAME> <<EMAIL>>
# This code is released under the MIT license. See LICENSE for details.

from twisted.internet import reactor
from twisted.web import static, resource, server, resource
from epsilon.extime import Time

from sparked.web.io import listen

import glob
import os
import tempfile
from email.Parser import Parser
import shutil

from weareforests import telephony


class UploadResource(resource.Resource):

    def __init__(self, app):
        self.app = app


    def render_POST(self, request):
        referer = "/"
        body = ""
        for k, vs in request.requestHeaders.getAllRawHeaders():
            for v in vs:
                if k.lower() == "referer":
                    referer = v
                body += k + ": " + v + "\r\n"
        body += "\r\n"
        body += "".join(request.content.readlines())

        p = Parser()
        msg = p.parsestr(body)
        audiopart = None
        for part in msg.walk():
            if part.is_multipart():
                continue
            if part.get_content_type() in ("audio/mp3", "audio/mpeg"):
                audiopart = part
                break

        if not audiopart:
            request.redirect(referer+"#uploadFailure")
            return "FAIL"

        print audiopart.get_filename()

        payload = audiopart.get_payload()
        fp, fn = tempfile.mkstemp()
        os.write(fp, payload)
        os.close(fp)

        self.app.fileUploaded(fn, audiopart.get_filename())

        request.redirect(referer+"#uploadOK")
        return "OK"





class WebMixIn:

    def started(self):
        root = resource.Resource()
{'fraction_non_alphanumeric': 0.129015271195366, 'fraction_numerical': 0.00315955766192733, 'mean_word_length': 1.96796875, 'pattern_counts': {'":': 5, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3667835', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1097, 'n_words': 315}