<commit_before>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from pytest import raises

from pando import Response
from pando.exceptions import CRLFInjection


def test_response_is_a_wsgi_callable():
    response = Response(body=b"Greetings, program!")
    def start_response(status, headers):
        pass
    expected = [b"Greetings, program!"]
    actual = list(response({}, start_response).body)
    assert actual == expected

def test_response_wsgi_status_is_not_based_on_str_method():
    class CustomResponse(Response):
        __str__ = lambda self: 'not a valid HTTP status line'
    response = CustomResponse()
    def start_response(status, headers):
        assert status == '200 OK'
    response({}, start_response)

def test_response_body_can_be_bytestring():
    response = Response(body=b"Greetings, program!")
    expected = b"Greetings, program!"
    actual = response.body
    assert actual == expected

def test_response_body_as_bytestring_results_in_an_iterable():
    response = Response(body=b"Greetings, program!")
    def start_response(status, headers):
        pass
    expected = [b"Greetings, program!"]
    actual = list(response({}, start_response).body)
    assert actual == expected

def test_response_body_can_be_iterable():
    response = Response(body=["Greetings, ", "program!"])
    expected = ["Greetings, ", "program!"]
    actual = response.body
    assert actual == expected

def test_response_body_as_iterable_comes_through_untouched():
    response = Response(body=[b"Greetings, ", b"program!"])
    def start_response(status, headers):
        pass
    expected = [b"Greetings, ", b"program!"]
    actual = list(response({}, start_response).body)
    assert actual == expected

def test_response_body_can_be_unicode():
    try:
        Response(body='Greetings, program!')
    except:
        assert False, 'expecting no error'

def test_response_headers_protect_against_crlf_injection():
    response = Response()
    def inject():
        response.headers[b'Location'] = b'foo\r\nbar'<commit_msg>failing test for type of HTTP response headers<commit_after>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from pytest import raises

from pando import Response
from pando.exceptions import CRLFInjection


def test_response_is_a_wsgi_callable():
    response = Response(body=b"Greetings, program!")
    def start_response(status, headers):
        pass
    expected = [b"Greetings, program!"]
    actual = list(response({}, start_response).body)
    assert actual == expected

def test_response_wsgi_status_is_not_based_on_str_method():
    class CustomResponse(Response):
        __str__ = lambda self: 'not a valid HTTP status line'
    response = CustomResponse()
    def start_response(status, headers):
        assert status == '200 OK'
    response({}, start_response)

def test_response_body_can_be_bytestring():
    response = Response(body=b"Greetings, program!")
    expected = b"Greetings, program!"
    actual = response.body
    assert actual == expected

def test_response_body_as_bytestring_results_in_an_iterable():
    response = Response(body=b"Greetings, program!")
    def start_response(status, headers):
        pass
    expected = [b"Greetings, program!"]
    actual = list(response({}, start_response).body)
    assert actual == expected

def test_response_body_can_be_iterable():
    response = Response(body=["Greetings, ", "program!"])
    expected = ["Greetings, ", "program!"]
    actual = response.body
    assert actual == expected

def test_response_body_as_iterable_comes_through_untouched():
    response = Response(body=[b"Greetings, ", b"program!"])
    def start_response(status, headers):
        pass
    expected = [b"Greetings, ", b"program!"]
    actual = list(response({}, start_response).body)
    assert actual == expected

def test_response_body_can_be_unicode():
    try:
        Response(body='Greetings, program!')
    except:
        assert False, 'expecting no error'

def test_response_headers_are_str():
    response = Response()
    response.headers[b'Location'] = b'somewhere'
    def start_response(status, headers):
        assert isinstance(headers[0][0], str)
        assert isinstance(headers[0][1], str)
    response({}, start_response)

def test_response_headers_protect_against_crlf_injection():
    response = Response()
    def inject():
        response.headers[b'Location'] = b'foo\r\nbar'
{'fraction_non_alphanumeric': 0.10399478940512376, 'fraction_numerical': 0.0021710811984368217, 'mean_word_length': 4.517365269461078, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3063591', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1361, 'n_words': 325}