<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def batch(self, source_id, data):
 """ Upload data to the given soruce :param source_id: The ID of the source to upload to :type source_id: str :param data: The data to upload to the source :type data: list :return: dict of REST API output with headers attached :rtype: :class:`~datasift.request.DictResponse` :raises: :class:`~datasift.exceptions.DataSiftApiException`, :class:`requests.exceptions.HTTPError`, :class:`~datasift.exceptions.BadRequest` """

        if type(data) is not list or type(data[0]) is not dict:
            raise BadRequest("Ingestion data must be a list of dicts")
        data = "\r\n".join(map(json.dumps, data))
        return self.request.post(source_id, data, {'Accept-Encoding': 'application/text'})