
    &g*3                   0   S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJrJrJrJr  SSKJr  SSKJr  SSKJrJrJr  SS	KJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&  SS
K'J(r(J)r)J*r*J+r+  SSK,J-r-  SSK.J/r/  SSK0J1r1  SSK2J3r3  SSK4J5r5  SSK6J7r7  SSK8J9r9J:r:J;r;J<r<J=r=J>r>  SSK?J@r@  SSKAJBrBJCrC  SrDS$S jrE " S S5      rF " S S5      rG " S S5      rH\D(       a  \R                  O\JrK " S S\K5      rL " S S5      rM " S  S!5      rN " S" S#\15      rOg)%z.Tools for representing files stored in GridFS.    )annotationsN)abc)AnyIterableMappingNoReturnOptionalcast)Int64)ObjectId)CorruptGridFile
FileExistsNoFile)_C_INDEX_CHUNK_OVERHEAD_F_INDEX	_SEEK_CUR	_SEEK_END	_SEEK_SET_UPLOAD_BUFFER_CHUNKS_UPLOAD_BUFFER_SIZEDEFAULT_CHUNK_SIZEEMPTYNEWLN_a_grid_in_property_a_grid_out_property_clear_entity_type_registry)	ASCENDING
DESCENDINGWriteConcern_csot)AsyncClientSession)AsyncCollection)AsyncCursor)AsyncDatabase)anext)validate_string)BulkWriteErrorConfigurationErrorCursorNotFoundDuplicateKeyErrorInvalidOperationOperationFailure)_check_write_command_response)ReadPreference_ServerModeFc                L    U (       a  U R                   (       a  [        S5      eg g )Nz3GridFS does not support multi-document transactions)in_transactionr,   sessions    bC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\gridfs/asynchronous/grid_file.py_disallow_transactionsr6   A   s     7))TUU *w    c                      \ rS rSrSrSSS jjrSS jrSS jrSSS jjr   S         SS jjr	  S       SS	 jjr
SSS
 jjrSSS jjr  S         SS jjrSS jr  S       SS jjrSrg)AsyncGridFSF   2An instance of GridFS on top of a single Database.c                <   [        U[        5      (       d  [        S[        U5       35      e[	        U5      nUR
                  R                  (       d  [        S5      eX   U l        U R                  R                  U l
        U R                  R                  U l        g)aP  Create 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 <https://dochub.mongodb.org/core/gridfs>`_.
z.database must be an instance of Database, not z,database must use acknowledged write_concernN)
isinstancer%   	TypeErrortyper   write_concernacknowledgedr)   _collectionfiles_fileschunks_chunks)selfdatabase
collections      r5   __init__AsyncGridFS.__init__I   s    : (M22LTRZ^L\]^^.x8%%22$%STT#/&&,,''..r7   c                .    [        U R                  40 UD6$ )a  Create 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
)AsyncGridInrB   )rG   kwargss     r5   new_fileAsyncGridFS.new_filer   s     4++6v66r7   c                   #    [        U R                  40 UD6 ISh  vN nUR                  U5      I Sh  vN   UR                  sSSS5      ISh  vN   $  N: N# N	! , ISh  vN  (       d  f       g= f7f)aP  Put 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)rM   rB   write_id)rG   datarN   	grid_files       r5   putAsyncGridFS.put   sT     4 t//:6::i//$'''== ;::' ;:::sT   A8AA8AAAA8AA8AA8A5$A'%A51A8Nc                j   #    [        U R                  XS9nUR                  5       I Sh  vN   U$  N7f)aD  Get 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.
r3   NAsyncGridOutrB   openrG   file_idr4   gouts       r5   getAsyncGridFS.get   s4      D,,gG iik 	   (313c                  #    UnUb  XS'   [        U5        U R                  R                  XSS9nUc  SnUS:  aC  [        U5      S-
  nUR	                  S5      R                  U5      R                  S[        5        O4UR	                  S5      R                  U5      R                  S[        5         [        U5      I Sh  vN n[        U R                  XS9$  N! [         a    [        S	X!4-  5      Sef = f7f)
a)  Get 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.
Nfilenamer3   r      
uploadDatefile_documentr4   no version %d for filename %r)r6   rD   findabslimitskipsortr   r   r&   rZ   rB   StopAsyncIterationr   )	rG   rc   versionr4   rN   querycursorrm   docs	            r5   get_versionAsyncGridFS.get_version   s     P  (*w'!!%!9?GQ;w<!#DLL!!$',,\:FLL!!'*//iH	Zf%C 0 0UU &! 	Z8G;NNOUYY	Zs0   B0C:3C CC C:C C77C:c                F   #    U R                   " SXS.UD6I Sh  vN $  N7f)a  Get the most recent version of a file in GridFS by ``"filename"``
or metadata fields.

Equivalent to calling :meth:`get_version` with the default
`version` (``-1``).

:param filename: ``"filename"`` of the file to get, or `None`
:param session: a
    :class:`~pymongo.client_session.AsyncClientSession`
:param kwargs: find files by custom metadata.

.. versionchanged:: 3.6
   Added ``session`` parameter.
)rc   r4   N )rt   )rG   rc   r4   rN   s       r5   get_last_versionAsyncGridFS.get_last_version   s&     ( %%SxSFSSSSs   !!c                   #    [        U5        U R                  R                  SU0US9I Sh  vN   U R                  R	                  SU0US9I Sh  vN   g N) N7f)a  Delete a file from GridFS by ``"_id"``.

Deletes all data belonging to the file with ``"_id"``:
`file_id`.

.. warning:: Any processes/threads reading from the file while
   this method is executing will likely see an invalid/corrupt
   file. Care should be taken to avoid concurrent reads to a file
   while it is being deleted.

.. note:: Deletes of non-existent files are considered successful
   since the end result is the same: no file with that _id remains.

:param file_id: ``"_id"`` of the file to delete
:param session: a
    :class:`~pymongo.client_session.AsyncClientSession`

.. versionchanged:: 3.6
   Added ``session`` parameter.

.. versionchanged:: 3.1
   ``delete`` no longer ensures indexes.
rS   r3   Nfiles_id)r6   rD   
delete_onerF   delete_many)rG   r]   r4   s      r5   deleteAsyncGridFS.delete  s\     0 	w'kk$$eW%5w$GGGll&&
G'<g&NNN 	HNs!   +AA#AAAAc                   #    [        U5        U R                  R                  SUS9I Sh  vN  Vs/ s H
  nUc  M  UPM     sn$  Ns  snf 7f)a  List the names of all files stored in this instance of
:class:`GridFS`.

:param session: a
    :class:`~pymongo.client_session.AsyncClientSession`

.. versionchanged:: 3.6
   Added ``session`` parameter.

.. versionchanged:: 3.1
   ``list`` no longer ensures indexes.
rc   r3   N)r6   rD   distinct)rG   r4   names      r5   listAsyncGridFS.list   sV      	w'
 #kk22:w2OOO
O O
 	
O
s%   )AAAAAAAc                   #    Ub#  [        U[        R                  5      (       d  SU0n[        U5        U R                  " U/UQ7SU0UD6  Sh  vN nUs  $  N
 g7f)aB  Get a single file from gridfs.

All arguments to :meth:`find` are also valid arguments for
:meth:`find_one`, although any `limit` argument will be
ignored. Returns a single :class:`~gridfs.grid_file.GridOut`,
or ``None`` if no matching file is found. For example:

.. code-block: python

    file = fs.find_one({"filename": "lisa.txt"})

:param filter: a dictionary specifying
    the query to be performing OR any other type to be used as
    the value for a query for ``"_id"`` in the file collection.
:param args: any additional positional arguments are
    the same as the arguments to :meth:`find`.
:param session: a
    :class:`~pymongo.client_session.AsyncClientSession`
:param kwargs: any additional keyword arguments
    are the same as the arguments to :meth:`find`.

.. versionchanged:: 3.6
   Added ``session`` parameter.
NrS   r4   )r=   r   r   r6   rj   )rG   filterr4   argsrN   fs         r5   find_oneAsyncGridFS.find_one6  sb     > j&E&EV_Fw'yyJ$JJ6J 	!H	J s*   A
AAAAAAAc                4    [        U R                  /UQ70 UD6$ )aw  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 <https://dochub.mongodb.org/core/find>`_.
AsyncGridOutCursorrB   rG   r   rN   s      r5   rj   AsyncGridFS.find^  s     t "$"2"2DTDVDDr7   c                   #    [        U5        U(       a(  U R                  R                  US/US9I Sh  vN nUSL$ U R                  R                  US/US9I Sh  vN nUSL$  N0 N
7f)aQ  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.
rS   r3   N)r6   rD   r   )rG   document_or_idr4   rN   r   s        r5   existsAsyncGridFS.exists  st     T 	w'kk**6E7G*LLA } kk**>E7G*TTA}	 MTs!   2A)A%'A)A'	A)'A))rF   rB   rD   )fs)rH   r%   rI   str)rN   r   returnrM   )rT   r   rN   r   r   r   Nr]   r   r4   Optional[AsyncClientSession]r   rZ   )Nrd   N)
rc   Optional[str]rp   Optional[int]r4   r   rN   r   r   rZ   )NN)rc   r   r4   r   rN   r   r   rZ   r]   r   r4   r   r   None)r4   r   r   z	list[str])
r   Optional[Any]r4   r   r   r   rN   r   r   zOptional[AsyncGridOut]r   r   rN   r   r   r   )r   r   r4   r   rN   r   r   bool)__name__
__module____qualname____firstlineno____doc__rJ   rO   rV   r_   rt   rx   r~   r   r   rj   r   __static_attributes__rw   r7   r5   r9   r9   F   s!   <'/R7!<* #'!#04	9Z9Z 9Z .	9Z
 9Z 
9Zz #'04TT .T 	T
 
T.O8
0 !%04&& .& 	&
 & 
 &P:E| )-040%0 .0 	0
 
0 0r7   r9   c                     \ rS rSrSrS\SS4           SS jjr   S         SS jjr   S           SS jjr\	R                     S           SS jj5       r\	R                     S             SS	 jj5       r S     SS
 jjr\	R                   S       SS jj5       r\	R                  SSS jj5       r\	R                   S     SS jj5       rSS jr S        S!S jjr\	R                    S          S"S jj5       r S       S#S jjr S       S$S jjrSrg)%AsyncGridFSBucketi  r;   r   Nc                   [        U[        5      (       d  [        S[        U5       35      e[	        U5      nUb  UOUR
                  nUR                  (       d  [        S5      eX l        X   U l	        U R                  R                  R                  XES9U l        U R                  R                  R                  XES9U l        X0l        UR                   R"                  R$                  U l        g)aa  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 <https://dochub.mongodb.org/core/gridfs>`_.
z3database must be an instance of AsyncDatabase, not Nz"write concern must be acknowledged)r@   read_preference)r=   r%   r>   r?   r   r@   rA   r)   _bucket_namerB   rE   with_optionsrF   rC   rD   _chunk_size_bytesclientoptionstimeout_timeout)rG   dbbucket_namechunk_size_bytesr@   r   wtcs          r5   rJ   AsyncGridFSBucket.__init__  s    R "m,,QRVWYRZQ[\]](,,8mb>N>N$%IJJ'?(,(8(8(?(?(L(L' )M )
 (,'7'7'='='J'J' (K (
 "2		))11r7   c                    [        SU5        UUb  UOU R                  S.nUb  X5S'   [        U R                  4SU0UD6$ )a  Opens 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.
rc   )rc   
chunk_sizemetadatar4   r'   r   rM   rB   )rG   rc   r   r   r4   optss         r5   open_upload_stream$AsyncGridFSBucket.open_upload_stream  sW    R 	
H- !$4$@ dF\F\
 '4++EWEEEr7   c                    [        SU5        UUUb  UOU R                  S.nUb  XFS'   [        U R                  4SU0UD6$ )aG  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.
rc   )rS   rc   r   r   r4   r   )rG   r]   rc   r   r   r4   r   s          r5   open_upload_stream_with_id,AsyncGridFSBucket.open_upload_stream_with_idE  sZ    \ 	
H-  $4$@ dF\F\	
 '4++EWEEEr7   c                  #    U R                  XXES9 ISh  vN nUR                  U5      I Sh  vN   SSS5      ISh  vN   [        [        WR                  5      $  NG N0 N"! , ISh  vN  (       d  f       N7= f7f)a  Uploads 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.
r3   N)r   rR   r
   r   rS   )rG   rc   sourcer   r   r4   gins          r5   upload_from_stream$AsyncGridFSBucket.upload_from_stream  su     V ** + 
 
))F###
 

 Hcgg&&
 $
 
 
 
sS   A?AA?A%A!A%A? A#A?!A%#A?%A<+A.,A<8A?c                   #    U R                  XXEUS9 ISh  vN nUR                  U5      I Sh  vN   SSS5      ISh  vN   g N. N N	! , ISh  vN  (       d  f       g= f7f)a,  Uploads 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.
r3   N)r   rR   )rG   r]   rc   r   r   r   r4   r   s           r5   upload_from_stream_with_id,AsyncGridFSBucket.upload_from_stream_with_id  se     Z 22/7 3 
 
))F###
 
 
 $
 
 
 
sS   A'AA'AA	AA'AA'	AA'A$AA$ A'c                j   #    [        U R                  XS9nUR                  5       I Sh  vN   U$  N7f)a  Opens 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.
r3   NrY   r\   s       r5   open_download_stream&AsyncGridFSBucket.open_download_stream  s4     4 D,,gG iik 	ra   c                *  #    U R                  XS9I Sh  vN  ISh  vN n UR                  5       I Sh  vN n[        U5      (       d  OUR                  U5        M<  SSS5      ISh  vN   g N[ NT N= N! , ISh  vN  (       d  f       g= f7f)a  Downloads 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.
r3   N)r   	readchunklenrR   )rG   r]   destinationr4   r^   chunks         r5   download_to_stream$AsyncGridFSBucket.download_to_stream  ss     : 2272LLLLPT"nn..5zz!!%(	  MLL. MLLLsd   BA1BA3BA9A5(A9 B+A7,B3B5A97B9B?B BBc                   #    [        U5        U R                  R                  SU0US9I Sh  vN nU R                  R	                  SU0US9I Sh  vN   UR
                  (       d  [        SU-  5      eg NH N&7f)a1  Given 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.
rS   r3   Nr{   z0no file could be deleted because none matched %s)r6   rD   r|   rF   r}   deleted_countr   )rG   r]   r4   ress       r5   r~   AsyncGridFSBucket.delete)  sz     , 	w'KK**E7+;W*MMll&&
G'<g&NNN  KgUVV ! NNs!   +A:A6#A:A8%A:8A:c                |  #    [        U5        U R                  R                  SU0SS0US9nU Vs/ s Sh  vN oDS   PM   N

 Os  snf nnU R                  R                  SSU00US9I Sh  vN  nU R                  R                  SSU00US9I Sh  vN    UR
                  (       d  [        SU< 35      eg7f)	a  Given a filename, delete this stored file's files collection document(s)
and associated chunks from a GridFS bucket.

For example::

  my_db = AsyncMongoClient().test
  fs = AsyncGridFSBucket(my_db)
  await fs.upload_from_stream("test_file", "data I want to store!")
  await fs.delete_by_name("test_file")

Raises :exc:`~gridfs.errors.NoFile` if no file with the given filename exists.

:param filename: The name of the file to be deleted.
:param session: a :class:`~pymongo.client_session.AsyncClientSession`

.. versionadded:: 4.12
rc   rS   re   r3   Nz$inr{   z7no file could be deleted because none matched filename )r6   rD   rj   r}   rF   r   r   )rG   rc   r4   rC   filefile_idsr   s          r5   delete_by_name AsyncGridFSBucket.delete_by_nameE  s     * 	w'  *h!7%W U2788$K888KK++UUH4E,FPW+XXXll&&
UH4E'FPW&XXX  RS[R^_`` !sH   /B<AAA
AAAA)B<.A1/&B<B&B<c                4    [        U R                  /UQ70 UD6$ )a  Find and return the files collection documents that match ``filter``

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_data in fs.find({"filename": "lisa.txt"},
                          no_cursor_timeout=True):
      data = grid_data.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: Search query.
:param batch_size: The number of documents to return per
    batch.
:param limit: The maximum number of documents to return.
:param no_cursor_timeout: The server normally times out idle
    cursors after an inactivity period (10 minutes) to prevent excess
    memory use. Set this option to True prevent that.
:param skip: The number of documents to skip before
    returning.
:param sort: The order by which to sort results. Defaults to
    None.
r   r   s      r5   rj   AsyncGridFSBucket.findb  s     Z "$"2"2DTDVDDr7   c                  #    [        SU5        SU0n[        U5        U R                  R                  XCS9nUS:  aC  [	        U5      S-
  nUR                  S5      R                  U5      R                  S[        5        O4UR                  S5      R                  U5      R                  S[        5         [        U5      I Sh  vN n[        U R                  XsS9$  N! [         a    [        S	X!4-  5      Sef = f7f)
a  Opens a Stream from which the application can read the contents of
`filename` and optional `revision`.

For example::

  my_db = MongoClient().test
  fs = GridFSBucket(my_db)
  grid_out = fs.open_download_stream_by_name("test_file")
  contents = grid_out.read()

Returns an instance of :class:`~gridfs.grid_file.GridOut`.

Raises :exc:`~gridfs.errors.NoFile` if no such version of
that file exists.

Raises :exc:`~ValueError` filename is not a string.

:param filename: The name of the file to read from.
:param revision: Which revision (documents with the same
    filename and different uploadDate) of the file to retrieve.
    Defaults to -1 (the most recent revision).
:param session: a
    :class:`~pymongo.client_session.AsyncClientSession`

:Note: Revision numbers are defined as follows:

  - 0 = the original stored file
  - 1 = the first revision
  - 2 = the second revision
  - etc...
  - -2 = the second most recent revision
  - -1 = the most recent revision

.. versionchanged:: 3.6
   Added ``session`` parameter.
rc   r3   r   re   rd   rf   Nrg   ri   )r'   r6   rD   rj   rk   rl   rm   rn   r   r   r&   rZ   rB   ro   r   )rG   rc   revisionr4   rq   rr   rm   rU   s           r5   open_download_stream_by_name.AsyncGridFSBucket.open_download_stream_by_name  s     N 	
H-X&w'!!%!9a<x=1$DLL!!$',,\:FLL!!(+00yI	[#Fm+I 0 0	[[ ,! 	[8H;OOPVZZ	[s0   B2C<5C CC C<C C99C<c                ,  #    U R                  XUS9I Sh  vN  ISh  vN n UR                  5       I Sh  vN n[        U5      (       d  OUR                  U5        M<  SSS5      ISh  vN   g N[ NT N= N! , ISh  vN  (       d  f       g= f7f)a  Write the contents of `filename` (with optional `revision`) to
`destination`.

For example::

  my_db = MongoClient().test
  fs = GridFSBucket(my_db)
  # Get file to write to
  file = open('myfile','wb')
  fs.download_to_stream_by_name("test_file", 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 read from.
:param destination: A file-like object that implements :meth:`write`.
:param revision: Which revision (documents with the same
    filename and different uploadDate) of the file to retrieve.
    Defaults to -1 (the most recent revision).
:param session: a
    :class:`~pymongo.client_session.AsyncClientSession`

:Note: Revision numbers are defined as follows:

  - 0 = the original stored file
  - 1 = the first revision
  - 2 = the second revision
  - etc...
  - -2 = the second most recent revision
  - -1 = the most recent revision

.. versionchanged:: 3.6
   Added ``session`` parameter.
r3   N)r   r   r   rR   )rG   rc   r   r   r4   r^   r   s          r5   download_to_stream_by_name,AsyncGridFSBucket.download_to_stream_by_name  s     X :: ; 
 
 
 
"nn..5zz!!%(	 
 
 
 /	
 
 
 
sd   BA2BA4BA:A6(A:!B,A8-B4B6A:8B:B BBBc                   #    [        U5        U R                  R                  SU0SSU00US9I Sh  vN nUR                  (       d  [	        SX!4-  5      eg N%7f)a3  Renames 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.
rS   $setrc   r3   Nz<no files could be renamed %r because none matched file_id %i)r6   rD   
update_onematched_countr   )rG   r]   new_filenamer4   results        r5   renameAsyncGridFSBucket.rename  su     . 	w'{{--Gv
L'ABG . 
 
 ##%(4'>?  $
s   0AA&Ac                   #    [        U5        U R                  R                  SU0SSU00US9I Sh  vN nUR                  (       d  [	        SU< SU< 35      eg N)7f)a  Renames 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
rc   r   r3   Nzno files could be renamed z because none matched filename )r6   rD   update_manyr   r   )rG   rc   r   r4   r   s        r5   rename_by_name AsyncGridFSBucket.rename_by_name  sz     ( 	w'{{.."Vj,-G$HRY / 
 
 ##,\,<<[\d[gh  $
s   0AA*A)r   r   rF   rB   rD   r   )r   r%   r   r   r   intr@   zOptional[WriteConcern]r   zOptional[_ServerMode]r   r   NNN)
rc   r   r   r   r   Optional[Mapping[str, Any]]r4   r   r   rM   )r]   r   rc   r   r   r   r   r   r4   r   r   rM   )rc   r   r   r   r   r   r   r   r4   r   r   r   )r]   r   rc   r   r   r   r   r   r   r   r4   r   r   r   r   r   )r]   r   r   r   r4   r   r   r   r   )rc   r   r4   r   r   r   r   )rd   N)rc   r   r   r   r4   r   r   rZ   )
rc   r   r   r   r   r   r4   r   r   r   )r]   r   r   r   r4   r   r   r   )rc   r   r   r   r4   r   r   r   )r   r   r   r   r   r   rJ   r   r   r!   applyr   r   r   r   r~   r   rj   r   r   r   r   r   rw   r7   r5   r   r     sM   <
   20415=2=2 =2 	=2
 .=2 /=2 
=2D +/04044F4F (4F .	4F
 .4F 
4Ft +/0404:F:F :F (	:F
 .:F .:F 
:Fx [[
 +/0404/'/' /' (	/'
 ./' ./' 
/' /'b [[ +/0404/$/$ /$ 	/$
 (/$ ./$ ./$ 
/$ /$d EI%A	@ [[VZ!)!)),!)7S!)	!) !)F [[W W6 [[EIaa&Ba	a a8-E` Z^4[4['*4[:V4[	4[l [[
 042)2) 2) 	2)
 .2) 
2) 2)j X\*-8T	D Y]+.9U	 r7   r   c                  .   \ rS rSr% Sr S<       S=S jjr        S>S jrS?S jrS?S	 jr\	S@S
 j5       r
\" SSSS9rS\S'   \" SS5      rS\S'   \" SS5      rS\S'   \" SS5      rS\S'   \" SSSS9rS\S'   \" SSSS9rS\S'   \" SSSS9rS \S!'   \" S"S#SS9rS\S"'   S$\S%'   S\S&'   S'\S('   S\S)'   SAS* jrSBS+ jrSBS, jrSCSDS- jjrSCSES. jjrSFS/ jrSGS0 jrS?S1 jrSHSIS2 jjrS@S3 jrS@S4 jrSJS5 jr SKS6 jr!SLS7 jr"S@S8 jr#SMS9 jr$SNS: jr%S;r&g)OrM   i;  zClass to write data to GridFS.Nr   c                   [        U[        5      (       d  [        S[        U5       35      eUR                  R
                  (       d  [        S5      e[        U5        SU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   [        U[        R                  S9nUR                  S[        5       5      US'   UR                  S[        5      US'   [        R!                  U S	U5        [        R!                  U S
U5        [        R!                  U SUR"                  5        [        R!                  U SU5        [        R!                  U S[$        R&                  " 5       5        [        R!                  U SS5        [        R!                  U SS5        [        R!                  U SS5        [        R!                  U SS5        [        R!                  U S/ 5        [        R!                  U SS5        g)al  Write 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
<http://dochub.mongodb.org/core/gridfsspec>`_ 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`
<root_collection must be an instance of AsyncCollection, not z3root_collection must use acknowledged write_concerncontent_typecontentTyper   	chunkSize)r   rS   _session_collrF   _file_buffer	_positionr   _chunk_number_closedF_ensured_index_buffered_docs_buffered_docs_sizeN)r=   r#   r>   r?   r@   rA   r)   r6   popr   r/   PRIMARYr_   r   r   object__setattr__rE   ioBytesIO)rG   root_collectionr4   rN   colls        r5   rJ   AsyncGridIn.__init__>  s   p /?;;NtTcOdNef  ,,99$%Z[[w' V#$*JJ~$>F=!6!"(**\":F;*?NLbLbc 

5(*5u$jj6HI{4W54$/4DKK84&14BJJL94a04!44E24!1594!1264!6:r7   r   c                z  #    UR                  SS0U R                  S9I S h  vN nUc6   UR                  U R                  S9I S h  vN  Vs/ s S h  vN nUS   PM  g  N> N N
 Os  snf nnO! [         a    / n Of = fX&;  a2  UR	                  UR                  5       X0R                  S9I S h  vN    g g 7f)NrS   re   )
projectionr4   r3   key)uniquer4   )r   r   list_indexesr-   create_indexitems)rG   rI   	index_keyr  rs   
index_spec
index_keyss          r5   _create_indexAsyncGridIn._create_index  s      ''E1:t}}'UU;  3=2I2IRVR_R_2I2`,`,` ( u%  V
 -a 
 
 $  
 * --OO%fmm .    +s    B;A!B;A1 A#A1 A)A'A%
A'A) B;#A1 %A''A)(A1 0B;1B =B;?B  3B;3B64B;c                p  #    [         R                  U S5      (       d  [        U R                  5        U R	                  U R
                  R                  [        S5      I S h  vN   U R	                  U R
                  R                  [        S5      I S h  vN   [         R                  U SS5        g g  NP N7f)Nr  FT)r  __getattribute__r6   r   r  r   rC   r   rE   r   r  rG   s    r5   _ensure_indexesAsyncGridIn._ensure_indexes  s     &&t-=>>"4==1$$TZZ%5%5xGGG$$TZZ%6%6$GGGt%5t<	 ?GGs$   AB6!B2"2B6B4B64B6c                V  #    U R                   R                  R                  SU R                  S   0U R                  S9I Sh  vN   U R                   R
                  R                  SU R                  S   0U R                  S9I Sh  vN   [        R                  U SS5        g Na N7f)z>Remove all chunks/files that may have been uploaded and close.r{   rS   r3   Nr  T)	r   rE   r}   r   r   rC   r|   r  r  r  s    r5   abortAsyncGridIn.abort  s     jj++ZE9J,KUYUbUb+cccjj))5$**U2C*Ddmm)\\\4D1 	d\s%   AB)B%AB)B'	B)'B)c                    U R                   $ )zIs this file closed?)r  r  s    r5   closedAsyncGridIn.closed  s     ||r7   rS   "The ``'_id'`` value for this file.T)	read_onlyrc   Name of this file.r   Alias for `filename`.r   r   DDEPRECATED, will be removed in PyMongo 5.0. Mime-type for this file.r   lengthLength (in bytes) of this file.)closed_onlyr   r   Chunk size for this file.r   rf   z!Date that this file was uploaded.datetime.datetimeupload_datemd5gDEPRECATED, will be removed in PyMongo 5.0. MD5 of the contents of this file if an md5 sum was created.z
io.BytesIOr   r  zlist[dict[str, Any]]r  r  c                    US:X  a  [         R                  X5      $ XR                  ;   a  U R                  U   $ [        SU-  5      e)Nr   z#GridIn object has no attribute '%s')r  r  r   AttributeErrorrG   r   s     r5   __getattr__AsyncGridIn.__getattr__  sD    7?**466ZZ::d##BTIJJr7   c                ^   XR                   ;   d  XR                  R                   ;   a  [        R                  XU5        g X R                  U'   U R
                  (       aO  [        (       a9  U R                  R                  R                  SU R                  S   0SX005        g [        S5      eg )NrS   r   zAsyncGridIn does not support __setattr__ after being closed(). Set the attribute before closing the file or use AsyncGridIn.set() instead)__dict__	__class__r  r  r   r  _IS_SYNCr   rC   r   r3  rG   r   values      r5   r  AsyncGridIn.__setattr__  s     == DNN,C,C$Ct51
  %JJt||8JJ$$//

58I0JVVZUbLcd( d 	 r7   c                   #    X R                   U'   U R                  (       aA  U R                  R                  R	                  SU R                   S   0SX005      I S h  vN   g g  N7f)NrS   r   )r   r  r   rC   r   r;  s      r5   setAsyncGridIn.set  sW      

4<<**""--udjj6G.H6TXS`Jabbb bs   AA&A$A&c                  #    U R                  5       I Sh  vN   [        U5      U R                  ::  d   eU(       a[  U R                  R	                  U R
                  S   U R                  US.5        U =R                  [        U5      [        -   -  sl        U R                  (       d  gU(       d1  U R                  [        :  d  [        U R                  5      [        :  aE   U R                  R                  U R                  U R                  S9I Sh  vN   / U l        SU l        U =R                  S-  sl        U =R&                  [        U5      -  sl        g GNE NI! [         a  nUR                  S   nU H8  nUR!                  S5      S;   d  M  U R#                  U R
                  S   5        M:     SU0nUR                  S   nU(       a  US	   US
'   [%        U5        e SnAff = f7f)zFlush `data` to a chunk.NrS   )r{   nrT   r3   writeErrorscode)i*  i*  i&1  writeConcernErrorsrd   writeConcernErrorr   re   )r  r   r   r  appendr   r   r  r   r   r   rF   insert_manyr   r(   detailsr_   _raise_file_existsr.   r   )rG   rT   forceexcwrite_errorserrr   wcess           r5   _flush_dataAsyncGridIn._flush_data  s    ""$$$4yDOO+++&&!ZZ.T5G5GQUV $$D	O(CC$"" ''+>>4&&'+@@ll..t/B/BDMM.ZZZ #%D'(D$a#d)#A 	%  [! "{{=9'Cwwv*??//

50AB ( (6{{#7826r(F./-f5sN   G-ECG-#1E  EE  AG-E   
G**'G%AG%%G**G-c                   #    U R                  U R                  R                  5       US9I Sh  vN   U R                  R                  5         [        R
                  " 5       U l        g N97f)z)Flush the buffer contents out to a chunk.rK  N)rP  r   getvaluecloser	  r
  )rG   rK  s     r5   _flush_bufferAsyncGridIn._flush_buffer  sN     t||446eDDDzz| 	Es   ,A*A(:A*c                  #     U R                  SS9I Sh  vN   [        U R                  5      U R                  S'   [        R                  R                  [        R                  R                  S9U R                  S'   U R                  R                  R                  U R                  U R                  S9I Sh  vN $  N N! [         a    U R                  U R                  5         gf = f7f)zFlush the file to the database.TrS  Nr*  )tzrf   r3   )rV  r   r   r   datetimenowtimezoneutcr   rC   
insert_oner   r+   rJ  rS   r  s    r5   _flushAsyncGridIn._flush  s     	.$$4$000#(#8DJJx '/'8'8'<'<@Q@Q@U@U'<'VDJJ|$))44TZZ4WWW 1
 X  	.##DHH-	.sK   C.C B?B#C :C;C >C.?C C %C+(C.*C++C.c                    [        SU-  5      e)z3Raise a FileExists exception for the given file_id.zfile with _id %r already exists)r   )rG   r]   s     r5   rJ  AsyncGridIn._raise_file_exists#  s    :WDEEr7   c                   #    U R                   (       d0  U R                  5       I Sh  vN   [        R                  U SS5        gg N7f)zyFlush the file and close it.

A closed file cannot be written any more. Calling
:meth:`close` more than once is allowed.
Nr  T)r  r_  r  r  r  s    r5   rU  AsyncGridIn.close'  s7      ||++-tY5 s   %AAAc                .    [         R                  " S5      e)Nreadr	  UnsupportedOperationrG   sizes     r5   rf  AsyncGridIn.read1  s    %%f--r7   c                    gNFrw   r  s    r5   readableAsyncGridIn.readable4      r7   c                    grm  rw   r  s    r5   seekableAsyncGridIn.seekable7  rp  r7   c                  #    U R                   (       a  [        S5      e UR                  n[        R                  " U5      (       a  U R                  U5      I Sh  vN   gU R                  R!                  5       S:  az  U R"                  U R                  R!                  5       -
  nU(       a4   U" U5      nU R                  R)                  U5        [+        U5      U:  a  gU R-                  5       I Sh  vN   U" U R"                  5      nU(       af  [+        U5      U R"                  :X  aM  U R/                  U5      I Sh  vN   U" U R"                  5      nU(       a  [+        U5      U R"                  :X  a  MM  U R                  R)                  U5        g! [         a    [	        U[
        [        45      (       d  [        S5      Se[	        U[
        5      (       a7   UR                  U R                  5      nO! [         a    [        S5      Sef = f[        R                  " U5      R                  n GNf = f GN! [$         a    U R'                  5       I Sh  vN    e f = f GNo GN'7f)a  Write 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
zcannot write to a closed filez+can only write strings or file-like objectsNz7must specify an encoding for file in order to write strr   )r  
ValueErrorrf  r3  r=   r   bytesr>   encodeencodingr	  r
  inspectiscoroutinefunction_write_asyncr   tellr   BaseExceptionr   rR   r   rV  rP  )rG   rT   rf  spaceto_writes        r5   rR   AsyncGridIn.write:  s    ( <<<==	)99D &&t,,##D)))||  "Q&$,,*;*;*==#'; LL&&x08}u,((***DOO,Hs8}?&&x0000 s8}? LLx(C  	)dS%L11 MNTXX$$$ ;;t}}5D%  #Q   ::d#((D	) * ) "jjl** + 1s   I)F /I)H8AI).H; 6>I)4I#5A
I)?I& 6I)8I)AH5G76H57H#H51I)4H55I);I II  I)&I)c                  #    U R                   R                  5       S:  a  U R                  U R                   R                  5       -
  nU(       a<   U" U5      I S h  vN nU R                   R                  U5        [        U5      U:  a  g U R                  5       I S h  vN   U" U R                  5      I S h  vN nU(       an  [        U5      U R                  :X  aU  U R                  U5      I S h  vN   U" U R                  5      I S h  vN nU(       a  [        U5      U R                  :X  a  MU  U R                   R                  U5        g  N! [         a    U R	                  5       I S h  vN    e f = f N N N Nr7fNr   )	r   r|  r   r}  r   rR   r   rV  rP  )rG   rf  r~  r  s       r5   r{  AsyncGridIn._write_asyncw  s"    <<"OOdll&7&7&99E%)%[0H ""8,x=5($$&&&doo..3x=DOO;""8,,,!$//22H 3x=DOO; 	8$  1$ **,&& '.,2s   AF E EE  >F E8F 8E:98F 1E<2F E>$F 2F E E5-E0.E55F :F <F >F c                T   #    U H  nU R                  U5      I Sh  vN   M     g N	7f)zCWrite a sequence of strings to the file.

Does not add separators.
N)rR   )rG   sequencelines      r5   
writelinesAsyncGridIn.writelines  s&     
 D**T""" "s   (&
(c                    gNTrw   r  s    r5   	writeableAsyncGridIn.writeable      r7   c                   #    U $ 7f)z)Support for the context manager protocol.rw   r  s    r5   
__aenter__AsyncGridIn.__aenter__  s
        c                v   #    Uc  U R                  5       I Sh  vN   g[        R                  U SS5        g N7f)ztSupport for the context manager protocol.

Close the file if no exceptions occur and allow exceptions to propagate.
Nr  TF)rU  r  r  rG   exc_typeexc_valexc_tbs       r5   	__aexit__AsyncGridIn.__aexit__  s?     
 **,  tY5  s   979)r   r  r  r   )r  r#   r4   r   rN   r   r   r   )rI   r#   r  r   r  r   r   r   r   r   r   r   r   r   r   r   )r   r   r<  r   r   r   )F)rT   r   rK  r   r   r   )rK  r   r   r   )r   r   )r]   r   r   r   rd   )rj  r   r   r   )rT   r   r   r   )rf  r   r   r   )r  zIterable[Any]r   r   )r   rM   r  r   r  r   r  r   r   r   )'r   r   r   r   r   rJ   r  r  r   propertyr#  r   rS   __annotations__rc   r   r   r*  r   r/  r0  r5  r  r?  rP  rV  r_  rJ  rU  rf  rn  rr  rR   r{  r  r  r  r  r   rw   r7   r5   rM   rM   ;  s   (
 15V;(V; .V; 	V;
 
V;p)69CG	"=2   #5*NZ^_C_1*>RSHmS-j:QRD-R"5]#L-  &h0Q_cdFCd)+7R^bcJc%89t&K"  -qC  M((K$c
"$H$
.F6.;)z%(#r7   rM   c                    ^  \ rS rSr% Sr   S@         SAU 4S jjjr\" SS5      rS\S'   \" SS5      r	S	\S'   \" SS
5      r
S	\S'   \" SS5      rS\S'   \" SS5      rS\S'   \" SS5      rS\S'   \" SS5      rS\S'   \" SS5      rS\S'   \" SS5      rS\S'   \" S S!5      rS\S '   S\S"'   S\S#'   \(       d  S$\S%'   SBS& jrSCS' jrSDSES( jjrSDSFS) jjrSGS* jrSHS+ jrSIS, jrSBS- jrSJSKS. jjrSDSES/ jjrSLS0 jr\4SMS1 jjrSIS2 jr SNS3 jr!SGU 4S4 jjr"SOS5 jr#SPS6 jr$SIS7 jr%SNS8 jr&SQS9 jr'SRS: jr(SGS; jr)SIS< jr*SSSTS= jjr+SGS> jr,S?r-U =r.$ )UrZ   i  z!Class to read data out of GridFS.c                t  > [        U[        5      (       d  [        S[        U5       35      e[	        U5        [        U5      n[        TU ]  5         UR                  U l	        UR                  U l        X l        [        U l        SU l        SU l        SU l        X0l        X@l        [(        (       d  SU l        gg)a#  Read 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.
r   r   NF)r=   r#   r>   r?   r6   r   superrJ   rE   rF   rC   rD   _file_idr   r   _buffer_pos_chunk_iterr   r   r   r:  r#  )rG   r  r]   rh   r4   r9  s        r5   rJ   AsyncGridOut.__init__  s    L /?;;NtTcOdNef  	w'5oF&--%++"
xDK r7   rS   r%  r   rc   r'  r   r(  r   r   r)  r   r   r*  r+  r   r   r-  r   rf   z'Date that this file was first uploaded.r.  r/  aliaseszJDEPRECATED, will be removed in PyMongo 5.0. List of aliases for this file.zOptional[list[str]]r   zMetadata attached to this file.r   r0  r1  r   r  r   r#  c                d   #    U R                  5       I S h  vN nU(       a  U$ [        5       e N7fr   )readlinero   )rG   r  s     r5   	__anext__AsyncGridOut.__anext__  s)     (D$&& )s   0.0c                D   #    U  Vs/ s S h  vN oPM   N
 sn$ s  snf 7fr   rw   )rG   xs     r5   to_listAsyncGridOut.to_list  s     %)**A***s$    
 c                >   #    U R                  USS9I Sh  vN $  N7f)eRead one line or up to `size` bytes from the file.

:param size: the maximum number of bytes to read
T)rj  r  N_read_size_or_lineri  s     r5   r  AsyncGridOut.readline  s#     
 00d0FFFFs   c                  #    U R                  5       I Sh  vN   / n[        U R                  5      U R                  -
  nSnUS:  ar  U R	                  SS9I Sh  vN nU[        U5      -  nUR                  U5        [        U R                  5      U R                  -
  nSUs=:  a	  U:  a    U$   US:  a  Mr  U$  N Nc7f)r  Nr   T)r  )r[   r   r*  r   r  r   rG  )rG   rj  lines	remainder
bytes_readr  s         r5   	readlinesAsyncGridOut.readlines  s     
 ))+EDKK(4>>9IJa-!44$4??c$i'
T",t~~=	t(j(L ) a- L 
 @s)   B?B;AB?B=AB?9B?=B?c                H  #    U R                   (       d  [        U R                  5        U R                  R	                  SU R
                  0U R                  S9I S h  vN U l         U R                   (       d'  [        SU R                  < SU R
                  < 35      eg g  NC7f)NrS   r3   zno file in gridfs collection z
 with _id )r   r6   r   rD   r   r  r   r  s    r5   r[   AsyncGridOut.open.  s     zz"4==1#{{33UDMM4JTXTaTa3bbDJ::3DKK?*T]]L]^   bs   AB"B AB"c                    [         (       a  U R                  5         OU R                  (       d  [        SU-  5      eXR                  ;   a  U R                  U   $ [	        SU-  5      e)NzBYou must call AsyncGridOut.open() before accessing the %s propertyz$GridOut object has no attribute '%s')r:  r[   r   r,   r3  r4  s     r5   r5  AsyncGridOut.__getattr__7  sY    8IIK"TW[[  ::::d##CdJKKr7   c                    gr  rw   r  s    r5   rn  AsyncGridOut.readableB  r  r7   c                  #    U R                  5       I Sh  vN   [        U R                  5      U R                  -
  n[        n[        U R                  5      nUS:  a  U R                  U R                  S nOU R                  [        U R                  5      :  a  [        XR                  -   U-  5      nU R                  c&  [        X R                  U R                  U5      U l	        U R                  R                  5       I Sh  vN nUS   U R                  U-  S nU(       d  [        S5      eU =R                  [        U5      -  sl        [        U l        SU l        U$  GNM N`7f)zkReads a chunk at a time. If the current position is within a
chunk the remainder of the chunk is returned.
Nr   rT   ztruncated chunk)r[   r   r   r  r   r   r   r   r*  r  _AsyncGridOutChunkIteratorrF   r   nextr   )rG   received
chunk_datar   chunk_numberr   s         r5   r   AsyncGridOut.readchunkE  s&     iikt||$t'7'77
)
a<d&6&6&89J^^c$++..>> 9ZGHL'#=,,|$  **//11Evt~~
'B'DEJ%&788#j/)/ 	 2s#   E(E#C.E(E&AE(&E(c                F  #    U R                  5       I Sh  vN   [        U R                  5      U R                  -
  nUS:  d  X:  a  UnUS:X  a  [        $ Sn/ nXA:  Ga_  X-
  nU R
                  (       aa  U R
                  nU R                  n[        U5      U R                  S n	[        U l        SU l        U =R                  [        U	5      -  sl        O%U R                  5       I Sh  vN nSn[        U5      n	U(       a.  UR                  [        XU-   5      U-
  n
U
S:  a  XJ-   S-   nU
S-   n[        U	5      U:  aY  UR                  U	SU 5        Xpl        X-   U l        U =R                  [        U R
                  5      U R                  -
  -  sl        OUR                  U	5        U[        U	5      -  nXA:  a  GM_  X:X  a4  U R                  (       a#   U R                  R                  5       I Sh  vN   SR!                  U5      $  GN GN# N! [         a     N%f = f7f)z&Internal read() and readline() helper.Nr   re   r7   )r[   r   r*  r   r   r   r  
memoryviewr   r   rj   r   rG  r  r  ro   join)rG   rj  r  r  r  rT   neededbufchunk_startr  poss              r5   r  AsyncGridOut._read_size_or_lineb  s    iik$t~~5	!8t'D19Lo_F||ll"..'_T-=-=-?@
$#$ #j/1 NN,,'_
hhuk3GH;V!8#>A-D 1WF:'Jw/0"#.#7 #dll"3d6F6F"FFJ'J'H9 o> !1!1&&++--- xx~_ 	* -, .% s_   H!H	CH!)H*CH!?H!H 3H4H 8H!H!H 
HH!HH!c                <   #    U R                  US9I Sh  vN $  N7f)a  Read 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.
)rj  Nr  ri  s     r5   rf  AsyncGridOut.read  s!      ,,$,7777s   c                    U R                   $ )z)Return the current position of this file.)r   r  s    r5   r|  AsyncGridOut.tell  s    ~~r7   c                  #    U[         :X  a  UnOIU[        :X  a  U R                  U-   nO/U[        :X  a  [	        U R
                  5      U-   nO[        SS5      eUS:  a  [        SS5      eX0R                  :X  a  U$ X0l        [        U l        SU l	        U R                  (       a)  U R                  R                  5       I Sh  vN   SU l
        U$  N7f)a  Set 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`.
   zInvalid value for `whence`r   z*Invalid value for `pos` - must be positiveN)r   r   r   r   r   r*  OSErrorr   r   r  r  rU  )rG   r  whencenew_poss       r5   seekAsyncGridOut.seek  s      YGy nns*Gy $++&,G":;;Q;"JKK nn$N ""((***#D +s   C CCCc                    gr  rw   r  s    r5   rr  AsyncGridOut.seekable  r  r7   c                    U $ )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.
rw   r  s    r5   	__aiter__AsyncGridOut.__aiter__  s	    & r7   c                   >#    U R                   (       a)  U R                   R                  5       I Sh  vN   SU l         [        (       a  [        TU ]  5         gSU l        g N-7f)z(Make GridOut more generically file-like.NT)r  rU  r:  r  r#  )rG   r9  s    r5   rU  AsyncGridOut.close  sI     ""((***#D8GMODK +s   /A"A .A"c                .    [         R                  " S5      e)NrR   rg  )rG   r<  s     r5   rR   AsyncGridOut.write  s    %%g..r7   c                .    [         R                  " S5      e)Nr  rg  )rG   r  s     r5   r  AsyncGridOut.writelines  s    %%l33r7   c                    grm  rw   r  s    r5   writableAsyncGridOut.writable  rp  r7   c                   #    U $ 7f)^Makes it possible to use :class:`AsyncGridOut` files
with the async context manager protocol.
rw   r  s    r5   r  AsyncGridOut.__aenter__  s      r  c                @   #    U R                  5       I Sh  vN   g N7f)r  NF)rU  r  s       r5   r  AsyncGridOut.__aexit__  s      jjl 	s   c                .    [         R                  " S5      e)Nfilenorg  r  s    r5   r  AsyncGridOut.fileno  s    %%h//r7   c                    g r   rw   r  s    r5   flushAsyncGridOut.flush  s    r7   c                    grm  rw   r  s    r5   isattyAsyncGridOut.isatty  rp  r7   c                .    [         R                  " S5      e)Ntruncaterg  ri  s     r5   r  AsyncGridOut.truncate  s     %%j11r7   c                    g r   rw   r  s    r5   __del__AsyncGridOut.__del__  s    r7   )
r   r  r  rF   r   r  rD   r   r   r#  r   )
r  r#   r]   r   rh   r   r4   r   r   r   r   rv  )r   list[bytes]r  )rj  r   r   rv  )rj  r   r   r  r  r  r  )rd   F)rj  r   r  r   r   rv  )r   r   )r  r   r  r   r   r   r   rZ   )r<  r   r   r   )r  r   r   r   r  )r   r   r   )rj  r   r   r   )/r   r   r   r   r   rJ   r   rS   r  rc   r   r   r*  r   r/  r  r   r0  r:  r  r  r  r  r[   r5  rn  r   r  rf  r|  r   r  rr  r  rU  rR   r  r  r  r  r  r  r  r  r  r   __classcell__r9  s   @r5   rZ   rZ     s   +
 "&'+04< (<  <  %	< 
 .<  
<  < | $E+OPCP(5IJHcJ$Z1HID#I"6]#L-  'x1RSFCS*;8STJT%9?&K"  $8_$G   -A5-H)  .qC 
 J	'	+	G	&	L:1f8  2; %N*/402 r7   rZ   c                      \ rS rSr% Sr          SS jrS\S'   SS jrSS jrSS jr	SS	 jr
SS
 jr\rSS jrSrg)r  i  zIterates over a file's chunks using a single cursor.

Raises CorruptGridFile when encountering any truncated, missing, or extra
chunk in a file.
c                6   UR                   U l         [        UR                  5      U l        [        UR                  5      U l        X l        X0l        X@l        [        R                  " [        U R
                  5      U R                  -  5      U l        S U l        g r   )rS   r   r   _chunk_sizer*  _lengthrF   r   _next_chunkmathceilfloat_num_chunks_cursor)rG   grid_outrE   r4   
next_chunks        r5   rJ   #_AsyncGridOutChunkIterator.__init__%  sn     <<x2238??+%99U4<<%84;K;K%KLr7   zOptional[AsyncCursor]r  c                    XR                   S-
  :  a  U R                  $ U R                  U R                  U R                   S-
  -  -
  $ )Nre   )r
  r  r  )rG   chunk_ns     r5   expected_chunk_length0_AsyncGridOutChunkIterator.expected_chunk_length7  sD    %%))###||t//43C3Ca3GHIIr7   c                    U $ r   rw   r  s    r5   r  $_AsyncGridOutChunkIterator.__aiter__<      r7   c                    SU R                   0nU R                  S:  a  SU R                  0US'   [        U R                  5        U R                  R                  US/U R                  S9U l        g )Nr{   r   z$gterB  )rB  re   )rn   r4   )rS   r  r6   r   rF   rj   r  )rG   r   s     r5   _create_cursor)_AsyncGridOutChunkIterator._create_cursor?  sa    dhh'a!4#3#34F3Kt}}-||((xj$--(Xr7   c                x  #    U R                   c  U R                  5         U R                   c   e U R                   R                  5       I Sh  vN $  N! [         aY    U R                   R	                  5       I Sh  vN    U R                  5         U R                   R                  5       I Sh  vN  s $ f = f7f)zReturn 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)r  r  r  r*   rU  r  s    r5   _next_with_retry+_AsyncGridOutChunkIterator._next_with_retryF  s      <<!<<+++	-**,,,, 	-,,$$&&&!**,,,,	-sR   -B:A AA B:A 'B7;A><2B7.B1/B74B:6B77B:c           	       #     U R                  5       I S h  vN nUS   U R                  :w  a5  U R                  5       I S h  vN   [	        SU R                  US   4-  5      eUS   U R                  :  aH  [        US   5      (       a5  U R                  5       I S h  vN   [	        SU R                  US   4-  5      eU R                  US   5      n[        US   5      U:w  a8  U R                  5       I S h  vN   [	        SUS   U[        US   5      4-  5      eU =R                  S-  sl        U$  GN! [         a5    U R                  U R                  :  a  e [	        SU R                  -  5      S ef = f GN7 N N7f)Nzno chunk #%drB  z;Missing chunk: expected chunk #%d but found chunk with n=%drT   z?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 %dre   )r  ro   r  r
  r   rU  r   r  )rG   r   expected_lengths      r5   r  _AsyncGridOutChunkIterator.nextW  s    	O//11E :)))**,!"%)%5%5uSz$BC 
 :)))5=!!jjl""%&)-)9)95:(FG 
 44U3Z@uV}0**,!-05c
OSQVW]Q^M_/`a 
 	A? 2! 	O4#3#33!.43C3C"CD$N	O  # s]   F D7 D4D7 &F E9AF E<AF 8E>9;F 4D7 7?E66F <F >F c                   #    U R                   (       a*  U R                   R                  5       I S h  vN   S U l         g g  N7fr   )r  rU  r  s    r5   rU   _AsyncGridOutChunkIterator.close|  s1     <<,,$$&&&DL &s   /A?A)r  rF   r  rS   r  r  r
  r   N)
r  rZ   rE   r#   r4   r   r  r   r   r   )r  r   r   r   )r   r  r  )r   zMapping[str, Any])r   r   r   r   r   rJ   r  r  r  r  r  r  r  rU  r   rw   r7   r5   r  r    sl       .	
  
  #"J
Y-"!F I r7   r  c                  B    \ rS rSr      SS jrSS jrS	S jr\rSrg)
AsyncGridOutIteratori  c                (    [        XUS5      U l        g r  )r  r  )rG   r  rE   r4   s       r5   rJ   AsyncGridOutIterator.__init__  s     6hQRSr7   c                    U $ r   rw   r  s    r5   r  AsyncGridOutIterator.__aiter__  r  r7   c                n   #    U R                   R                  5       I S h  vN n[        US   5      $  N7f)NrT   )r  r  rv  )rG   r   s     r5   r  AsyncGridOutIterator.next  s0     &&++--U6]## .s   535)r  N)r  rZ   rE   r#   r4   r"   )r   r"  r  )	r   r   r   r   rJ   r  r  r  r   rw   r7   r5   r"  r"    s4    T$T.=THZT
$ Ir7   r"  c                     ^  \ rS rSrSr       S
                 SU 4S jjjrSU 4S jjrSSS jjr\rSS jr	SS jr
SS jrS	rU =r$ )r   i  z{A cursor / iterator for returning GridOut objects as the result
of an arbitrary query against the GridFS files collection.
c	                z   > [        U5        [        U5      nXl        [        T	U ]  UR
                  UUUUUUUS9  g)aI  Create 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 <https://dochub.mongodb.org/core/cursors>`_.
)rm   rl   no_cursor_timeoutrn   
batch_sizer4   N)r6   r   _root_collectionr  rJ   rC   )
rG   rI   r   rm   rl   r+  rn   r,  r4   r9  s
            r5   rJ   AsyncGridOutCursor.__init__  sO    * 	w'0<
 !+/! 	 		
r7   c                   >#    [        U R                  5        [        TU ]  5       I Sh  vN n[	        U R
                  XR                  S9$  N"7f)z$Get next GridOut object from cursor.Nrg   )r6   r4   r  r  rZ   r-  )rG   	next_filer9  s     r5   r  AsyncGridOutCursor.next  s>     t||,',.(	D11T`T`aa )s   'AA#Ac                   #    Uc  U  Vs/ s Sh  vN o"PM  US:  a  [        S5      e/ n[        U5       H*  nUR                  U R                  5       I Sh  vN 5        M,     U$  NU
 sn$ s  snf  N7f)zConvert the cursor to a list.Nre   z'to_list() length must be greater than 0)ru  rangerG  r  )rG   r*  r  ret_s        r5   r  AsyncGridOutCursor.to_list  sh     >%)**AA:FGGvAJJTYY[() 
 +**
 )sA   A3A,A(A&
A(A,?A3A1
A3&A((A,)	A3c                    [        S5      eNz'Method does not exist for GridOutCursorNotImplementedErrorr   s      r5   
add_optionAsyncGridOutCursor.add_option      !"KLLr7   c                    [        S5      er8  r9  r   s      r5   remove_option AsyncGridOutCursor.remove_option  r=  r7   c                *    [        U R                  US9$ )zACreates an empty GridOutCursor for information to be copied into.r3   )r   r-  )rG   r4   s     r5   _clone_baseAsyncGridOutCursor._clone_base  s    !$"7"7IIr7   )r-  )Nr   r   FNr   N)rI   r#   r   r   rm   r   rl   r   r+  r   rn   r   r,  r   r4   r   r   r   r  r   )r*  r   r   zlist[AsyncGridOut])r   r   rN   r   r   r   )r4   r   r   r   )r   r   r   r   r   rJ   r  r  r  r;  r?  rB  r   r   r  s   @r5   r   r     s     /3"'"04$
#$
 ,$
 	$

 $
  $
 $
 $
 .$
 
$
 $
Lb	 IMMJ Jr7   r   )r4   r   r   r   )Pr   
__future__r   rZ  ry  r	  r  collectionsr   typingr   r   r   r   r	   r
   
bson.int64r   bson.objectidr   gridfs.errorsr   r   r   gridfs.grid_file_sharedr   r   r   r   r   r   r   r   r   r   r   r   r   r   pymongor   r   r    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/   r0   r:  r6   r9   r   rM   IOBaser  GRIDOUT_BASE_CLASSrZ   r  r"  r   rw   r7   r5   <module>rW     s    5 "   	   C C  " = =     ? > B ; 3 7 . *  A @V
D DNk	 k	\l l^ #+RYY n% nba  a H  FJ FJr7   