def ok(doc): if doc is None: raise NoFile( "TxMongo: no file in gridfs with filename {0}".format( repr(filename))) return GridOut(self.__collection, doc)
def get_last_version(self, filename): """Get a file from GridFS by ``"filename"``. Returns the most recently uploaded file in GridFS with the name `filename` as an instance of :class:`~gridfs.grid_file.GridOut`. Raises :class:`~gridfs.errors.NoFile` if no such file exists. An index on ``{filename: 1, uploadDate: -1}`` will automatically be created when this method is called the first time. :Parameters: - `filename`: ``"filename"`` of the file to get .. versionadded:: 1.6 """ self.__files.ensure_index( filter.sort(ASCENDING("filename") + DESCENDING("uploadDate"))) doc = yield self.__files.find_one({"filename": filename}, filter=filter.sort( DESCENDING("uploadDate"))) if doc is None: raise NoFile("TxMongo: no file in gridfs with filename {0}".format( repr(filename))) defer.returnValue(GridOut(self.__collection, doc))
def get(self, file_id): """Get a file from GridFS by ``"_id"``. Returns an instance of :class:`~gridfs.grid_file.GridOut`, which provides a file-like interface for reading. :Parameters: - `file_id`: ``"_id"`` of the file to get .. versionadded:: 1.6 """ doc = yield self.__files.find_one({'_id': file_id}) defer.returnValue(GridOut(self.__collection, doc))
def get(self, file_id): """Get a file from GridFS by ``"_id"``. Returns an instance of :class:`~gridfs.grid_file.GridOut`, which provides a file-like interface for reading. :Parameters: - `file_id`: ``"_id"`` of the file to get .. versionadded:: 1.6 """ doc = yield self.__collection.files.find_one({"_id": file_id}) if doc is None: raise NoFile("TxMongo: no file in gridfs with _id {0}".format( repr(file_id))) defer.returnValue(GridOut(self.__collection, doc))
def _cb_get_last_version(self, docs, filename): try: grid_file = docs[0] return GridOut(self.__collection, grid_file) except IndexError: raise NoFile("no file in gridfs with filename %r" % filename)
def ok(cursor): if cursor: return GridOut(self.__collection, cursor[0]) raise NoFile("no version %d for filename %r" % (version, filename))