<commit_before># -*- coding: utf-8 -*-
from hyper.packages.hyperframe.frame import (
    Frame, DataFrame, RstStreamFrame, SettingsFrame,
    PushPromiseFrame, PingFrame, WindowUpdateFrame, HeadersFrame,
    ContinuationFrame, BlockedFrame, GoAwayFrame, FRAME_MAX_LEN, FRAME_MAX_ALLOWED_LEN
)
from hyper.packages.hpack.hpack_compat import Encoder, Decoder
from hyper.http20.connection import HTTP20Connection
from hyper.http20.stream import (
    Stream, STATE_HALF_CLOSED_LOCAL, STATE_OPEN, MAX_CHUNK, STATE_CLOSED
)
from hyper.http20.response import HTTP20Response, HTTP20Push
from hyper.http20.exceptions import (
    HPACKDecodingError, HPACKEncodingError, ProtocolError, ConnectionError,
)
from hyper.http20.window import FlowControlManager
from hyper.http20.util import (
    combine_repeated_headers, split_repeated_headers, h2_safe_headers
)
from hyper.common.headers import HTTPHeaderMap
from hyper.compat import zlib_compressobj
from hyper.contrib import HTTP20Adapter
import hyper.http20.errors as errors
import errno
import os
import pytest
import socket
import zlib
from io import BytesIO
import hyper

def decode_frame(frame_data):
    f, length = Frame.parse_frame_header(frame_data[:9])
    f.parse_body(memoryview(frame_data[9:9 + length]))
    assert 9 + length == len(frame_data)
    return f


class TestHyperConnection(object):
    def test_connections_accept_hosts_and_ports(self):
        c = HTTP20Connection(host='www.google.com', port=8080)
        assert c.host =='www.google.com'
        assert c.port == 8080
        assert c.proxy_host == None

    def test_connections_can_parse_hosts_and_ports(self):
        c = HTTP20Connection('www.google.com:8080')
        assert c.host == 'www.google.com'
        assert c.port == 8080
        assert c.proxy_host == None

    def test_connections_accept_proxy_hosts_and_ports(self):
        c = HTTP20Connection('www.google.com', proxy_host='localhost:8443')
        assert c.host == 'www.google.com'
        assert c.proxy_host == 'localhost'
        assert c.proxy_port == 8443

    def test_connections_can_parse_proxy_hosts_and_ports(self):
        c = HTTP20Connection('www.google.com', 
                             proxy_host='localhost', 
                             proxy_port=8443)
        assert c.host == 'www.google.com'
        assert c.proxy_host == 'localhost'
        assert c.proxy_port == 8443

    def test_putrequest_establishes_new_stream(self):
        c = HTTP20Connection("www.google.com")

        stream_id = c.putrequest('GET', '/')
        stream = c.streams[stream_id]

        assert len(c.streams) == 1
        assert c.recent_stream is stream

    def test_putrequest_autosets_headers(self):
        c = HTTP20Connection("www.google.com")

        c.putrequest('GET', '/')
        s = c.recent_stream

        assert s.headers == [
            (':method', 'GET'),<commit_msg>Clear up trailing whitespace.<commit_after># -*- coding: utf-8 -*-
from hyper.packages.hyperframe.frame import (
    Frame, DataFrame, RstStreamFrame, SettingsFrame,
    PushPromiseFrame, PingFrame, WindowUpdateFrame, HeadersFrame,
    ContinuationFrame, BlockedFrame, GoAwayFrame, FRAME_MAX_LEN, FRAME_MAX_ALLOWED_LEN
)
from hyper.packages.hpack.hpack_compat import Encoder, Decoder
from hyper.http20.connection import HTTP20Connection
from hyper.http20.stream import (
    Stream, STATE_HALF_CLOSED_LOCAL, STATE_OPEN, MAX_CHUNK, STATE_CLOSED
)
from hyper.http20.response import HTTP20Response, HTTP20Push
from hyper.http20.exceptions import (
    HPACKDecodingError, HPACKEncodingError, ProtocolError, ConnectionError,
)
from hyper.http20.window import FlowControlManager
from hyper.http20.util import (
    combine_repeated_headers, split_repeated_headers, h2_safe_headers
)
from hyper.common.headers import HTTPHeaderMap
from hyper.compat import zlib_compressobj
from hyper.contrib import HTTP20Adapter
import hyper.http20.errors as errors
import errno
import os
import pytest
import socket
import zlib
from io import BytesIO
import hyper

def decode_frame(frame_data):
    f, length = Frame.parse_frame_header(frame_data[:9])
    f.parse_body(memoryview(frame_data[9:9 + length]))
    assert 9 + length == len(frame_data)
    return f


class TestHyperConnection(object):
    def test_connections_accept_hosts_and_ports(self):
        c = HTTP20Connection(host='www.google.com', port=8080)
        assert c.host =='www.google.com'
        assert c.port == 8080
        assert c.proxy_host == None

    def test_connections_can_parse_hosts_and_ports(self):
        c = HTTP20Connection('www.google.com:8080')
        assert c.host == 'www.google.com'
        assert c.port == 8080
        assert c.proxy_host == None

    def test_connections_accept_proxy_hosts_and_ports(self):
        c = HTTP20Connection('www.google.com', proxy_host='localhost:8443')
        assert c.host == 'www.google.com'
        assert c.proxy_host == 'localhost'
        assert c.proxy_port == 8443

    def test_connections_can_parse_proxy_hosts_and_ports(self):
        c = HTTP20Connection('www.google.com',
                             proxy_host='localhost',
                             proxy_port=8443)
        assert c.host == 'www.google.com'
        assert c.proxy_host == 'localhost'
        assert c.proxy_port == 8443

    def test_putrequest_establishes_new_stream(self):
        c = HTTP20Connection("www.google.com")

        stream_id = c.putrequest('GET', '/')
        stream = c.streams[stream_id]

        assert len(c.streams) == 1
        assert c.recent_stream is stream

    def test_putrequest_autosets_headers(self):
        c = HTTP20Connection("www.google.com")

        c.putrequest('GET', '/')
        s = c.recent_stream

        assert s.headers == [
            (':method', 'GET'),
{'fraction_non_alphanumeric': 0.09400969529085873, 'fraction_numerical': 0.02527700831024931, 'mean_word_length': 3.467904098994586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 20, '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': '1413011', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1736, 'n_words': 376}