

def __getitem__(self, index):
    'Get a single document or a slice of documents from this cursor.\n\n        Raises :class:`~pymongo.errors.InvalidOperation` if this\n        cursor has already been used.\n\n        To get a single document use an integral index, e.g.::\n\n          >>> db.test.find()[50]\n\n        An :class:`IndexError` will be raised if the index is negative\n        or greater than the amount of documents in this cursor. Any\n        limit previously applied to this cursor will be ignored.\n\n        To get a slice of documents use a slice index, e.g.::\n\n          >>> db.test.find()[20:25]\n\n        This will return this cursor with a limit of ``5`` and skip of\n        ``20`` applied.  Using a slice index will override any prior\n        limits or skips applied to this cursor (including those\n        applied through previous calls to this method). Raises\n        :class:`IndexError` when the slice has a step, a negative\n        start value, or a stop value less than or equal to the start\n        value.\n\n        :Parameters:\n          - `index`: An integer or slice index to be applied to this cursor\n        '
    self.__check_okay_to_chain()
    self.__empty = False
    if isinstance(index, slice):
        if (index.step is not None):
            raise IndexError('Cursor instances do not support slice steps')
        skip = 0
        if (index.start is not None):
            if (index.start < 0):
                raise IndexError('Cursor instances do not supportnegative indices')
            skip = index.start
        if (index.stop is not None):
            limit = (index.stop - skip)
            if (limit < 0):
                raise IndexError(('stop index must be greater than startindex for slice %r' % index))
            if (limit == 0):
                self.__empty = True
        else:
            limit = 0
        self.__skip = skip
        self.__limit = limit
        return self
    if isinstance(index, (int, long)):
        if (index < 0):
            raise IndexError('Cursor instances do not support negativeindices')
        clone = self.clone()
        clone.skip((index + self.__skip))
        clone.limit((- 1))
        for doc in clone:
            return doc
        raise IndexError('no such item for Cursor instance')
    raise TypeError(('index %r cannot be applied to Cursor instances' % index))

dataset/ETHPy150Open blynch/CloudMemeBackend/pymongo/cursor.py Cursor.__getitem__/original