def download_instances(self, form_id, cursor=0, num_entries=100):
        self.logger.debug("Starting submissions download for %s" % form_id)
        if not self._get_response(self.submission_list_url,
                                  params={'formId': form_id,
                                          'numEntries': num_entries,
                                          'cursor': cursor}):
            self.logger.error("Fetching %s formId: %s, cursor: %s" %
                              (self.submission_list_url, form_id, cursor))
            return

        response = self._current_response
        self.logger.debug("Fetching %s formId: %s, cursor: %s" %
                          (self.submission_list_url, form_id, cursor))
        try:
            xml_doc = clean_and_parse_xml(response.content)
        except ExpatError:
            return

        instances = self.get_instances_uuids(xml_doc)
        path = os.path.join(self.forms_path, form_id, 'instances')

        for uuid in instances:
            self.logger.debug("Fetching %s %s submission" % (uuid, form_id))
            form_str = u'%(formId)s[@version=null and @uiVersion=null]/'\
                u'%(formId)s[@key=%(instanceId)s]' % {
                    'formId': form_id,
                    'instanceId': uuid
                }
            instance_path = os.path.join(path, uuid.replace(':', ''),
                                         'submission.xml')
            if not default_storage.exists(instance_path):
                if self._get_response(self.download_submission_url,
                                      params={'formId': form_str}):
                    instance_res = self._current_response
                    content = instance_res.content.strip()
                    default_storage.save(instance_path, ContentFile(content))
                else:
                    continue
            else:
                instance_res = default_storage.open(instance_path)
                content = instance_res.read()

            try:
                instance_doc = clean_and_parse_xml(content)
            except ExpatError:
                continue

            media_path = os.path.join(path, uuid.replace(':', ''))
            self.download_media_files(instance_doc, media_path)
            self.logger.debug("Fetched %s %s submission" % (form_id, uuid))

        if xml_doc.getElementsByTagName('resumptionCursor'):
            rs_node = xml_doc.getElementsByTagName('resumptionCursor')[0]
            cursor = rs_node.childNodes[0].nodeValue

            if self.resumption_cursor != cursor:
                self.resumption_cursor = cursor
                self.download_instances(form_id, cursor)
dataset/ETHPy150Open kobotoolbox/kobocat/onadata/libs/utils/briefcase_client.py/BriefcaseClient.download_instances/original