# Path: chirp/stream/message.py
# CONNECTED = "Connected"        # New connection initiated.
# RESPONSE = "Response"          # HTTP response received.
# BLOCK = "Block"                # A chunk of raw data.
# FRAME = "Frame"                # An MP3 frame.
# ERROR = "Error"                # An error.
# CONNECT_TIMEOUT_ERROR = "Connect Timeout Error"
# CONNECT_ERROR = "Connect Error"
# REQUEST_ERROR = "Request Error"
# READ_TIMEOUT_ERROR = "Read Timeout Error"
# READ_ERROR = "Read Error"
# MISSING_HEADERS_ERROR = "Missing HTTP Headers Error"
# MALFORMED_HEADERS_ERROR = "Malformed HTTP Headers Error"
# BAD_REDIRECT_ERROR = "Bad Redirect Error"
# END_OF_STREAM_ERROR = "End of Stream Error"
# class Message(object):
# class MessageSource(object):
# class MessageConsumer(looper.Looper):
# class MessageTee(MessageConsumer):
#     def payload_sha1(self):
#     def payload_hex_sha1(self):
#     def __str__(self):
#     def set_error(self, error_type, err):
#     def is_error(self):
#     def is_end_of_stream(self):
#     def __init__(self):
#     def _add_message(self, msg):
#     def _add_stop_message(self):
#     def get_next_message(self, timeout=None):
#     def get_all_messages(self):
#     def wait_until_empty(self):
#     def __init__(self, src):
#     def _process_message(self, msg):
#     def _loop_once(self):
#     def __init__(self, input_src, num_outputs):
#     def _process_message(self, msg):
# 
# Path: chirp/stream/http_puller.py
# _HTTP_REQUEST = """GET %(path)s HTTP/1.1
# User-Agent: CHIRP stream_monitor
# Host: %(host)s
# Accept: */*
# Connection: Keep-Alive
# 
# """.replace("\n", "\r\n")
#     READ_TIMEOUT_S = 1
#     READ_SIZE = 2048
#     BACKOFF_S = 0.5  # i.e. 500ms
# def _parse_http_headers(header_str):
#     def __init__(self, host, post, path):
#     def _now_ms(self):
#     def _create_socket(self):
#     def _backoff(self):
#     def _start_message(self):
#     def _finish_message(self, msg, error_type=None, error=None):
#     def _connect(self):
#     def _handle_redirect(self, location):
#     def _pull_one_block(self):
#     def _loop_once(self):
#     def _done_looping(self):
# class HttpPuller(looper.Looper, message.MessageSource):


import threading
import time
import socket
import unittest
from chirp.stream import message
from chirp.stream import http_puller
        self.sendall_data.append(payload)
        if self.simulate_sendall_error:
            raise socket.error(MOCK_ERROR_CODE, MOCK_ERROR_TEXT)

    def recv(self, read_size):
        if not self.recv_data:
            if self.simulate_read_timeout:
                raise socket.timeout
            # We raise a read error if we run out of data, like a
            # closing socket would.
            raise socket.error(MOCK_ERROR_CODE, MOCK_ERROR_TEXT)
        current = self.recv_data[0]
        to_return = current[:read_size]
        if to_return == current:
            self.recv_data.pop(0)
        else:
            self.recv_data[0] = current[read_size:]
        return to_return

    def close(self):
        self.close_called = True


class MockHttpPuller(http_puller.HttpPuller):

    mock_time_ms = 100
    backoff_count = 0

    def __init__(self, *args, **kwargs):
        self.next_socket = MockSocket()

# Path: chirp/stream/message.py
# CONNECTED = "Connected"        # New connection initiated.
# RESPONSE = "Response"          # HTTP response received.
# BLOCK = "Block"                # A chunk of raw data.
# FRAME = "Frame"                # An MP3 frame.
# ERROR = "Error"                # An error.
# CONNECT_TIMEOUT_ERROR = "Connect Timeout Error"
# CONNECT_ERROR = "Connect Error"
# REQUEST_ERROR = "Request Error"
# READ_TIMEOUT_ERROR = "Read Timeout Error"
# READ_ERROR = "Read Error"
# MISSING_HEADERS_ERROR = "Missing HTTP Headers Error"
# MALFORMED_HEADERS_ERROR = "Malformed HTTP Headers Error"
# BAD_REDIRECT_ERROR = "Bad Redirect Error"
# END_OF_STREAM_ERROR = "End of Stream Error"
# class Message(object):
# class MessageSource(object):
# class MessageConsumer(looper.Looper):
# class MessageTee(MessageConsumer):
#     def payload_sha1(self):
#     def payload_hex_sha1(self):
#     def __str__(self):
#     def set_error(self, error_type, err):
#     def is_error(self):
#     def is_end_of_stream(self):
#     def __init__(self):
#     def _add_message(self, msg):
#     def _add_stop_message(self):
#     def get_next_message(self, timeout=None):
#     def get_all_messages(self):
#     def wait_until_empty(self):
#     def __init__(self, src):
#     def _process_message(self, msg):
#     def _loop_once(self):
#     def __init__(self, input_src, num_outputs):
#     def _process_message(self, msg):
# 
# Path: chirp/stream/http_puller.py
# _HTTP_REQUEST = """GET %(path)s HTTP/1.1
# User-Agent: CHIRP stream_monitor
# Host: %(host)s
# Accept: */*
# Connection: Keep-Alive
# 
# """.replace("\n", "\r\n")
#     READ_TIMEOUT_S = 1
#     READ_SIZE = 2048
#     BACKOFF_S = 0.5  # i.e. 500ms
# def _parse_http_headers(header_str):
#     def __init__(self, host, post, path):
#     def _now_ms(self):
#     def _create_socket(self):
#     def _backoff(self):
#     def _start_message(self):
#     def _finish_message(self, msg, error_type=None, error=None):
#     def _connect(self):
#     def _handle_redirect(self, location):
#     def _pull_one_block(self):
#     def _loop_once(self):
#     def _done_looping(self):
# class HttpPuller(looper.Looper, message.MessageSource):


# Path: chirp/stream/http_puller_test.py
import threading
import time
import socket
import unittest
from chirp.stream import message
from chirp.stream import http_puller

        self.sendall_data.append(payload)
        if self.simulate_sendall_error:
            raise socket.error(MOCK_ERROR_CODE, MOCK_ERROR_TEXT)

    def recv(self, read_size):
        if not self.recv_data:
            if self.simulate_read_timeout:
                raise socket.timeout
            # We raise a read error if we run out of data, like a
            # closing socket would.
            raise socket.error(MOCK_ERROR_CODE, MOCK_ERROR_TEXT)
        current = self.recv_data[0]
        to_return = current[:read_size]
        if to_return == current:
            self.recv_data.pop(0)
        else:
            self.recv_data[0] = current[read_size:]
        return to_return

    def close(self):
        self.close_called = True


class MockHttpPuller(http_puller.HttpPuller):

    mock_time_ms = 100
    backoff_count = 0

    def __init__(self, *args, **kwargs):
        self.next_socket = MockSocket()

        http_puller.HttpPuller.__init__(self, *args, **kwargs)