#NEWLINE# def get_version( self , filename = None , version = ( - 1 ) , **kwargs ) : #NEWLINE# #INDENT# 'Get a file from GridFS by ``"filename"`` or metadata fields.\n\n        Returns a version of the file in GridFS whose filename matches\n        `filename` and whose metadata fields match the supplied keyword\n        arguments, as an instance of :class:`~gridfs.grid_file.GridOut`.\n\n        Version numbering is a convenience atop the GridFS API provided\n        by MongoDB. If more than one file matches the query (either by\n        `filename` alone, by metadata fields, or by a combination of\n        both), then version ``-1`` will be the most recently uploaded\n        matching file, ``-2`` the second most recently\n        uploaded, etc. Version ``0`` will be the first version\n        uploaded, ``1`` the second version, etc. So if three versions\n        have been uploaded, then version ``0`` is the same as version\n        ``-3``, version ``1`` is the same as version ``-2``, and\n        version ``2`` is the same as version ``-1``.\n\n        Raises :class:`~gridfs.errors.NoFile` if no such version of\n        that file exists.\n\n        :Parameters:\n          - `filename`: ``"filename"`` of the file to get, or `None`\n          - `version` (optional): version of the file to get (defaults\n            to -1, the most recent version uploaded)\n          - `**kwargs` (optional): find files by custom metadata.\n\n        .. versionchanged:: 3.1\n           ``get_version`` no longer ensures indexes.\n        ' #NEWLINE# query = kwargs #NEWLINE# if ( filename is not None ) : #NEWLINE# #INDENT# query [ 'filename' ] = filename #NEWLINE# #UNINDENT# cursor = self . __files . find ( query ) #NEWLINE# if ( version < 0 ) : #NEWLINE# #INDENT# skip = ( abs ( version ) - 1 ) #NEWLINE# cursor . limit ( ( - 1 ) ) . skip ( skip ) . sort ( 'uploadDate' , DESCENDING ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cursor . limit ( ( - 1 ) ) . skip ( version ) . sort ( 'uploadDate' , ASCENDING ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# grid_file = next ( cursor ) #NEWLINE# return GridOut ( version . __collection , file_document = grid_file ) #NEWLINE# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# raise NoFile ( ( 'no version %d for filename %r' % ( version , filename ) ) )