# 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
# 
# def url_quote(s, charset='utf-8', safe='/:'):
#     """URL encode a single string with a given encoding."""
#     if isinstance(s, unicode):
#         s = s.encode(charset)
#     elif not isinstance(s, str):
#         s = str(s)
#     return urllib.quote(s, safe=safe)
# 
# def url_encode(obj, charset="utf8", encode_keys=False):
#     items = []
#     if isinstance(obj, dict):
#         for k, v in list(obj.items()):
#             items.append((k, v))
#     else:
#         items = list(items)
#         
#     tmp = []
#     for k, v in items:
#         if encode_keys: 
#             k = encode(k, charset)
#         
#         if not isinstance(v, (tuple, list)):
#             v = [v]
#             
#         for v1 in v:
#             if v1 is None:
#                 v1 = ''
#             elif callable(v1):
#                 v1 = encode(v1(), charset)
#             else:
#                 v1 = encode(v1, charset)
#             tmp.append('%s=%s' % (urllib.quote(k), urllib.quote_plus(v1)))
#     return '&'.join(tmp)


import mimetypes
import os
import re
import urllib
from restkit.util import to_bytestring, url_quote, url_encode
            headers.append("")
            self._encoded_hdr = CRLF.join(headers)
        return self._encoded_hdr

    def encode(self, boundary):
        """Returns the string encoding of this parameter"""
        value = self.value
        if re.search("^--%s$" % re.escape(boundary), value, re.M):
            raise ValueError("boundary found in encoded string")

        return "%s%s%s" % (self.encode_hdr(boundary), value, CRLF)

    def iter_encode(self, boundary, blocksize=16384):
        if not hasattr(self.value, "read"):
            yield self.encode(boundary)
        else:
            yield self.encode_hdr(boundary)
            while True:
                block = self.value.read(blocksize)
                if not block:
                    yield CRLF
                    return
                yield block

    def encode_unreadable_value(self, value):
            return value


class MultipartForm(object):
    def __init__(self, params, boundary, headers, bitem_cls=BoundaryItem,

# 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
# 
# def url_quote(s, charset='utf-8', safe='/:'):
#     """URL encode a single string with a given encoding."""
#     if isinstance(s, unicode):
#         s = s.encode(charset)
#     elif not isinstance(s, str):
#         s = str(s)
#     return urllib.quote(s, safe=safe)
# 
# def url_encode(obj, charset="utf8", encode_keys=False):
#     items = []
#     if isinstance(obj, dict):
#         for k, v in list(obj.items()):
#             items.append((k, v))
#     else:
#         items = list(items)
#         
#     tmp = []
#     for k, v in items:
#         if encode_keys: 
#             k = encode(k, charset)
#         
#         if not isinstance(v, (tuple, list)):
#             v = [v]
#             
#         for v1 in v:
#             if v1 is None:
#                 v1 = ''
#             elif callable(v1):
#                 v1 = encode(v1(), charset)
#             else:
#                 v1 = encode(v1, charset)
#             tmp.append('%s=%s' % (urllib.quote(k), urllib.quote_plus(v1)))
#     return '&'.join(tmp)


# Path: restkit/forms.py
import mimetypes
import os
import re
import urllib
from restkit.util import to_bytestring, url_quote, url_encode

            headers.append("")
            self._encoded_hdr = CRLF.join(headers)
        return self._encoded_hdr

    def encode(self, boundary):
        """Returns the string encoding of this parameter"""
        value = self.value
        if re.search("^--%s$" % re.escape(boundary), value, re.M):
            raise ValueError("boundary found in encoded string")

        return "%s%s%s" % (self.encode_hdr(boundary), value, CRLF)

    def iter_encode(self, boundary, blocksize=16384):
        if not hasattr(self.value, "read"):
            yield self.encode(boundary)
        else:
            yield self.encode_hdr(boundary)
            while True:
                block = self.value.read(blocksize)
                if not block:
                    yield CRLF
                    return
                yield block

    def encode_unreadable_value(self, value):
            return value


class MultipartForm(object):
    def __init__(self, params, boundary, headers, bitem_cls=BoundaryItem,

                 quote=url_quote):