# Path: restkit/util.py
# def to_bytestring(s):
#     if not isinstance(s, basestring):
#         raise TypeError("value should be a str or unicode")
# 
#     if isinstance(s, unicode):
#         return s.encode('utf-8')
#     return s


import base64
import cgi
import os
import socket
import tempfile
import threading
import unittest
import urlparse
import Cookie
import urllib
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
    from urlparse import parse_qsl, parse_qs
    from cgi import parse_qsl, parse_qs
from restkit.util import to_bytestring
        elif path == "/chunked":
            te = (self.headers.get("transfer-encoding") == "chunked")
            if te:
                body = self.rfile.read(29)
                extra_headers.append(('Content-Length', "29"))
                self._respond(200, extra_headers, body)
            else:
                self.error_Response()
        else:
            self.error_Response('Bad path')
            
    do_PUT = do_POST

    def do_DELETE(self):
        if self.path == "/delete":
            extra_headers = [('Content-type', 'text/plain')]
            self._respond(200, extra_headers, '')
        else:
            self.error_Response()

    def do_HEAD(self):
        if self.path == "/ok":
            extra_headers = [('Content-type', 'text/plain')]
            self._respond(200, extra_headers, '')
        else:
            self.error_Response()

    def error_Response(self, message=None):
        req = [
            ('HTTP method', self.command),

# Path: restkit/util.py
# def to_bytestring(s):
#     if not isinstance(s, basestring):
#         raise TypeError("value should be a str or unicode")
# 
#     if isinstance(s, unicode):
#         return s.encode('utf-8')
#     return s


# Path: tests/_server_test.py
import base64
import cgi
import os
import socket
import tempfile
import threading
import unittest
import urlparse
import Cookie
import urllib
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
    from urlparse import parse_qsl, parse_qs
    from cgi import parse_qsl, parse_qs
from restkit.util import to_bytestring

        elif path == "/chunked":
            te = (self.headers.get("transfer-encoding") == "chunked")
            if te:
                body = self.rfile.read(29)
                extra_headers.append(('Content-Length', "29"))
                self._respond(200, extra_headers, body)
            else:
                self.error_Response()
        else:
            self.error_Response('Bad path')
            
    do_PUT = do_POST

    def do_DELETE(self):
        if self.path == "/delete":
            extra_headers = [('Content-type', 'text/plain')]
            self._respond(200, extra_headers, '')
        else:
            self.error_Response()

    def do_HEAD(self):
        if self.path == "/ok":
            extra_headers = [('Content-type', 'text/plain')]
            self._respond(200, extra_headers, '')
        else:
            self.error_Response()

    def error_Response(self, message=None):
        req = [
            ('HTTP method', self.command),

            ('path', self.path),