Ejemplo n.º 1
0
    def next(self):
        """Read the next result from the cursor.

        :returns: the next item in the cursor
        :rtype: dict
        :raises: StopIteration, CursorNextError
        """
        if not self.batch() and self.has_more():
            res = self._conn.put("/_api/export/{}".format(self.id))
            if res.status_code not in HTTP_OK:
                raise CursorNextError(res)
            self._data = res.body
        elif not self.batch() and not self.has_more():
            raise StopIteration
        return self.batch().pop(0)
Ejemplo n.º 2
0
    def fetch(self):
        """Fetch the next batch from server and update the cursor.

        :return: New batch details.
        :rtype: dict
        :raise arango.exceptions.CursorNextError: If batch retrieval fails.
        :raise arango.exceptions.CursorStateError: If cursor ID is not set.
        """
        if self._id is None:
            raise CursorStateError('cursor ID not set')
        request = Request(method='put',
                          endpoint='/_api/{}/{}'.format(self._type, self._id))
        resp = self._conn.send_request(request)

        if not resp.is_success:
            raise CursorNextError(resp, request)
        return self._update(resp.body)
Ejemplo n.º 3
0
 def handler(res):
     if res.status_code not in HTTP_OK:
         raise CursorNextError(res)
     return res.body