+\hR+$dZddlmZddlZddlZddlZddlZddlmZddl m Z m Z m Z m Z mZmZddlmZddlmZddlmZmZmZdd lmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&dd l'm(Z(m)Z)m*Z*m+Z+dd l,m-Z-dd l.m/Z/dd l0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9m:Z:m;Z;mZ>ddl?m@Z@ddlAmBZBmCZCdZDd$dZEGddZFGddZGGddZHeDr ejneJZKGddeKZLGddZMGd d!ZNGd"d#e1ZOy)%z.Tools for representing files stored in GridFS.) annotationsN)abc)AnyIterableMappingNoReturnOptionalcast)Int64)ObjectId)CorruptGridFile FileExistsNoFile)_C_INDEX_CHUNK_OVERHEAD_F_INDEX _SEEK_CUR _SEEK_END _SEEK_SET_UPLOAD_BUFFER_CHUNKS_UPLOAD_BUFFER_SIZEDEFAULT_CHUNK_SIZEEMPTYNEWLN_a_grid_in_property_a_grid_out_property_clear_entity_type_registry) ASCENDING DESCENDING WriteConcern_csot)AsyncClientSession)AsyncCollection) AsyncCursor) AsyncDatabase)anext)validate_string)BulkWriteErrorConfigurationErrorCursorNotFoundDuplicateKeyErrorInvalidOperationOperationFailure)_check_write_command_response)ReadPreference _ServerModeFc8|r|jr tdyy)Nz3GridFS does not support multi-document transactions)in_transactionr,sessions `/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/gridfs/asynchronous/grid_file.py_disallow_transactionsr6As 7))TUU*wceZdZdZdddZddZddZdddZ d ddZ d ddZ ddd Z ddd Z d dd Z dd Z d dd Zy) AsyncGridFS2An instance of GridFS on top of a single Database.c*t|tstdt|t |}|j j s td|||_|jj|_ |jj|_ y)aCreate a new instance of :class:`GridFS`. Raises :class:`TypeError` if `database` is not an instance of :class:`~pymongo.database.Database`. :param database: database to use :param collection: root collection to use .. versionchanged:: 4.0 Removed the `disable_md5` parameter. See :ref:`removed-gridfs-checksum` for details. .. versionchanged:: 3.11 Running a GridFS operation in a transaction now always raises an error. GridFS does not support multi-document transactions. .. versionchanged:: 3.7 Added the `disable_md5` parameter. .. versionchanged:: 3.1 Indexes are only ensured on the first write to the DB. .. versionchanged:: 3.0 `database` must use an acknowledged :attr:`~pymongo.database.Database.write_concern` .. seealso:: The MongoDB documentation on `gridfs `_. z.database must be an instance of Database, not z,database must use acknowledged write_concernN) isinstancer% TypeErrortyper write_concern acknowledgedr) _collectionfiles_fileschunks_chunks)selfdatabase collections r5__init__zAsyncGridFS.__init__Is:(M2LTRZ^L\]^ ^.x8%%22$%ST T#J/&&,, ''.. r7c .t|jfi|S)aCreate a new file in GridFS. Returns a new :class:`~gridfs.grid_file.GridIn` instance to which data can be written. Any keyword arguments will be passed through to :meth:`~gridfs.grid_file.GridIn`. If the ``"_id"`` of the file is manually specified, it must not already exist in GridFS. Otherwise :class:`~gridfs.errors.FileExists` is raised. :param kwargs: keyword arguments for file creation ) AsyncGridInrA)rFkwargss r5new_filezAsyncGridFS.new_filers4++6v66r7cKt|jfi|4d{}|j|d{|jcdddd{S7:7#7 #1d{7swYyxYww)aPut data in GridFS as a new file. Equivalent to doing:: with fs.new_file(**kwargs) as f: f.write(data) `data` can be either an instance of :class:`bytes` or a file-like object providing a :meth:`read` method. If an `encoding` keyword argument is passed, `data` can also be a :class:`str` instance, which will be encoded as `encoding` before being written. Any keyword arguments will be passed through to the created file - see :meth:`~gridfs.grid_file.GridIn` for possible arguments. Returns the ``"_id"`` of the created file. If the ``"_id"`` of the file is manually specified, it must not already exist in GridFS. Otherwise :class:`~gridfs.errors.FileExists` is raised. :param data: data to be written as a file. :param kwargs: keyword arguments for file creation .. versionchanged:: 3.0 w=0 writes to GridFS are now prohibited. N)rKrAwrite_id)rFdatarL grid_files r5putzAsyncGridFS.putsi4t//:6: ! !i//$' ' '== ! ! ! ' ! ! ! !sTA3AA3AAA A3AA3AA3A0$A' %A0,A3NcrKt|j||}|jd{|S7w)aGet a file from GridFS by ``"_id"``. Returns an instance of :class:`~gridfs.grid_file.GridOut`, which provides a file-like interface for reading. :param file_id: ``"_id"`` of the file to get :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. r3N AsyncGridOutrAopenrFfile_idr4gouts r5getzAsyncGridFS.gets7D,,gwGiik   ,757cK|}|||d<t||jj||}|d}|dkrCt|dz }|j dj |j dtn4|j dj |j dt t|d{}t|j||S7#t$rtd ||fzdwxYww) aGet a file from GridFS by ``"filename"`` or metadata fields. Returns a version of the file in GridFS whose filename matches `filename` and whose metadata fields match the supplied keyword arguments, as an instance of :class:`~gridfs.grid_file.GridOut`. Version numbering is a convenience atop the GridFS API provided by MongoDB. If more than one file matches the query (either by `filename` alone, by metadata fields, or by a combination of both), then version ``-1`` will be the most recently uploaded matching file, ``-2`` the second most recently uploaded, etc. Version ``0`` will be the first version uploaded, ``1`` the second version, etc. So if three versions have been uploaded, then version ``0`` is the same as version ``-3``, version ``1`` is the same as version ``-2``, and version ``2`` is the same as version ``-1``. Raises :class:`~gridfs.errors.NoFile` if no such version of that file exists. :param filename: ``"filename"`` of the file to get, or `None` :param version: version of the file to get (defaults to -1, the most recent version uploaded) :param session: a :class:`~pymongo.client_session.AsyncClientSession` :param kwargs: find files by custom metadata. .. versionchanged:: 3.6 Added ``session`` parameter. .. versionchanged:: 3.1 ``get_version`` no longer ensures indexes. Nfilenamer3r uploadDate file_documentr4no version %d for filename %r)r6rCfindabslimitskipsortrrr&rVrAStopAsyncIterationr) rFr^versionr4rLquerycursorrhdocs r5 get_versionzAsyncGridFS.get_versionsP   (E* w'!!%!9 ?G Q;w  j&EV_Fw' tyyJ$JJ6J  !H Js*AAA A AAAAc4t|jg|i|S)a Query GridFS for files. Returns a cursor that iterates across files matching arbitrary queries on the files collection. Can be combined with other modifiers for additional control. For example:: for grid_out in fs.find({"filename": "lisa.txt"}, no_cursor_timeout=True): data = grid_out.read() would iterate through all versions of "lisa.txt" stored in GridFS. Note that setting no_cursor_timeout to True may be important to prevent the cursor from timing out during long multi-file processing work. As another example, the call:: most_recent_three = fs.find().sort("uploadDate", -1).limit(3) would return a cursor to the three most recently uploaded files in GridFS. Follows a similar interface to :meth:`~pymongo.collection.Collection.find` in :class:`~pymongo.collection.Collection`. If a :class:`~pymongo.client_session.AsyncClientSession` is passed to :meth:`find`, all returned :class:`~gridfs.grid_file.GridOut` instances are associated with that session. :param filter: A query document that selects which files to include in the result set. Can be an empty document to include all files. :param skip: the number of files to omit (from the start of the result set) when returning the results :param limit: the maximum number of results to return :param no_cursor_timeout: if False (the default), any returned cursor is closed by the server after 10 minutes of inactivity. If set to True, the returned cursor will never time out on the server. Care should be taken to ensure that cursors with no_cursor_timeout turned on are properly closed. :param sort: a list of (key, direction) pairs specifying the sort order for this query. See :meth:`~pymongo.cursor.Cursor.sort` for details. Raises :class:`TypeError` if any of the arguments are of improper type. Returns an instance of :class:`~gridfs.grid_file.GridOutCursor` corresponding to this query. .. versionchanged:: 3.0 Removed the read_preference, tag_sets, and secondary_acceptable_latency_ms options. .. versionadded:: 2.7 .. seealso:: The MongoDB documentation on `find `_. AsyncGridOutCursorrArFr~rLs r5rezAsyncGridFS.find^s t"$"2"2DTDVDDr7cKt||r+|jj|dg|d{}|duS|jj|dg|d{}|duS737 w)a!Check if a file exists in this instance of :class:`GridFS`. The file to check for can be specified by the value of its ``_id`` key, or by passing in a query document. A query document can be passed in as dictionary, or by using keyword arguments. Thus, the following three calls are equivalent: >>> fs.exists(file_id) >>> fs.exists({"_id": file_id}) >>> fs.exists(_id=file_id) As are the following two calls: >>> fs.exists({"filename": "mike.txt"}) >>> fs.exists(filename="mike.txt") And the following two: >>> fs.exists({"foo": {"$gt": 12}}) >>> fs.exists(foo={"$gt": 12}) Returns ``True`` if a matching file exists, ``False`` otherwise. Calls to :meth:`exists` will not automatically create appropriate indexes; application developers should be sure to create indexes if needed and as appropriate. :param document_or_id: query document, or _id of the document to check for :param session: a :class:`~pymongo.client_session.AsyncClientSession` :param kwargs: keyword arguments are used as a query document, if they're present. .. versionchanged:: 3.6 Added ``session`` parameter. rPr3N)r6rCr)rFdocument_or_idr4rLrs r5existszAsyncGridFS.existssvT w' kk**6E7G*LLA}kk**>E7G*TTA} MTs!0A*A&*A*A( A*(A*)fs)rGr%rHstr)rLrreturnrK)rQrrLrrrNrYrr4Optional[AsyncClientSession]rrV)Nr_N) r^ Optional[str]rk Optional[int]r4rrLrrrV)NN)r^rr4rrLrrrVrYrr4rrNone)r4rrz list[str]) r} Optional[Any]r4rr~rrLrrzOptional[AsyncGridOut]r~rrLrrr)rrr4rrLrrbool)__name__ __module__ __qualname____doc__rIrMrSr[rorrrwr{rrerrqr7r5r9r9Fs<'/R 7!<*#'!#04 9Z9Z9Z. 9Z  9Z  9Zz#'04TT.T T  T.O8 0!%04&&.& &  & &P:E|)-040%0.0 0  0r7r9cJeZdZdZdeddf ddZ d ddZ d ddZej d ddZ ej d ddZ d dd Z ej d dd Z ejddd Zej d dd Zdd Z d ddZej d d dZ d d!dZ d d"dZy)#AsyncGridFSBucketr:rNct|tstdt|t |}||n |j }|j s td||_|||_ |jjj|||_ |jjj|||_||_|j j"j$|_y)a!Create a new instance of :class:`GridFSBucket`. Raises :exc:`TypeError` if `database` is not an instance of :class:`~pymongo.database.Database`. Raises :exc:`~pymongo.errors.ConfigurationError` if `write_concern` is not acknowledged. :param database: database to use. :param bucket_name: The name of the bucket. Defaults to 'fs'. :param chunk_size_bytes: The chunk size in bytes. Defaults to 255KB. :param write_concern: The :class:`~pymongo.write_concern.WriteConcern` to use. If ``None`` (the default) db.write_concern is used. :param read_preference: The read preference to use. If ``None`` (the default) db.read_preference is used. .. versionchanged:: 4.0 Removed the `disable_md5` parameter. See :ref:`removed-gridfs-checksum` for details. .. versionchanged:: 3.11 Running a GridFSBucket operation in a transaction now always raises an error. GridFSBucket does not support multi-document transactions. .. versionchanged:: 3.7 Added the `disable_md5` parameter. .. versionadded:: 3.1 .. seealso:: The MongoDB documentation on `gridfs `_. z3database must be an instance of AsyncDatabase, not Nz"write concern must be acknowledged)r?read_preference)r<r%r=r>rr?r@r) _bucket_namerArD with_optionsrErBrC_chunk_size_bytesclientoptionstimeout_timeout)rFdb bucket_namechunk_size_bytesr?rwtcs r5rIzAsyncGridFSBucket.__init__sR"m,QRVWYRZQ[\] ] ( ,,8mb>N>N$%IJ J'k?(,(8(8(?(?(L(L')M)  (,'7'7'='='J'J'(K(  "2 ))11 r7c~td||||n |jd}|||d<t|jfd|i|S)aOpens a Stream that the application can write the contents of the file to. The user must specify the filename, and can choose to add any additional information in the metadata field of the file document or modify the chunk size. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) with fs.open_upload_stream( "test_file", chunk_size_bytes=4, metadata={"contentType": "text/plain"}) as grid_in: grid_in.write("data I want to store!") # uploaded on close Returns an instance of :class:`~gridfs.grid_file.GridIn`. Raises :exc:`~gridfs.errors.NoFile` if no such version of that file exists. Raises :exc:`~ValueError` if `filename` is not a string. :param filename: The name of the file to upload. :param chunk_size_bytes` (options): The number of bytes per chunk of this file. Defaults to the chunk_size_bytes in :class:`GridFSBucket`. :param metadata: User data for the 'metadata' field of the files collection document. If not provided the metadata field will be omitted from the files collection document. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. r^)r^ chunk_sizemetadatar4r'rrKrA)rFr^rrr4optss r5open_upload_streamz$AsyncGridFSBucket.open_upload_streamsYR  H-!$4$@ dF\F\   'D 4++EWEEEr7ctd|||||n |jd}|||d<t|jfd|i|S)a?Opens a Stream that the application can write the contents of the file to. The user must specify the file id and filename, and can choose to add any additional information in the metadata field of the file document or modify the chunk size. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) with fs.open_upload_stream_with_id( ObjectId(), "test_file", chunk_size_bytes=4, metadata={"contentType": "text/plain"}) as grid_in: grid_in.write("data I want to store!") # uploaded on close Returns an instance of :class:`~gridfs.grid_file.GridIn`. Raises :exc:`~gridfs.errors.NoFile` if no such version of that file exists. Raises :exc:`~ValueError` if `filename` is not a string. :param file_id: The id to use for this file. The id must not have already been used for another file. :param filename: The name of the file to upload. :param chunk_size_bytes` (options): The number of bytes per chunk of this file. Defaults to the chunk_size_bytes in :class:`GridFSBucket`. :param metadata: User data for the 'metadata' field of the files collection document. If not provided the metadata field will be omitted from the files collection document. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. r^)rPr^rrr4r)rFrYr^rrr4rs r5open_upload_stream_with_idz,AsyncGridFSBucket.open_upload_stream_with_idEs\\  H- $4$@ dF\F\    'D 4++EWEEEr7cK|j||||4d{}|j|d{dddd{ttjS7G707"#1d{7swY2xYww)aUploads a user file to a GridFS bucket. Reads the contents of the user file from `source` and uploads it to the file `filename`. Source can be a string or file-like object. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) file_id = fs.upload_from_stream( "test_file", "data I want to store!", chunk_size_bytes=4, metadata={"contentType": "text/plain"}) Returns the _id of the uploaded file. Raises :exc:`~gridfs.errors.NoFile` if no such version of that file exists. Raises :exc:`~ValueError` if `filename` is not a string. :param filename: The name of the file to upload. :param source: The source stream of the content to be uploaded. Must be a file-like object that implements :meth:`read` or a string. :param chunk_size_bytes` (options): The number of bytes per chunk of this file. Defaults to the chunk_size_bytes of :class:`GridFSBucket`. :param metadata: User data for the 'metadata' field of the files collection document. If not provided the metadata field will be omitted from the files collection document. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. r3N)rrOr r rP)rFr^sourcerrr4gins r5upload_from_streamz$AsyncGridFSBucket.upload_from_streamsV** &'+  $ $ ))F# # # $ $ Hcgg&&  $ $ $ $ $ $sSA?A$A?A*A&A* A?A(A?&A*(A?*A<0A3 1A<8A?cK|j|||||4d{}|j|d{dddd{y7.77 #1d{7swYyxYww)aUploads a user file to a GridFS bucket with a custom file id. Reads the contents of the user file from `source` and uploads it to the file `filename`. Source can be a string or file-like object. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) file_id = fs.upload_from_stream( ObjectId(), "test_file", "data I want to store!", chunk_size_bytes=4, metadata={"contentType": "text/plain"}) Raises :exc:`~gridfs.errors.NoFile` if no such version of that file exists. Raises :exc:`~ValueError` if `filename` is not a string. :param file_id: The id to use for this file. The id must not have already been used for another file. :param filename: The name of the file to upload. :param source: The source stream of the content to be uploaded. Must be a file-like object that implements :meth:`read` or a string. :param chunk_size_bytes` (options): The number of bytes per chunk of this file. Defaults to the chunk_size_bytes of :class:`GridFSBucket`. :param metadata: User data for the 'metadata' field of the files collection document. If not provided the metadata field will be omitted from the files collection document. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. r3N)rrO)rFrYr^rrrr4rs r5upload_from_stream_with_idz,AsyncGridFSBucket.upload_from_stream_with_idsrZ22 X/73  $ $ ))F# # # $ $ $ $ $ $ $ $sSA'A A'AAA A'AA'AA'A$A A$ A'crKt|j||}|jd{|S7w)aOpens a Stream from which the application can read the contents of the stored file specified by file_id. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) # get _id of file to read. file_id = fs.upload_from_stream("test_file", "data I want to store!") grid_out = fs.open_download_stream(file_id) contents = grid_out.read() Returns an instance of :class:`~gridfs.grid_file.GridOut`. Raises :exc:`~gridfs.errors.NoFile` if no file with file_id exists. :param file_id: The _id of the file to be downloaded. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. r3NrUrXs r5open_download_streamz&AsyncGridFSBucket.open_download_streams74D,,gwGiik  r\cK|j||d{4d{} |jd{}t|sn|j|6dddd{y7U7N777 #1d{7swYyxYww)auDownloads the contents of the stored file specified by file_id and writes the contents to `destination`. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) # Get _id of file to read file_id = fs.upload_from_stream("test_file", "data I want to store!") # Get file to write to file = open('myfile','wb+') fs.download_to_stream(file_id, file) file.seek(0) contents = file.read() Raises :exc:`~gridfs.errors.NoFile` if no file with file_id exists. :param file_id: The _id of the file to be downloaded. :param destination: a file-like object implementing :meth:`write`. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. r3N)r readchunklenrO)rFrY destinationr4rZchunks r5download_to_streamz$AsyncGridFSBucket.download_to_streams:227G2LL ) )PT"nn..5z!!%(  ) ) )L ). ) ) ) )sdB A/B A1B A7A3"A7 B )A5*B 1B 3A75B 7B =B >B B cKt||jjd|i|d{}|jj d|i|d{|j st d|zy7F7!w)aGiven an file_id, delete this stored file's files collection document and associated chunks from a GridFS bucket. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) # Get _id of file to delete file_id = fs.upload_from_stream("test_file", "data I want to store!") fs.delete(file_id) Raises :exc:`~gridfs.errors.NoFile` if no file with file_id exists. :param file_id: The _id of the file to be deleted. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. rPr3Nrtz0no file could be deleted because none matched %s)r6rCrurErv deleted_countr)rFrYr4ress r5rwzAsyncGridFSBucket.delete)s|, w'KK**E7+;W*MMll&& G'B ?B B cKt||jjd|idd|ii|d{}|jst d||fzy7!w)aRenames the stored file with the specified file_id. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) # Get _id of file to rename file_id = fs.upload_from_stream("test_file", "data I want to store!") fs.rename(file_id, "new_test_name") Raises :exc:`~gridfs.errors.NoFile` if no file with file_id exists. :param file_id: The _id of the file to be renamed. :param new_filename: The new name of the file. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionchanged:: 3.6 Added ``session`` parameter. rP$setr^r3Nz? $ s3AA"AcKt||jjd|idd|ii|d{}|jst d|d|y7"w)arRenames the stored file with the specified filename. For example:: my_db = AsyncMongoClient().test fs = AsyncGridFSBucket(my_db) await fs.upload_from_stream("test_file", "data I want to store!") await fs.rename_by_name("test_file", "new_test_name") Raises :exc:`~gridfs.errors.NoFile` if no file with the given filename exists. :param filename: The filename of the file to be renamed. :param new_filename: The new name of the file. :param session: a :class:`~pymongo.client_session.AsyncClientSession` .. versionadded:: 4.12 r^rr3Nzno files could be renamed z because none matched filename )r6rC update_manyrr)rFr^rr4rs r5rename_by_namez AsyncGridFSBucket.rename_by_names{( w'{{..  "Vj,-G$HRY/  ##,\,<<[\d[gh $ s3AA#A) rr%rrrintr?zOptional[WriteConcern]rzOptional[_ServerMode]rrNNN) r^rrrrOptional[Mapping[str, Any]]r4rrrK) rYrr^rrrrrr4rrrK) r^rrrrrrrr4rrr )rYrr^rrrrrrrr4rrrrr)rYrrrr4rrrr)r^rr4rrrr)r_N)r^rrrr4rrrV) r^rrrrrr4rrr)rYrrrr4rrr)r^rrrr4rrr)rrrrrrIrrr!applyrrrrrwrrerrrrrqr7r5rrsH<  20415 =2 =2=2 =2 . =2 / =2 =2D+/0404 4F4F(4F. 4F . 4F  4Ft+/0404 :F:F:F( :F . :F . :F :Fx [[ +/0404 /'/'/'( /' . /' . /' /'/'b [[ +/0404/$/$/$ /$ ( /$ . /$./$ /$/$dEI%A @ [[VZ!)!)),!)7S!) !)!)F [[WW6 [[EIaa&Ba aa8-E`Z^4[4['*4[:V4[ 4[l [[ 04 2)2)2) 2) . 2)  2)2)jX\*-8T DY]+.9U r7rceZdZUdZ d: d;dZ dd Z e d d d Z de d <e ddZ de d<e ddZde d<e ddZde d<e ddd Zde d<e ddd Zde d<e ddd Zde d <e d!d"d Zde d!<d#e d$<de d%<d&e d'<de d(<d?d)Zd@d*Zd@d+ZdAdBd,ZdAdCd-ZdDd.ZdEd/Zd=d0ZdFdGd1Zd>d2Zd>d3ZdHd4ZdId5Z dJd6Z!d>d7Z"dKd8Z#dLd9Z$y)MrKzClass to write data to GridFS.Nrc t|tstdt||jj s t dt|d|vr|jd|d<d|vr|jd|d<t|tj}|jdt|d<|jdt|d<tj!|d |tj!|d |tj!|d |j"tj!|d |tj!|d t%j&tj!|ddtj!|ddtj!|ddtj!|ddtj!|dgtj!|ddy)aWrite a file to GridFS Application developers should generally not need to instantiate this class directly - instead see the methods provided by :class:`~gridfs.GridFS`. Raises :class:`TypeError` if `root_collection` is not an instance of :class:`~pymongo.collection.AsyncCollection`. Any of the file level options specified in the `GridFS Spec `_ may be passed as keyword arguments. Any additional keyword arguments will be set as additional fields on the file document. Valid keyword arguments include: - ``"_id"``: unique ID for this file (default: :class:`~bson.objectid.ObjectId`) - this ``"_id"`` must not have already been used for another file - ``"filename"``: human name for the file - ``"contentType"`` or ``"content_type"``: valid mime-type for the file - ``"chunkSize"`` or ``"chunk_size"``: size of each of the chunks, in bytes (default: 255 kb) - ``"encoding"``: encoding used for this file. Any :class:`str` that is written to the file will be converted to :class:`bytes`. :param root_collection: root collection to write to :param session: a :class:`~pymongo.client_session.AsyncClientSession` to use for all commands :param kwargs: Any: file level options (see above) .. versionchanged:: 4.0 Removed the `disable_md5` parameter. See :ref:`removed-gridfs-checksum` for details. .. versionchanged:: 3.7 Added the `disable_md5` parameter. .. versionchanged:: 3.6 Added ``session`` parameter. .. versionchanged:: 3.0 `root_collection` must use an acknowledged :attr:`~pymongo.collection.AsyncCollection.write_concern` r?r@r)r6poprr/PRIMARYr[r robject __setattr__rDioBytesIO)rFroot_collectionr4rLcolls r5rIzAsyncGridIn.__init__>sp/?;NtTcOdNef ,,99$%Z[ [w' V #$*JJ~$>F= ! 6 !"(**\":F; *?NLbLbc 5(*5u $jj6HI{4W54$/4DKK84&14BJJL94a04!44E24!1594!1264!6:r7rcK|jddi|jd{}|: |j|jd{2cgc3d{}|dyyy7A776ncc}w}}n#t$rg}YnwxYw||vs(|j |j ||jd{7_w)NrPr`) projectionr4r3key)uniquer4)rr list_indexesr- create_indexitems)rFrH index_keyrrn index_spec index_keyss r5 _create_indexzAsyncGridIn._create_indexs''E1:t}}'UU ; 3=2I2IRVR_R_2I2`,`(u% + V -a $    * --OO%fdmm.s#CA'CA7 A) A7A/A-A+ A-A/$C)A7+A--A/.A76C7 BCBC /C<B?=CcfKtj|dst|j|j |j j tdd{|j |j jtdd{tj|ddyy7P7w)NrFT) r__getattribute__r6rrrrBrrDrrrFs r5_ensure_indexeszAsyncGridIn._ensure_indexess&&t-=> "4== 1$$TZZ%5%5xG G G$$TZZ%6%6$G G G   t%5t < ? G Gs$AB1B-2B1B/B1/B1cbK|jjjd|jdi|jd{|jj j d|jdi|jd{tj|ddy7d7w)z>Remove all chunks/files that may have been uploaded and close.rtrPr3NrT) rrDrvrrrBrurrrs r5abortzAsyncGridIn.abortsjj++ZE9J,KUYUbUb+cccjj))5$**U2C*Ddmm)\\\4D1 d\s%AB/B+AB/B-B/-B/c|jS)zIs this file closed?)rrs r5closedzAsyncGridIn.closeds||r7rP"The ``'_id'`` value for this file.T) read_onlyr^Name of this file.rAlias for `filename`.rzrDDEPRECATED, will be removed in PyMongo 5.0. Mime-type for this file.rlengthLength (in bytes) of this file.) closed_onlyrrChunk size for this file.rraz!Date that this file was uploaded.datetime.datetime upload_datemd5gDEPRECATED, will be removed in PyMongo 5.0. MD5 of the contents of this file if an md5 sum was created.z io.BytesIOrrzlist[dict[str, Any]]rrc|dk(rtj||S||jvr|j|Std|z)Nrz#GridIn object has no attribute '%s')rrrAttributeErrorrFrzs r5 __getattr__zAsyncGridIn.__getattr__sH 7?**46 6 TZZ ::d# #BTIJJr7cL||jvs||jjvrtj|||y||j|<|j rKt r:|jjjd|jdid||iiytdy)NrPrzAsyncGridIn does not support __setattr__ after being closed(). Set the attribute before closing the file or use AsyncGridIn.set() instead) __dict__ __class__rrrr_IS_SYNCrrBrrrFrzvalues r5rzAsyncGridIn.__setattr__s 4== DDNN,C,C$C   tT5 1 %DJJt ||JJ$$// 58I0JVVZ\aUbLcd(d r7cK||j|<|jrB|jjj d|jdid||iid{yy7w)NrPr)rrrrBrrs r5setzAsyncGridIn.sets]  4 <<**""--udjj6G.H6TXZ_S`Jab b b  bsAA#A!A#cK|jd{t||jksJ|r[|jj |j d|j |d|xjt|tzz c_|jsy|s/|jtk\st|jtk\rH |jj|j|jd{g|_d |_|xj d z c_|xj&t|z c_y767I#t$rv}|jd}|D]4}|j!ddvs|j#|j d6d|i}|jd}|r|d |d <t%|d}~wwxYww) zFlush `data` to a chunk.NrP)rtnrQr3 writeErrorscode)i*i*i&1writeConcernErrorsr_writeConcernErrorrr`)rrrrappendrrrrrrrE insert_manyrr(detailsr[_raise_file_existsr.r)rFrQforceexc write_errorserrrwcess r5 _flush_datazAsyncGridIn._flush_datas""$$$4yDOO+++     & &!ZZ.T5G5GQUV   $ $D O(C C $""  ''+>>4&&'+@@ ll..t/B/BDMM.ZZZ#%D '(D $ a #d)#A % [! "{{=9 'CCwwv*??// 50ABC(6{{#7826r(F./-f5 sNGE B9G4EEE AGE G'G A G  GGcK|j|jj|d{|jjt j |_y78w)z)Flush the buffer contents out to a chunk.r'N)r,rgetvaluecloserr)rFr's r5 _flush_bufferzAsyncGridIn._flush_buffersOt||446eDDD zz|  Es/A,A*9A,cK |jdd{t|j|jd<tjj tj j|jd<|jjj|j|jd{S77#t$r|j|jYywxYww)zFlush the file to the database.Tr.Nr )tzrar3)r1r rrdatetimenowtimezoneutcrrB insert_onerr+r&rPrs r5_flushzAsyncGridIn._flushs .$$4$0 0 0#(#8DJJx '/'8'8'<'<@Q@Q@U@U'<'VDJJ| $))44TZZ4WW W 1 X  .  # #DHH - .sKC6C CB)C C C C6C C $C30C62C33C6ctd|z)z3Raise a FileExists exception for the given file_id.zfile with _id %r already exists)r)rFrYs r5r&zAsyncGridIn._raise_file_exists#s:WDEEr7cK|js0|jd{tj|ddyy7w)zFlush the file and close it. A closed file cannot be written any more. Calling :meth:`close` more than once is allowed. NrT)rr9rrrs r5r0zAsyncGridIn.close's8 ||++-     tY 5 s AAAc,tjd)NreadrUnsupportedOperationrFsizes r5r=zAsyncGridIn.read1s%%f--r7cyNFrqrs r5readablezAsyncGridIn.readable4r7cyrCrqrs r5seekablezAsyncGridIn.seekable7rEr7c|K|jr td |j}tj|r|j|d{y|jj!dkDrt|j"|jj!z }|r3 ||}|jj)|t+||kry|j-d{||j"}|r^t+||j"k(rF|j/|d{||j"}|rt+||j"k(rF|jj)|y#t$rt |t t fs tddt |t r6 |j|j}n#t$r tddwxYwtj|j}YwxYw7#t$$r|j'd{7wxYw7T7w)agWrite data to the file. There is no return value. `data` can be either a string of bytes or a file-like object (implementing :meth:`read`). If the file has an :attr:`encoding` attribute, `data` can also be a :class:`str` instance, which will be encoded as :attr:`encoding` before being written. Due to buffering, the data may not actually be written to the database until the :meth:`close` method is called. Raises :class:`ValueError` if this file is already closed. Raises :class:`TypeError` if `data` is not an instance of :class:`bytes`, a file-like object, or an instance of :class:`str`. Unicode data is only allowed if the file has an :attr:`encoding` attribute. :param data: string of bytes or file-like object to be written to the file zcannot write to a closed filez+can only write strings or file-like objectsNz7must specify an encoding for file in order to write strr)r ValueErrorr=rr<rbytesr=encodeencodingrrinspectiscoroutinefunction _write_asyncrtellr BaseExceptionrrOrr1r,)rFrQr=spaceto_writes r5rOzAsyncGridIn.write:s( <<<= = )99D  & &t ,##D) ) )||  "Q&$,,*;*;*==#';LL&&x08}u,((***DOO,Hs8}?&&x0000s8}? LL  x (C )dS%L1 MNTXX$$ ;;t}}5D% #Q  ::d#((D ) *)"jjl** +1sH< E5)H<H A H<H%=H<"H6#AH<'H9(0H<H<5;H 1G  H  G##"H H<H  H<H3+H.,H33H<9H<cK|jjdkDr||j|jjz }|r; ||d{}|jj |t ||kry|jd{||jd{}|rft ||jk(rN|j|d{||jd{}|rt ||jk(rN|jj |y7#t$r|j d{7wxYw7777jwNr) rrPrrQrrOrr1r,)rFr=rRrSs r5rOzAsyncGridIn._write_asyncws& <<    "OOdll&7&7&99E%)%[0H ""8,x=5($$& & &doo..3x=DOO;""8, , ,!$//22H3x=DOO; 8$ 1$**,&& '. ,2sAE+ D<D:D<=E+E#E+1E%22E+$E'%E+>E)?E+E+:D<<E EE  E+%E+'E+)E+cPK|D]}|j|d{y7w)zSWrite a sequence of strings to the file. Does not add separators. N)rO)rFsequencelines r5 writelineszAsyncGridIn.writeliness,  #D**T" " " # "s &$&cyNTrqrs r5 writeablezAsyncGridIn.writeabler7cK|Sw)z)Support for the context manager protocol.rqrs r5 __aenter__zAsyncGridIn.__aenter__s  ctK||jd{ytj|ddy7w)zSupport for the context manager protocol. Close the file if no exceptions occur and allow exceptions to propagate. NrTF)r0rrrFexc_typeexc_valexc_tbs r5 __aexit__zAsyncGridIn.__aexit__s@  **,      tY 5 s 868r)rr#r4rrLrrr)rHr#rrrrrrrrrrrzrrr)rzrrrrr)F)rQrr'rrr)r'rrr)rr)rYrrrr_)rArrr)rQrrr)r=rrr)rWz Iterable[Any]rr)rrKrcrrdrrerrr)%rrrrrIrrrpropertyrrrP__annotations__r^rzrr rrrrrrr,r1r9r&r0r=rDrGrOrOrYr\r_rfrqr7r5rKrK;s( 15V;(V;.V; V;  V;p)69CG "=2 #5*NZ^_C_1*>RSHmS-j:QRD-R"5]#L-&h0Q_cdFCd)+7R^bcJc%89t&K"- qC  M((K$c "$H$ .F6.;)z%(# r7rKcTeZdZUdZ d> d?fd ZeddZded<eddZded<edd Z ded <ed d Z d ed<eddZ ded<eddZ ded<eddZ ded<eddZded<eddZded<edd Zd ed<ded!<ded"<esd#ed$<d@d%ZdAd&ZdBdCd'ZdBdDd(ZdEd)ZdFd*ZdGd+Zd@d,ZdHdId-ZdBdCd.ZdJd/ZefdKd0ZdGd1ZdLd2Z dEfd3 Z!dMd4Z"dNd5Z#dGd6Z$dLd7Z%dOd8Z&dPd9Z'dEd:Z(dGd;Z)dQdRd<Z*dEd=Z+xZ,S)SrVz!Class to read data out of GridFS.cft|tstdt|t |t |}t ||j|_ |j|_ ||_ t|_d|_d|_d|_||_||_t(sd|_yy)aRead a file from GridFS Application developers should generally not need to instantiate this class directly - instead see the methods provided by :class:`~gridfs.GridFS`. Either `file_id` or `file_document` must be specified, `file_document` will be given priority if present. Raises :class:`TypeError` if `root_collection` is not an instance of :class:`~pymongo.collection.AsyncCollection`. :param root_collection: root collection to read from :param file_id: value of ``"_id"`` for the file to read :param file_document: file document from `root_collection.files` :param session: a :class:`~pymongo.client_session.AsyncClientSession` to use for all commands .. versionchanged:: 3.8 For better performance and to better follow the GridFS spec, :class:`GridOut` now uses a single cursor to read all the chunks in the file. .. versionchanged:: 3.6 Added ``session`` parameter. .. versionchanged:: 3.0 Creating a GridOut does not immediately retrieve the file metadata from the server. Metadata is fetched when first needed. rrNF)r<r#r=r>r6rsuperrIrDrErBrC_file_idrr _buffer_pos _chunk_iterrrrrr)rFrrYrcr4rs r5rIzAsyncGridOut.__init__sL/?;NtTcOdNef  w'5oF &-- %++   "  DKr7rPrrr^rrrrzrrrrr r rrr rraz'Date that this file was first uploaded.r raliaseszJDEPRECATED, will be removed in PyMongo 5.0. List of aliases for this file.zOptional[list[str]]rzMetadata attached to this file.rrrrrsrrcZK|jd{}|r|St7wr)readlinerj)rFrXs r5 __anext__zAsyncGridOut.__anext__ s*(D $& &)s +)+cDK|2cgc3d{}| 76c}Scc}wwrrq)rFxs r5to_listzAsyncGridOut.to_lists!%)**A** **s$   cDK|j|dd{S7w)}Read one line or up to `size` bytes from the file. :param size: the maximum number of bytes to read T)rArXN_read_size_or_liner@s r5rvzAsyncGridOut.readlines$ 00d0FF FFs   c|K|jd{g}t|j|jz }d}|dkDrp|j dd{}|t |z }|j |t|j|jz }d|cxkr|kr |S|dkDrp|S77^w)r|NrT)rX)rWrr rr~rr#)rFrAlines remainder bytes_readrXs r5 readlineszAsyncGridOut.readliness ))+  EDKK(4>>9IJa-!44$4??c$i'  T" ,t~~= t(j(L) a-L  @s)B<B8AB<B:AB<6B<:B<c6K|jst|j|jj d|j i|jd{|_|js%t d|jd|j yy7<w)NrPr3zno file in gridfs collection z with _id )rr6rrCrrqrrs r5rWzAsyncGridOut.open.szz "4== 1#{{33UDMM4JTXTaTa3bbDJ::3DKK?*T]]L]^bsABB=Bctr|jn|jstd|z||jvr|j|St d|z)NzBYou must call AsyncGridOut.open() before accessing the %s propertyz$GridOut object has no attribute '%s')rrWrr,rrs r5rzAsyncGridOut.__getattr__7sY  IIK"TW[[  4:: ::d# #CdJKKr7cyr[rqrs r5rDzAsyncGridOut.readableBr]r7cK|jd{t|j|jz }t}t |j }|dkDr|j|jd}n|jt |jkrt ||jz|z }|j't||j|j||_ |jjd{}|d|j|zd}|s td|xjt|z c_t|_d|_|S7G7[w)z{Reads a chunk at a time. If the current position is within a chunk the remainder of the chunk is returned. NrrQztruncated chunk)rWrrrrrrrrr rs_AsyncGridOutChunkIteratorrErnextr )rFreceived chunk_datar chunk_numberrs r5rzAsyncGridOut.readchunkEs,iikt||$t'7'77 ) a<d&6&6&89J ^^c$++. .4>> 9ZGHL'#=$,, |$ **//11Evt~~ 'B'DEJ%&788 #j/) / 2s#E"EC-E"E AE" E"c&K|jd{t|j|jz }|dks||kDr|}|dk(rtSd}g}||krW||z }|j ra|j }|j }t||j d} t|_d|_|xjt| z c_n%|jd{}d}t|} |r/|jt|||z|z } | dk\r || zdz}| dz}t| |kDr[|j| d|||_||z|_|xjt|j |j z zc_n|j| |t| z }||krW||k(r/|jr# |jjd{dj!|S777#t$rY$wxYww)z&Internal read() and readline() helper.Nrr`r7)rWrr rrrrr memoryviewrrrerr#rsrrjjoin) rFrArXrrrQneededbuf chunk_startrposs r5r~zAsyncGridOut._read_size_or_linebsiik $t~~5 !8ti'D 19LoH_F||ll".. '_T-=-=-?@ $ #$ #j/1 NN,, '_ hhuk;3GH;V!8#c>A-D 1WF:' Jw/0" #.#7 #dll"3d6F6F"FF J' J 'H9o> 9 !1!1 &&++---xx~_ *-,.%  s_HG:C H#G=$CH5HH$H%H)H=HH H H HHcBK|j|d{S7w)aRead at most `size` bytes from the file (less if there isn't enough data). The bytes are returned as an instance of :class:`bytes` If `size` is negative or omitted all data is read. :param size: the number of bytes to read .. versionchanged:: 3.8 This method now only checks for extra chunks after reading the entire file. Previously, this method would check for extra chunks on every call. )rANr}r@s r5r=zAsyncGridOut.reads",,$,7777s c|jS)z)Return the current position of this file.)rrs r5rPzAsyncGridOut.tells ~~r7cK|tk(r|}nG|tk(r|j|z}n.|tk(rt |j |z}n t dd|dkr t dd||jk(r|S||_t|_d|_ |jr)|jjd{d|_ |S7 w)aKSet the current position of this file. :param pos: the position (or offset if using relative positioning) to seek to :param whence: where to seek from. :attr:`os.SEEK_SET` (``0``) for absolute file positioning, :attr:`os.SEEK_CUR` (``1``) to seek relative to the current position, :attr:`os.SEEK_END` (``2``) to seek relative to the file's end. .. versionchanged:: 4.1 The method now returns the new position in the file, to conform to the behavior of :meth:`io.IOBase.seek`. zInvalid value for `whence`rz*Invalid value for `pos` - must be positiveN) rrrrrr OSErrorrrrrrsr0)rFrwhencenew_poss r5seekzAsyncGridOut.seeks Y G y nns*G y $++&,G":; ; Q;"JK K dnn $N     ""((* * *#D  +sB8C :C;C cyr[rqrs r5rGzAsyncGridOut.seekabler]r7c|S)a-Return an iterator over all of this file's data. The iterator will return lines (delimited by ``b'\n'``) of :class:`bytes`. This can be useful when serving files using a webserver that handles such an iterator efficiently. .. versionchanged:: 3.8 The iterator now raises :class:`CorruptGridFile` when encountering any truncated, missing, or extra chunk in a file. The previous behavior was to only raise :class:`CorruptGridFile` on a missing chunk. .. versionchanged:: 4.0 The iterator now iterates over *lines* in the file, instead of chunks, to conform to the base class :py:class:`io.IOBase`. Use :meth:`GridOut.readchunk` to read chunk by chunk instead of line by line. rqrs r5 __aiter__zAsyncGridOut.__aiter__s & r7cK|jr)|jjd{d|_trt|yd|_y7(w)z(Make GridOut more generically file-like.NT)rsr0rrpr)rFrs r5r0zAsyncGridOut.closesH   ""((* * *#D   GMODK +s*AA)Ac,tjd)NrOr>)rFrs r5rOzAsyncGridOut.writes%%g..r7c,tjd)NrYr>)rFrs r5rYzAsyncGridOut.writeliness%%l33r7cyrCrqrs r5writablezAsyncGridOut.writablerEr7cK|Sw)nMakes it possible to use :class:`AsyncGridOut` files with the async context manager protocol. rqrs r5r_zAsyncGridOut.__aenter__s  r`c@K|jd{y7w)rNF)r0rbs r5rfzAsyncGridOut.__aexit__sjjl s c,tjd)Nfilenor>rs r5rzAsyncGridOut.filenos%%h//r7cyrrqrs r5flushzAsyncGridOut.flush s r7cyrCrqrs r5isattyzAsyncGridOut.isattyrEr7c,tjd)Ntruncater>r@s r5rzAsyncGridOut.truncates%%j11r7cyrrqrs r5__del__zAsyncGridOut.__del__s r7r) rr#rYrrcrr4rrrrrJ)r list[bytes]rj)rArrrJ)rArrrrgrirh)r_F)rArrXrrrJ)rr)rrrrrrrrV)rrrr)rrrrrk)rrr)rArrr)-rrrrrIrrPrmr^rzrr rrrtrrrrwrzrvrrWrrDrr~r=rPrrrGrr0rOrYrr_rfrrrrr __classcell__rs@r5rVrVs+ "&'+04 < (< < % < . <  < |$E+OPCP(5IJHcJ$Z1HID#I"6]#L-'x1RSFCS*;8STJT%9?&K"$8_$G -A5-H). qC J   '  + G & L:1f8 2;%N*/4 0 2 r7rVcleZdZUdZ d dZded<d dZddZddZddZ dd Z e Z dd Z y )rzIterates over a file's chunks using a single cursor. Raises CorruptGridFile when encountering any truncated, missing, or extra chunk in a file. c:|j|_t|j|_t|j|_||_||_||_tjt|j |jz |_ d|_ yr)rPrr _chunk_sizer _lengthrEr _next_chunkmathceilfloat _num_chunks_cursor)rFgrid_outrDr4 next_chunks r5rIz#_AsyncGridOutChunkIterator.__init__%st<<x2238??+   %99U4<<%84;K;K%KL r7zOptional[AsyncCursor]rc||jdz kr |jS|j|j|jdz zz S)Nr`)rrr)rFchunk_ns r5expected_chunk_lengthz0_AsyncGridOutChunkIterator.expected_chunk_length7sF T%%) )## #||t//43C3Ca3GHIIr7c|Srrqrs r5rz$_AsyncGridOutChunkIterator.__aiter__< r7cd|ji}|jdkDrd|ji|d<t|j|jj |dg|j|_y)Nrtrz$gter)rr`)rir4)rPrr6rrErer)rFr}s r5_create_cursorz)_AsyncGridOutChunkIterator._create_cursor?sadhh'   a !4#3#34F3Kt}}-||((xj$--(X r7crK|j|j|jJ |jjd{S7#t$rY|jj d{7|j|jjd{7cYSwxYww)aReturn the next chunk and retry once on CursorNotFound. We retry on CursorNotFound to maintain backwards compatibility in cases where two calls to read occur more than 10 minutes apart (the server's default cursor timeout). N)rrrr*r0rs r5_next_with_retryz+_AsyncGridOutChunkIterator._next_with_retryFs <<     !<<+ ++ -**,, ,, -,,$$& & &    !**,,, , -sR+B7A A AB7A&B48A;92B4+B.,B41B73B44B7c K |jd{}|d|jk7r5|j d{t d|j|dfz|d|jk\rCt |dr5|j d{t d|j|dfz|j|d}t |d|k7r8|j d{t d|d|t |dfz|xjdz c_|S7#t$r4|j|jk\rt d|jzdwxYw7.77w)Nz no chunk #%drz;Missing chunk: expected chunk #%d but found chunk with n=%drQz?Extra chunk found: expected %d chunks but found chunk with n=%dzRtruncated chunk #%d: expected chunk length to be %d but found chunk with length %dr`)rrjrrr r0rr)rFrexpected_lengths r5rz_AsyncGridOutChunkIterator.nextWs O//11E :)) )**,  !"%)%5%5uSz$BC  :)) )5=!jjl""%&)-)9)95:(FG 44U3Z@ uV}  0**,  !-05c OSQVW]Q^M_/`a  A ?2! O4#3#33!.43C3C"CD$ N O # s]E6D/D,D/%E6E/AE6E2AE60E41;E6,D//=E,,E62E64E6c|K|jr*|jjd{d|_yy7 wr)rr0rs r5r0z _AsyncGridOutChunkIterator.close|s2 <<,,$$& & &DL  &s *<:<N) rrVrDr#r4rrrrr)rrrr)rrrg)rzMapping[str, Any]) rrrrrIrmrrrrrrwr0rqr7r5rrsl  .      #"J Y-"!FI r7rc4eZdZ ddZddZddZeZy)AsyncGridOutIteratorc*t|||d|_yrU)rrs)rFrrDr4s r5rIzAsyncGridOutIterator.__init__s6hQRSr7c|Srrqrs r5rzAsyncGridOutIterator.__aiter__rr7cnK|jjd{}t|dS7w)NrQ)rsrrJ)rFrs r5rzAsyncGridOutIterator.nexts1&&++--U6]##.s 535N)rrVrDr#r4r")rrr)rrrrIrrrwrqr7r5rrs4T$T.=THZT $Ir7rceZdZdZ d d fd Zd fd Zd d dZeZd dZd dZ ddZ xZ S)rzA cursor / iterator for returning GridOut objects as the result of an arbitrary query against the GridFS files collection. c t|t|}||_t ||j |||||||y)ayCreate a new cursor, similar to the normal :class:`~pymongo.cursor.Cursor`. Should not be called directly by application developers - see the :class:`~gridfs.GridFS` method :meth:`~gridfs.GridFS.find` instead. .. versionadded 2.7 .. seealso:: The MongoDB documentation on `cursors `_. )rhrgno_cursor_timeoutri batch_sizer4N)r6r_root_collectionrprIrB) rFrHr}rhrgrrirr4rs r5rIzAsyncGridOutCursor.__init__sQ* w'0< !+     /!  r7cKt|jt| d{}t |j ||jS7&w)z$Get next GridOut object from cursor.Nrb)r6r4rprrVr)rF next_filers r5rzAsyncGridOutCursor.nextsBt||,',.( D11TXT`T`aa)s'AA'AcK||2cgc3d{}| |dkr tdg}t|D])}|j|jd{+|S7R6c}Scc}w7w)zConvert the cursor to a list.Nr`z'to_list() length must be greater than 0)rIranger#r)rFr ryret_s r5rzzAsyncGridOutCursor.to_listsr >%)**A A:FG Gv *A JJTYY[( ) * +* ** )sAA/A(A$A" A$A(>A/A-  A/"A$$A(% A/ctdNz'Method does not exist for GridOutCursorNotImplementedErrorrs r5 add_optionzAsyncGridOutCursor.add_option!"KLLr7ctdrrrs r5 remove_optionz AsyncGridOutCursor.remove_optionrr7c0t|j|S)zACreates an empty GridOutCursor for information to be copied into.r3)rr)rFr4s r5 _clone_basezAsyncGridOutCursor._clone_bases!$"7"7IIr7)NrrFNrN)rHr#r}rrhrrgrrrrirrrr4rrrrr)r rrzlist[AsyncGridOut])r~rrLrrr)r4rrr) rrrrrIrrzrwrrrrrs@r5rrs/3"'"04$ #$ ,$  $  $  $ $ $ .$  $ Lb IMMJr7r)r4rrr)Pr __future__rr4rMrr collectionsrtypingrrrrr r bson.int64r bson.objectidr gridfs.errorsr rrgridfs.grid_file_sharedrrrrrrrrrrrrrrpymongorrr r!#pymongo.asynchronous.client_sessionr"pymongo.asynchronous.collectionr#pymongo.asynchronous.cursorr$pymongo.asynchronous.databaser%pymongo.asynchronous.helpersr&pymongo.commonr'pymongo.errorsr(r)r*r+r,r-pymongo.helpers_sharedr.pymongo.read_preferencesr/r0rr6r9rrKIOBaserGRIDOUT_BASE_CLASSrVrrrrqr7r5rs5" CC"== ?>B;37.*A@ V DDN k k \ll^ #+RYYn %n b a a H   FJFJr7