<commit_before># -*- coding: utf-8 -
# Copyright 2009 <NAME> <<EMAIL>>
#
# This file is part of gunicorn released under the MIT license. 
# See the NOTICE for more information.

import array
import os
import tempfile

dirname = os.path.dirname(__file__)

from gunicorn.http.parser import Parser
from gunicorn.http.request import Request

def data_source(fname):
    with open(fname) as handle:
        lines = []
        for line in handle:
            line = line.rstrip("\n").replace("\\r\\n", "\r\n")
            lines.append(line)
        return "".join(lines)

class request(object):
    def __init__(self, name):
        self.fname = os.path.join(dirname, "requests", name)
        
    def __call__(self, func):
        def run():
            src = data_source(self.fname)
            func(src, Parser())
        run.func_name = func.func_name
        return run
        
        
class FakeSocket(object):
    
    def __init__(self, data=""):
        self.tmp = tempfile.TemporaryFile()
        if data:
            self.tmp.write(data)
            self.tmp.flush()
            self.tmp.seek(0)

    def fileno(self):
        return self.tmp.fileno()
        
    def len(self):
        return self.tmp.len
        
    def recv(self, length=None):
        return self.tmp.read()
        
    def recv_into(self, buf, length):
        tmp_buffer = self.tmp.read(length)
        v = len(tmp_buffer)
        for i, c in enumerate(tmp_buffer):
            buf[i] = c
        return v
        
    def send(self, data):
        self.tmp.write(data)
        self.tmp.flush()
        
    def seek(self, offset, whence=0):
        self.tmp.seek(offset, whence)
        
        
class http_request(object):
    def __init__(self, name):
        self.fname = os.path.join(dirname, "requests", name)
    
    def __call__(self, func):
        def run():
            fsock = FakeSocket(data_source(self.fname))
            req = Request(fsock, ('127.0.0.1', 6000), ('127.0.0.1', 8000))
            func(req)<commit_msg>Fix failed tests due to lack of passing config to a Request<commit_after># -*- coding: utf-8 -
# Copyright 2009 <NAME> <<EMAIL>>
#
# This file is part of gunicorn released under the MIT license. 
# See the NOTICE for more information.

import array
import os
import tempfile

dirname = os.path.dirname(__file__)

from gunicorn.http.parser import Parser
from gunicorn.http.request import Request
from gunicorn.config import Config

def data_source(fname):
    with open(fname) as handle:
        lines = []
        for line in handle:
            line = line.rstrip("\n").replace("\\r\\n", "\r\n")
            lines.append(line)
        return "".join(lines)

class request(object):
    def __init__(self, name):
        self.fname = os.path.join(dirname, "requests", name)
        
    def __call__(self, func):
        def run():
            src = data_source(self.fname)
            func(src, Parser())
        run.func_name = func.func_name
        return run
        
        
class FakeSocket(object):
    
    def __init__(self, data=""):
        self.tmp = tempfile.TemporaryFile()
        if data:
            self.tmp.write(data)
            self.tmp.flush()
            self.tmp.seek(0)

    def fileno(self):
        return self.tmp.fileno()
        
    def len(self):
        return self.tmp.len
        
    def recv(self, length=None):
        return self.tmp.read()
        
    def recv_into(self, buf, length):
        tmp_buffer = self.tmp.read(length)
        v = len(tmp_buffer)
        for i, c in enumerate(tmp_buffer):
            buf[i] = c
        return v
        
    def send(self, data):
        self.tmp.write(data)
        self.tmp.flush()
        
    def seek(self, offset, whence=0):
        self.tmp.seek(offset, whence)
        
        
class http_request(object):
    def __init__(self, name):
        self.fname = os.path.join(dirname, "requests", name)
    
    def __call__(self, func):
        def run():
            fsock = FakeSocket(data_source(self.fname))
            req = Request(fsock, ('127.0.0.1', 6000), ('127.0.0.1', 8000), Config({}))
            func(req)
{'fraction_non_alphanumeric': 0.12297264584846285, 'fraction_numerical': 0.013071895424836602, 'mean_word_length': 1.955650929899857, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '7001369', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1281, 'n_words': 325}