Beispiel #1
0
class AgnosticGridOutCursor(AgnosticBaseCursor):
    __motor_class_name__ = 'MotorGridOutCursor'
    __delegate_class__ = gridfs.GridOutCursor

    count = AsyncRead()
    distinct = AsyncRead()
    explain = AsyncRead()
    limit = MotorCursorChainingMethod()
    skip = MotorCursorChainingMethod()
    max_scan = MotorCursorChainingMethod()
    sort = MotorCursorChainingMethod()
    hint = MotorCursorChainingMethod()
    where = MotorCursorChainingMethod()
    max_time_ms = MotorCursorChainingMethod()
    min = MotorCursorChainingMethod()
    max = MotorCursorChainingMethod()
    comment = MotorCursorChainingMethod()

    # PyMongo's GridOutCursor inherits __die from Cursor.
    _Cursor__die = AsyncCommand()

    def next_object(self):
        """Get next GridOut object from cursor."""
        grid_out = super(self.__class__, self).next_object()
        if grid_out:
            grid_out_class = create_class_with_framework(
                AgnosticGridOut, self._framework, self.__module__)

            return grid_out_class(self.collection, delegate=grid_out)
        else:
            # Exhausted.
            return None

    def rewind(self):
        """Rewind this cursor to its unevaluated state."""
        self.delegate.rewind()
        self.started = False
        return self

    def _empty(self):
        return self.delegate._Cursor__empty

    def _query_flags(self):
        return self.delegate._Cursor__query_flags

    def _data(self):
        return self.delegate._Cursor__data

    def _clear_cursor_id(self):
        self.delegate._Cursor__id = 0

    def _close_exhaust_cursor(self):
        # Exhaust MotorGridOutCursors are prohibited.
        pass

    @motor_coroutine
    def _close(self):
        yield self._framework.yieldable(self._Cursor__die())
class AgnosticGridOutCursor(AgnosticCursorBase):
    __delegate_class__ = gridfs.grid_file.GridOutCursor
    __motor_class_name__ = 'MotorGridOutCursor'

    distinct = AsyncRead()
    limit = MotorCursorChainingMethod()
    skip = MotorCursorChainingMethod()
    sort = MotorCursorChainingMethod()
    hint = MotorCursorChainingMethod()
    max_time_ms = MotorCursorChainingMethod()
class AgnosticCursor(AgnosticCursorBase):
    __delegate_class__ = mongomock.collection.Cursor
    __motor_class_name__ = 'MotorCursor'

    alive = ReadOnlyProperty()
    distinct = AsyncRead()
    limit = MotorCursorChainingMethod()
    skip = MotorCursorChainingMethod()
    sort = MotorCursorChainingMethod()
    hint = MotorCursorChainingMethod()
    max_time_ms = MotorCursorChainingMethod()