'Prepares the given HTTP body data.'

def prepare_body(self, data, files, json=None):

    body = None
    content_type = None
    length = None
    if (json is not None):
        content_type = 'application/json'
        body = json_dumps(json)
    is_stream = all([hasattr(data, '__iter__'), (not isinstance(data, (basestring, list, tuple, dict)))])
    try:
        length = super_len(data)
    except (TypeError, AttributeError, UnsupportedOperation):
        length = None
    if is_stream:
        body = data
        if files:
            raise NotImplementedError('Streamed    bodies    and    files    are    mutually    exclusive.')
        if (length is not None):
            self.headers['Content-Length'] = builtin_str(length)
        else:
            self.headers['Transfer-Encoding'] = 'chunked'
    else:
        if files:
            (body, content_type) = self._encode_files(files, data)
        elif (data and (json is None)):
            body = self._encode_params(data)
            if (isinstance(data, basestring) or hasattr(data, 'read')):
                content_type = None
            else:
                content_type = 'application/x-www-form-urlencoded'
        self.prepare_content_length(body)
        if (content_type and ('content-type' not in self.headers)):
            self.headers['Content-Type'] = content_type
    self.body = body
