# Path: bustard/utils.py
# def to_text(st, encoding='utf-8'):
#     if isinstance(st, str):
#         return st
#     elif isinstance(st, collections.ByteString):
#         return st.decode(encoding)
#     else:
#         return str(st)
# 
# def to_bytes(bt, encoding='utf-8'):
#     if isinstance(bt, collections.ByteString):
#         return bt
#     elif isinstance(bt, str):
#         return bt.encode(encoding)
#     else:
#         return bytes(bt)


import datetime
import io
import socket
import sys
import time
import urllib
from .utils import to_text, to_bytes

        for k, v in self.headers.items():
            k = k.replace('-', '_').upper()
            if k in env:
                continue
            env['HTTP_' + k] = v
        return env

    def start_response(self, status, headers, exc_info=None):
        server_headers = [
            ('Date', self.date_time_string()),
            ('Server', self.version_string()),
        ]
        headers = list(headers) + server_headers

        if exc_info:
            try:
                if self.headers_set:
                    # Re-raise original exception if headers sent
                    raise (exc_info[0], exc_info[1], exc_info[2])
            finally:
                exc_info = None     # avoid dangling circular ref

        self.headers_set[:] = [status, headers]

    def finish_response(self, body):
        try:
            status, headers = self.headers_set
            # status line
            response = (

# Path: bustard/utils.py
# def to_text(st, encoding='utf-8'):
#     if isinstance(st, str):
#         return st
#     elif isinstance(st, collections.ByteString):
#         return st.decode(encoding)
#     else:
#         return str(st)
# 
# def to_bytes(bt, encoding='utf-8'):
#     if isinstance(bt, collections.ByteString):
#         return bt
#     elif isinstance(bt, str):
#         return bt.encode(encoding)
#     else:
#         return bytes(bt)


# Path: bustard/wsgi_server.py
import datetime
import io
import socket
import sys
import time
import urllib
from .utils import to_text, to_bytes


        for k, v in self.headers.items():
            k = k.replace('-', '_').upper()
            if k in env:
                continue
            env['HTTP_' + k] = v
        return env

    def start_response(self, status, headers, exc_info=None):
        server_headers = [
            ('Date', self.date_time_string()),
            ('Server', self.version_string()),
        ]
        headers = list(headers) + server_headers

        if exc_info:
            try:
                if self.headers_set:
                    # Re-raise original exception if headers sent
                    raise (exc_info[0], exc_info[1], exc_info[2])
            finally:
                exc_info = None     # avoid dangling circular ref

        self.headers_set[:] = [status, headers]

    def finish_response(self, body):
        try:
            status, headers = self.headers_set
            # status line
            response = (

                to_bytes(self.default_request_version) +