'Helper function for setting common request headers and calling the
passed in callback which uploads an object.'

def _upload_object(self, object_name, content_type, request_path, request_method='PUT', headers=None, file_path=None, stream=None, upload_func=None, upload_func_kwargs=None, chunked=False, multipart=False):

    headers = (headers or {})
    if (file_path and (not os.path.exists(file_path))):
        raise OSError(('File    %s    does    not    exist' % file_path))
    if ((stream is not None) and (not hasattr(stream, 'next')) and (not hasattr(stream, '__next__'))):
        raise AttributeError(('iterator    object    must    implement    next()    ' + 'method.'))
    if (not content_type):
        if file_path:
            name = file_path
        else:
            name = object_name
        (content_type, _) = libcloud.utils.files.guess_file_mime_type(name)
        if (not content_type):
            if self.strict_mode:
                raise AttributeError('File    content-type    could    not    be    guessed    and    no    content_type    value    is    provided')
            else:
                content_type = DEFAULT_CONTENT_TYPE
    headers['Content-Type'] = content_type
    if stream:
        response = self.connection.request(request_path, method=request_method, data=stream, headers=headers, raw=True)
        (stream_hash, stream_length) = self._hash_buffered_stream(stream, self._get_hash_function())
    else:
        with open(file_path, 'rb') as file_stream:
            response = self.connection.request(request_path, method=request_method, data=file_stream, headers=headers, raw=True)
        with open(file_path, 'rb') as file_stream:
            (stream_hash, stream_length) = self._hash_buffered_stream(file_stream, self._get_hash_function())
    if (not response.success()):
        response.parse_error()
    if upload_func:
        upload_func(**upload_func_kwargs)
    return {'response': response, 'bytes_transferred': stream_length, 'data_hash': stream_hash}
