+\hdZddlmZddlZddlZddlmZddlmZm Z m Z m Z m Z m Z mZmZmZmZmZmZddlmZmZddlmZddlmZdd lmZmZdd lmZdd l m!Z!m"Z"dd l#m$Z$m%Z%m&Z&m'Z'm(Z(dd l)m*Z*m+Z+m,Z,ddl-m.Z.ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6ddl7m8Z8ddl9m:Z:ddl;mZ>m?Z?ddl@mAZAer$ddlBmCZCddlDmEZEddlFmGZGddlHmIZIddlJmKZKddlLmMZMdZNGddZOGdde e?ZPGdd ePe e?ZQy)!z1Cursor class to iterate over Mongo query results.) annotationsN)deque) TYPE_CHECKINGAnyGenericIterableListMappingNoReturnOptionalSequenceUnioncastoverload)RE_TYPE&_convert_raw_document_lists_to_streams)Code)SON)_csothelpers_shared)validate_collation_or_none)validate_is_document_typevalidate_is_mapping)_CURSOR_CLOSED_ERRORS_QUERY_OPTIONS CursorType_Hint_Sort)ConnectionFailureInvalidOperationOperationFailure) _create_lock)_CursorAddress_GetMore_OpMsg_OpReply_Query_RawBatchGetMore_RawBatchQuery)PinnedResponsenext)_Address _CollationIn _DocumentOut _DocumentType)validate_boolean) SupportsItems) CodecOptions) _ServerMode) ClientSession) Collection) ConnectionTc(eZdZdZddZddZddZy) _ConnectionManagerz?Used with exhaust cursors to ensure the connection is returned.c>||_||_t|_yN)conn more_to_comer"_lock)selfr<r=s ]/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/synchronous/cursor.py__init__z_ConnectionManager.__init__Ms*. (!^ c||_yr;)r=)r?r=s r@update_exhaustz!_ConnectionManager.update_exhaustRs (rBc`|jr"|jjd|_yy)z9Return this instance's connection to the connection pool.N)r<unpinr?s r@closez_ConnectionManager.closeUs# 99 IIOO DI rBN)r<r7r=bool)r=rIreturnNonerJrK)__name__ __module__ __qualname____doc__rArDrHrBr@r9r9JsI$ )rBr9cReZdZeZeZdddddejdddddddddddddddddf d=dZ d>dZ e d?dZ e d@dZ d>dZdAd ZdBdCd ZdDd ZdEd Zd>d ZdFdZdFdZdGdZdHdZdIdZdJdZdKdZdLdZedMdZedNdZdOdZdPdZdQdZdQdZ dR dSdZ!dTdZ"dUdZ#dVdZ$dWd Z%dXd!Z&dYd"Z' dZ d[d#Z(d\d$Z)e d]d%Z*e d^d&Z+e d_d'Z,e d`d(Z-dAd)Z.dad*Z/edRdbd+Z0e dR dcd,Z0 dR ddd-Z0ded.Z1d>d/Z2d>d0Z3d>d1Z4dfd2Z5dgd3Z6d@d4Z7dAd5Z8dTd6Z9dRdhd7Z:dTd8Z;dAd9Ze?jdRdjd<ZAy)kCursorNrFc||_d|_d|_d|_d|_||r||_d|_nd|_d|_|xsi}td|t|tstdt|t|tstdt|td||r(|j stjdtd |t j"t j$t j&t j(fvr t+d td | td | t| tstdt| | dkr t+d| td|}|t-j.|d}| t1d|||_||_|du|_||_||_||_| |_|xrt-j@|xsd|_!||_"d|_#||_$||_%|jjLjNjPjR|_*d|_+||_,||_-t]| |_/||_0||_1||_2||_3||ji| d|_5tm|_7d|_8d|_9|jt|_;d|_<|jz|_>||_?||_@|r|xj~tdzc_?| r|xj~tdzc_?| r|xj~td zc_?|jLj|_C|j|_Dtrd|_F|jy|t j(k(|_d|_Fy)a Create a new cursor. Should not be called directly by application developers - see :meth:`~pymongo.collection.Collection.find` instead. .. seealso:: The MongoDB documentation on `cursors `_. NFTfilterz%skip must be an instance of int, not z&limit must be an instance of int, not no_cursor_timeoutzuse an explicit session with no_cursor_timeout=True otherwise the cursor may still timeout after 30 minutes, for more info see https://mongodb.com/docs/v4.4/reference/method/cursor.noCursorTimeout/#session-idle-timeout-overrides-nocursortimeout) stacklevelz!not a valid value for cursor_typeallow_partial_results oplog_replay#batch_size must be an integer, not rbatch_size must be >= 0allow_disk_use projectionlet no_timeoutpartial)H _collection_id_exhaust _sock_mgr_killed_session_explicit_sessionr isinstanceint TypeErrortyper1warningswarn UserWarningr NON_TAILABLETAILABLETAILABLE_AWAITEXHAUST ValueErrorr_fields_list_to_dictr_let_spec _has_filter _projection_skip_limit _batch_size_index_document _ordering _max_scan_explain_comment _max_time_msdatabaseclientoptionstimeout_timeout_max_await_time_ms_max_minr _collation _return_key_show_record_id_allow_disk_use _snapshot _set_hint_emptyr_data_address _retrieved codec_options_codec_options_read_preference read_concern _read_concern _query_flags _cursor_typername_dbname _collname_IS_SYNC_exhaust_checked_supports_exhaust)r? collectionrUr^skiplimitrV cursor_typesortrYrZ batch_size collationhintmax_scan max_time_msmaxmin return_keyshow_record_idsnapshotcommentsessionr]r_specs r@rAzCursor.__init__`stH7A "  #DM%)D " DM%*D ""(,BHd+$$CDJ<PQ Q%%DT%[MRS S,.?@ T%;%; MMB     # #     % %      @A A02GH6*c*A$zBRASTU U >67 7  %-.>ON  !'<>$'D T"  sB55B5=B5c<|j|j|S)zACreates an empty Cursor object for information to be copied into.)r) __class__rb)r?rs r@rzCursor._clone_baseEs~~d..~@@rBci}|jr|j|d<|jrd|d<|jr|j|d<|jr|j|d<|jr|j|d<|j r|j |d<|j |j |d<|jr|j|d <|jr|j|d <|j|j|d <|j|j|d <|j|j|d <|r0t|j}d|vrd|i}|j||Sd|jvrGt|jdk(s!t!t#|jdk(rd|jiS|jS)z Get the spec to use for a query.z$orderbyTz$explainz$hintr_z$commentz$maxScanz $maxTimeMSz$maxz$minz $returnKeyz $showDiskLocz $snapshotz$queryqueryr)r~r_hintrvrrrrrrrrdictrwrlenr,iter)r? operatorsrs r@ _query_speczCursor._query_specIs$& >>$(NNIj ! ==$(Ij ! ::!%Ig  99#yyIe  ==$(MMIj ! >>$(NNIj !    (&*&7&7Il # 99 $ If  99 $ If     '&*&6&6Il #    +(,(<(> %%)^^Ik "  #Dt# $' KK "K  "DJJ1(<T$**EU@VZa@adjj) )zzrBcJ|js |j tdy)z;Check if it is okay to chain more options onto this cursor.Nz(cannot set options after executing query)rrcr rGs r@_check_okay_to_chainzCursor._check_okay_to_chain{s# ??dhh2"#MN N3rBc\t|tstdt||j |t dzrS|j r td|jjjjr tdd|_ |xj|zc_ |S)zsSet arbitrary query flags using a bitmask. To set the tailable flag: cursor.add_option(2) mask must be an int, not rrrT)rirjrkrlrrr{r rbrrrrdrr?masks r@ add_optionzCursor.add_options $$7T |DE E !!# .+ +{{&'NOO((//99&'TUU DM T! rBct|tstdt||j |t dzrd|_|xj|zc_|S)zzUnset arbitrary query flags using a bitmask. To unset the tailable flag: cursor.remove_option(2) rrF)rirjrkrlrrrdrrs r@ remove_optionzCursor.remove_options] $$7T |DE E !!# .+ +!DM dU" rBct|tstdt||j ||_|S)aSpecifies whether MongoDB can use temporary disk files while processing a blocking sort operation. Raises :exc:`TypeError` if `allow_disk_use` is not a boolean. .. note:: `allow_disk_use` requires server version **>= 4.4** :param allow_disk_use: if True, MongoDB may use temporary disk files to store data exceeding the system memory limit while processing a blocking sort operation. .. versionadded:: 3.11 z#allow_disk_use must be a bool, not )rirIrkrlrr)r?r]s r@r]zCursor.allow_disk_uses@.$/A$~BVAWXY Y !!#- rBct|tstdt||jr t d|j d|_||_|S)aLimits the number of results to be returned by this cursor. Raises :exc:`TypeError` if `limit` is not an integer. Raises :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has already been used. The last `limit` applied to this cursor takes precedence. A limit of ``0`` is equivalent to no limit. :param limit: the number of results to return .. seealso:: The MongoDB documentation on `limit `_. zlimit must be an integer, not rF) rirjrkrlrdr rrr{)r?rs r@rz Cursor.limitsW%%67 7 !!#% rBct|tstdt||dkr t d|j ||_|S)aSkips the first `skip` results of this cursor. Raises :exc:`TypeError` if `skip` is not an integer. Raises :exc:`ValueError` if `skip` is less than ``0``. Raises :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has already been used. The last `skip` applied to this cursor takes precedence. :param skip: the number of results to skip zskip must be an integer, not rzskip must be >= 0)rirjrkrlrtrrz)r?rs r@rz Cursor.skipsP$$;DJ<HI I !801 1 !!#  rBct|ts|tdt||j ||_|S)aSpecifies a time limit for a query operation. If the specified time is exceeded, the operation will be aborted and :exc:`~pymongo.errors.ExecutionTimeout` is raised. If `max_time_ms` is ``None`` no limit is applied. Raises :exc:`TypeError` if `max_time_ms` is not an integer or ``None``. Raises :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has already been used. :param max_time_ms: the time limit after which the operation is aborted z,max_time_ms must be an integer or None, not )rirjrkrlrr)r?rs r@rzCursor.max_time_mssF+s+ 0GJ4P[K\J]^_ _ !!#' rBct|ts|tdt||j |j t jzr||_|S)aSSpecifies a time limit for a getMore operation on a :attr:`~pymongo.cursor.CursorType.TAILABLE_AWAIT` cursor. For all other types of cursor max_await_time_ms is ignored. Raises :exc:`TypeError` if `max_await_time_ms` is not an integer or ``None``. Raises :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has already been used. .. note:: `max_await_time_ms` requires server version **>= 3.2** :param max_await_time_ms: the time limit after which the operation is aborted .. versionadded:: 3.2 z2max_await_time_ms must be an integer or None, not ) rirjrkrlrrrrrr)r?rs r@rzCursor.max_await_time_mssd +S16G6SDTJ[E\D]^  !!#   z88 8&7D # rBcyr;rQr?indexs r@ __getitem__zCursor.__getitem__- rBcyr;rQrs r@rzCursor.__getitem__1rrBctre|jd|_t|tr|j t dd}|j&|jdkr t d|j}|j/|j|z }|dkrt d|z|dk(r d|_nd}||_ ||_ |St|tr|dkr t d|j}|j||jz|jd|xjt j"zc_|D]}|cSt dt%d |zt d ) aIGet a single document or a slice of documents from this cursor. .. warning:: A :class:`~Cursor` is not a Python :class:`list`. Each index access or slice requires that a new query be run using skip and limit. Do not iterate the cursor using index accesses. The following example is **extremely inefficient** and may return surprising results:: cursor = db.collection.find() # Warning: This runs a new query for each document. # Don't do this! for idx in range(10): print(cursor[idx]) Raises :class:`~pymongo.errors.InvalidOperation` if this cursor has already been used. To get a single document use an integral index, e.g.:: >>> db.test.find()[50] An :class:`IndexError` will be raised if the index is negative or greater than the amount of documents in this cursor. Any limit previously applied to this cursor will be ignored. To get a slice of documents use a slice index, e.g.:: >>> db.test.find()[20:25] This will return this cursor with a limit of ``5`` and skip of ``20`` applied. Using a slice index will override any prior limits or skips applied to this cursor (including those applied through previous calls to this method). Raises :class:`IndexError` when the slice has a step, a negative start value, or a stop value less than or equal to the start value. :param index: An integer or slice index to be applied to this cursor Fz+Cursor instances do not support slice stepsrz0Cursor instances do not support negative indicesz8stop index must be greater than start index for slice %rTz no such item for Cursor instancez.index %r cannot be applied to Cursor instancesz Cursor does not support indexing)rrrrislicestep IndexErrorstartstoprzr{rjrrrrrrrrk)r?rrrrdocs r@rzCursor.__getitem__5sfP   % % 'DK%'::)$%RSS;;*{{Q()[\\ ;;D::)!JJ-Eqy(VY^^z&* E! #  %%19$%WXX  54::-. B""z'@'@&@@" CJ !CDDLuTU U?@ @rBc4|j||_|S)a1**DEPRECATED** - Limit the number of documents to scan when performing the query. Raises :class:`~pymongo.errors.InvalidOperation` if this cursor has already been used. Only the last :meth:`max_scan` applied to this cursor has any effect. :param max_scan: the maximum number of documents to scan .. versionchanged:: 3.7 Deprecated :meth:`max_scan`. Support for this option is deprecated in MongoDB 4.0. Use :meth:`max_time_ms` instead to limit server side execution time. )rr)r?rs r@rzCursor.max_scans !!#! rBct|ttfstdt ||j t ||_|S)a!Adds ``max`` operator that specifies upper bound for specific index. When using ``max``, :meth:`~hint` should also be configured to ensure the query uses the expected index and starting in MongoDB 4.2 :meth:`~hint` will be required. :param spec: a list of field, limit pairs specifying the exclusive upper bound for all keys of a specific index in order. .. versionchanged:: 3.8 Deprecated cursors that use ``max`` without a :meth:`~hint`. .. versionadded:: 2.7 /spec must be an instance of list or tuple, not )rilisttuplerkrlrrrr?rs r@rz Cursor.maxF$u .MdSWj\Z[ [ !!#J  rBct|ttfstdt ||j t ||_|S)a!Adds ``min`` operator that specifies lower bound for specific index. When using ``min``, :meth:`~hint` should also be configured to ensure the query uses the expected index and starting in MongoDB 4.2 :meth:`~hint` will be required. :param spec: a list of field, limit pairs specifying the inclusive lower bound for all keys of a specific index in order. .. versionchanged:: 3.8 Deprecated cursors that use ``min`` without a :meth:`~hint`. .. versionadded:: 2.7 r)rirrrkrlrrrrs r@rz Cursor.minrrBc|jtj||}tj||_|S)aSorts this cursor's results. Pass a field name and a direction, either :data:`~pymongo.ASCENDING` or :data:`~pymongo.DESCENDING`.:: for doc in collection.find().sort('field', pymongo.ASCENDING): print(doc) To sort by multiple fields, pass a list of (key, direction) pairs. If just a name is given, :data:`~pymongo.ASCENDING` will be inferred:: for doc in collection.find().sort([ 'field1', ('field2', pymongo.DESCENDING)]): print(doc) Text search results can be sorted by relevance:: cursor = db.test.find( {'$text': {'$search': 'some words'}}, {'score': {'$meta': 'textScore'}}) # Sort by 'score' field. cursor.sort([('score', {'$meta': 'textScore'})]) for doc in cursor: print(doc) For more advanced text search functionality, see MongoDB's `Atlas Search `_. Raises :class:`~pymongo.errors.InvalidOperation` if this cursor has already been used. Only the last :meth:`sort` applied to this cursor has any effect. :param key_or_list: a single key or a list of (key, direction) pairs specifying the keys to sort on :param direction: only used if `key_or_list` is a single key, if not given :data:`~pymongo.ASCENDING` is assumed )rr _index_listr}r~)r? key_or_list directionkeyss r@rz Cursor.sorts:V !!#))+yA'77= rBc|j}d|_|jrt|j |_t |S)aJReturns an explain plan record for this cursor. .. note:: This method uses the default verbosity mode of the `explain command `_, ``allPlansExecution``. To use a different verbosity use :meth:`~pymongo.database.Database.command` to run the explain command directly. .. note:: The timeout of this method can be set using :func:`pymongo.timeout`. .. seealso:: The MongoDB documentation on `explain `_. T)rrr{absr,)r?cs r@rzCursor.explains9 JJL  88AHH ~AHAwrBc||d|_yt|tr||_ytj||_yr;)rristrrr}rs r@rzCursor._set_hint s4 =DJ  eS !DJ'77>DJrBcH|j|j||S)aAdds a 'hint', telling Mongo the proper index to use for the query. Judicious use of hints can greatly improve query performance. When doing a query on multiple fields (at least one of which is indexed) pass the indexed field as a hint to the query. Raises :class:`~pymongo.errors.OperationFailure` if the provided hint requires an index that does not exist on this collection, and raises :class:`~pymongo.errors.InvalidOperation` if this cursor has already been used. `index` should be an index as passed to :meth:`~pymongo.collection.Collection.create_index` (e.g. ``[('field', ASCENDING)]``) or the name of the index. If `index` is ``None`` any existing hint for this query is cleared. The last hint applied to this cursor takes precedence over all others. :param index: index to hint on (as an index specifier) )rrrs r@rz Cursor.hints!( !!# u rBc4|j||_|S)a"Adds a 'comment' to the cursor. http://mongodb.com/docs/manual/reference/operator/comment/ :param comment: A string to attach to the query to help interpret and trace the operation in the server logs and in profile data. .. versionadded:: 2.7 )rr)r?rs r@rzCursor.comment.s !!#  rBc|jt|ts t|}|jrt |j }nt t|j }||d<||_|S)aAdds a `$where`_ clause to this query. The `code` argument must be an instance of :class:`str` or :class:`~bson.code.Code` containing a JavaScript expression. This expression will be evaluated for each document scanned. Only those documents for which the expression evaluates to *true* will be returned as results. The keyword *this* refers to the object currently being scanned. For example:: # Find all documents where field "a" is less than "b" plus "c". for doc in db.test.find().where('this.a < (this.b + this.c)'): print(doc) Raises :class:`TypeError` if `code` is not an instance of :class:`str`. Raises :class:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has already been used. Only the last call to :meth:`where` applied to a :class:`Cursor` has any effect. .. note:: MongoDB 4.4 drops support for :class:`~bson.code.Code` with scope variables. Consider using `$expr`_ instead. :param code: JavaScript expression to use as a filter .. _$expr: https://mongodb.com/docs/manual/reference/operator/query/expr/ .. _$where: https://mongodb.com/docs/manual/reference/operator/query/where/ z$where)rrirrxrrwr)r?coders r@wherez Cursor.where<sa6 !!#$%:D    #Ddjj)DX  rBcF|jt||_|S)aAdds a :class:`~pymongo.collation.Collation` to this query. Raises :exc:`TypeError` if `collation` is not an instance of :class:`~pymongo.collation.Collation` or a ``dict``. Raises :exc:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has already been used. Only the last collation applied to this cursor has any effect. :param collation: An instance of :class:`~pymongo.collation.Collation`. )rrr)r?rs r@rzCursor.collationfs! !!#4Y? rBc*|j||||Sr;)unpack_response)r?response cursor_idr user_fieldslegacy_responses r@_unpack_responsezCursor._unpack_responseus'' =+__rBc|j*|jj|j|_|jSr;)rrb_read_preference_forrrGs r@_get_read_preferencezCursor._get_read_preferences7  ($($4$4$I$I$,,$WD !$$$rBc\tt|jxs |j S)aDoes this cursor have the potential to return more data? This is mostly useful with `tailable cursors `_ since they will stop iterating even though they *may* return more results in the future. With regular cursors, simply use a for loop instead of :attr:`alive`:: for doc in collection.find(): print(doc) .. note:: Even if :attr:`alive` is True, :meth:`next` can raise :exc:`StopIteration`. :attr:`alive` can also be True while iterating a cursor from a failed server. In this case :attr:`alive` will return False after :meth:`next` fails to retrieve the next batch of results from the server. )rIrrrfrGs r@alivez Cursor.alives#(C O9DLL(8::rBc|jS)zDReturns the id of the cursor .. versionadded:: 2.2 )rcrGs r@rzCursor.cursor_ids xxrBc|jS)zzThe (host, port) of the server used, or None. .. versionchanged:: 3.0 Renamed from "conn_id". )rrGs r@addresszCursor.addresss}}rBc4|jr |jSy)zmThe cursor's :class:`~pymongo.client_session.ClientSession`, or None. .. versionadded:: 3.6 N)rhrgrGs r@rzCursor.sessions  ! !== rBc&|jdS)zKSupport function for `copy.copy()`. .. versionadded:: 2.4 FrrrGs r@__copy__zCursor.__copy__s {{E{**rBc&|jdS)zOSupport function for `copy.deepcopy()`. .. versionadded:: 2.4 Tr(r)r?memos r@ __deepcopy__zCursor.__deepcopy__s {{D{))rBcyr;rQr?xr+s r@rzCursor._deepcopyrrBcyr;rQr.s r@rzCursor._deepcopys rBct|dsgdt|}}}nidtd|j}}}|i}t |}||vr||S|||<|D]\}}t |t tfr#t |ts|j||}n&t |tstj||}|r|j|yt |tstj||}|||<|S)zDeepcopy helper for the data dictionary or list. Regular expressions cannot be deep copied but as they are immutable we don't have to copy them when cloning. rTFr2)hasattr enumeraterridrirrrrrcopyrappend) r?r/r+yis_listiteratorval_idkeyvalues r@rzCursor._deepcopysq'"#%tYq\wA#%ud?A.F.L.L.NwA <DA T>< V " JC%$.z%7Mud3w/ eT2!#w/--T2C# rBcd|_|jrO|sM|j}|jJt|j|jd|j }||fSd}d}||fS)NT.r)rfrcrr#rrr?already_killedrr%s r@_prepare_to_diezCursor._prepare_to_diess 88NI==, ,,$T]]t||nAdnnEU4VWG '!!IG'!!rBc: |j}|j|\}}|jjj j |||j|j|j|jsd|_d|_y#t$rYywxYw)z,Closes this cursor without acquiring a lock.N) rfAttributeErrorrArbrr_cleanup_cursor_no_lockrergrhr?s r@rzCursor._die_no_locks !\\N "11.A 7 !!((@@ w t?U?U %% DM    B BBc: |j}|j|\}}|jjj j |||j|j|j|jsd|_d|_y#t$rYywxYw)zCloses this cursor.N) rfrCrArbrr_cleanup_cursor_lockrergrhr?s r@ _die_lockzCursor._die_lock s !\\N "11.A 7 !!((==   NN MM  " "  %% DM   rEc$|jy)z$Explicitly close / kill this cursor.N)rHrGs r@rHz Cursor.close!s  rBc0i}|jr|j|d<|j|j|d<|jr|j|d<|j|j|d<|jj |fd|j i|S)aOGet a list of distinct values for `key` among all documents in the result set of this query. Raises :class:`TypeError` if `key` is not an instance of :class:`str`. The :meth:`distinct` method obeys the :attr:`~pymongo.collection.Collection.read_preference` of the :class:`~pymongo.collection.Collection` instance on which :meth:`~pymongo.collection.Collection.find` was called. :param key: name of key for which we want to get the distinct values .. seealso:: :meth:`pymongo.collection.Collection.distinct` r maxTimeMSrrr)rwrrrrbdistinctrg)r?r;rs r@rLzCursor.distinct%s #% ::#zzGG     (#'#4#4GK ==!%GI  ?? &#'??GK (t((OdmmOwOOrBc~|jjj}|jr|jr t d |j ||j|j}|j(|_t+|t,r1|j.s%t1|j2|j4|_|j6}|j8}|j:r|dk7r|dd}|d |_|d k(r8|d }|j?d } | r%| jAd d\|_!|_"n|d}tG||_$|xjJtM|z c_%nd|_tG||_$|xjJtM|z c_%npt+|jNtPsJ|jNjR|_tG||_$|xjJ|jNjTz c_%|j<dk(r|j|jVr8|j<r+|jV|jJkr|jyyyy#t$r}|jtvs |jrd|_ |jr|jn|j|jtvr|j t"dzrYd}~yd}~wt$$rd|_ |jt&$r|jwxYw)a#Send a query or getmore operation and handles the response. If operation is ``None`` this is an exhaust cursor, which reads the next result batch off the exhaust socket instead of sending getMore messages to the server. Can raise ConnectionFailure. z.exhaust cursors do not support auto encryption)r%Ttailable_cursorNrrcursorr4find firstBatchnsr>r nextBatch),rbrr _encrypterrdr _run_operationrrr!rrrfrrrHrrr BaseExceptionr%rir*rer9r<r=rdocs from_commandrcgetsplitrrrrrrrr&rnumber_returnedr{) r? operationrrexccmd_namerWrO documentsrRs r@ _send_messagezCursor._send_messageAs!!**11   "#ST T ,,400$---H:!(( h />>!3HMM8CXCX!Y>>}}  9$a*!$<v% &| 4ID)B79xxQ7G4 dn &{ 3I"9- 3y>1"4[ 3t9,hmmX6 66}}..DHtDJ OOx}}<< A:K>=K>>>L<ct|js |jrt|jS|js3|jj j j|_|j<|js |jr|js td|j|j|jj j|jj|j |j#|j$|j&|j)|j*|j,|j.|j0|j|jj j |j2|j4}|j7|n|jr|j*r<|j*|j8z }|j,r#t;||j,}n |j,}|j=|j>|j@||j|j&|j)|j|jj j |jB|jD|j4|jF }|j7|t|jS)aRefreshes the cursor with more data from Mongo. Returns the length of self._data after refresh. Will exit early if self._data is already non-empty. Raises OperationFailure when the cursor cannot be refreshed due to an error on the query. zoPassing a 'hint' is required when using the min/max query option to ensure the query utilizes the correct index)$rrrfrgrbrr_ensure_sessionrcrrrr _query_classrrrzrryrr r{r|rrrrdr`rr_getmore_classrrrrer)r?qrgs r@_refreshzCursor._refreshs# tzz?dlltzz? "}} ,,55<<LLNDM 88  TYY &M!!!!  ))..  %%   "  ##))+   ""   ))00$$ !A$   q ! XX{{ doo5##t'7'78E((## ##))+   ))00''   A   q !4::rBc||jt|_d|_d|_d|_d|_|S)aRewind this cursor to its unevaluated state. Reset this cursor if it has been partially or completely evaluated. Any options that are present on the cursor will remain in effect. Future iterating performed on this cursor will cause new queries to be sent to the server, even if the resultant data has already been retrieved by this cursor. NrF)rHrrrcrrrfrGs r@rewindz Cursor.rewinds7 W    rBc|jsd|_|j|jrtt |j s|j r|j jSt)zAdvance the cursor.T)rrr StopIterationrrrgpopleftrGs r@r,z Cursor.nextsX$$$(D !  " " $ ;;  tzz?dmmo::%%' ' rBc|jsd|_|j|jryt|js|j r|6|j |j|jjyttt|j|D]+}|j|jj-yy)z*Get all or some documents from the cursor.TF) rrrrrrgextendclearrangerr6rl)r?resulttotalrs r@ _next_batchzCursor._next_batchs$$$(D !  " " $ ;; tzz?dmmo} djj)   "s3tzz?E:;8AMM$**"4"4"678rBc"|jSr;r+rGs r@__next__zCursor.__next__syy{rBc|Sr;rQrGs r@__iter__zCursor.__iter__ rBc|Sr;rQrGs r@ __enter__zCursor.__enter__ rxrBc$|jyr;)rH)r?exc_typeexc_valexc_tbs r@__exit__zCursor.__exit__ s  rBcg}|}t|tr|dkr td|jr:|j ||s |S||t |z }|dk(r |S|jr:|S)akConverts the contents of this cursor to a list more efficiently than ``[doc for doc in cursor]``. To use:: >>> cursor.to_list() Or, to read at most n items from the cursor:: >>> cursor.to_list(n) If the cursor is empty or has no more results, an empty list will be returned. .. versionadded:: 4.9 rz'to_list() length must be greater than 0r)rirjrtr"rsr)r?lengthres remainings r@to_listzCursor.to_lists $& fc "vzFG Gjj##C3  !"SX- > jj rB)2rCollection[_DocumentType]rUOptional[Mapping[str, Any]]r^z1Optional[Union[Mapping[str, Any], Iterable[str]]]rrjrrjrVrIrrjrOptional[_Sort]rYrIrZrIrrjrOptional[_CollationIn]rOptional[_Hint]r Optional[int]rrrrrrrOptional[bool]rrrrrz Optional[Any]rOptional[ClientSession]r]rr_rrJrKrL)rJr)rJrj)rJCursor[_DocumentType])TN)rrIrzOptional[Cursor]rJrS)rrrJrS)rJzMapping[str, Any])rrjrJr)r]rIrJr)rrjrJr)rrjrJr)rrjrJr)rrrJr)rrrJr)rrjrJr0)rrrJr)rzUnion[int, slice]rJz+Union[_DocumentType, Cursor[_DocumentType]])rrrJr)rrrJrr;)r rr zOptional[Union[int, str]]rJrrJr0)rrrJrK)rrrJr)rrrJr)rzUnion[str, Code]rJr)rrrJrNF) rUnion[_OpReply, _OpMsg]rrrr3rrrrIrJzSequence[_DocumentOut])rJr4)rJrI)rJr)rJzOptional[tuple[str, Any]])rJr)r+rrJr)r/rr+&Optional[dict[int, Union[list, dict]]]rJr)r/r2r+rrJr)r/zUnion[Iterable, SupportsItems]r+rrJzUnion[list, dict])r@rIrJz$tuple[int, Optional[_CursorAddress]])r;rrJr)r\zUnion[_Query, _GetMore]rJrK)rqrrrrrJrI)r|rr}rr~rrJrK)rrrJzlist[_DocumentType])BrMrNrOr'rcr$rdrrprArpropertyrrrrrrrrrrr]rrrrrrrrrrrrrrrrrrr r"rr%rr)r,rrArrHrHrLr`rgrir,rsrurwrzrrapplyrrQrBr@rSrS\sLN /3HL"'%22 $&+",0 $"&%)##%))-#'!%+/)-"3W*-W*,W*F W*  W*  W* W*W*W* $W*W*W**W*W* W* #!W*"#W*$%W*&#'W*(')W**!+W*,-W*.)/W*0'1W*23W*4 5W*r!  !(TA0dO ( *,6(&8    PAd&,.JN. .-F. .`,?0 (T (48 % `)`!`$ ` 1 `  ` `% ;;*+*  OS  &L   ae!/!7]! !F " (P8Qf>@$  $ [[rBrSc`eZdZdZeZeZdfd Z d ddZ d dZ d dZ xZ S) RawBatchCursorzFA cursor / iterator over raw batches of BSON data from a query result.c,t||g|i|y)aGCreate a new cursor / iterator over raw batches of BSON data. Should not be called directly by application developers - see :meth:`~pymongo.collection.Collection.find_raw_batches` instead. .. seealso:: The MongoDB documentation on `cursors `_. N)superrA)r?rargskwargsrs r@rAzRawBatchCursor.__init__4s 5d5f5rBcn|j||}|st|dttd|S)N)rrr/) raw_responserrr )r?rrrrrrs r@rzRawBatchCursor._unpack_response?s< ,,YK,P  3<? CD(,77rBcn|jdt|j}|jS)zReturns an explain plan record for this cursor. .. seealso:: The MongoDB documentation on `explain `_. T)rr)rrSrr)r?rs r@rzRawBatchCursor.explainNs+  Tt0G H}}rBctd)Nz)Cannot call __getitem__ on RawBatchCursor)r rs r@rzRawBatchCursor.__getitem__VsJKKrB)rrrrrrrJrKr) rrrrrzCodecOptions[Mapping[str, Any]]rrrrIrJzlist[_DocumentOut]r)rrrJr ) rMrNrOrPr)rcr(rdrArrr __classcell__)rs@r@rr.sgP!L%N 6 48 % 8) 8! 87 8 1 8  8  8LrBr)RrP __future__rr5rm collectionsrtypingrrrrr r r r r rrrbsonrr bson.coderbson.sonrpymongorrpymongo.collationrpymongo.commonrrpymongo.cursor_sharedrrrrrpymongo.errorsrr r! pymongo.lockr"pymongo.messager#r$r%r&r'r(r)pymongo.responser*pymongo.synchronous.helpersr,pymongo.typingsr-r.r/r0pymongo.write_concernr1 _typeshedr2bson.codec_optionsr3pymongo.read_preferencesr4"pymongo.synchronous.client_sessionr5pymongo.synchronous.collectionr6pymongo.synchronous.poolr7rr9rSrrQrBr@rs8"     A)8baPP%,,OO2'/4@93 $OW] #Od&)LVW]3)LrB