Ë
    Ü_ËijA  ã                  ó4  — d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZmZmZmZmZ dd
l m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z' erddl(m)Z) ddl*m+Z+ ddl,m-Z- dZ. G d„ dee'   «      Z/ G d„ de/e'   «      Z0y)z4CommandCursor class to iterate over command results.é    )Úannotations)Údeque)	ÚTYPE_CHECKINGÚAnyÚGenericÚIteratorÚMappingÚNoReturnÚOptionalÚSequenceÚUnion)ÚCodecOptionsÚ&_convert_raw_document_lists_to_streams)Ú_csot)Ú_CURSOR_CLOSED_ERRORS)ÚConnectionFailureÚInvalidOperationÚOperationFailure)Ú_CursorAddressÚ_GetMoreÚ_OpMsgÚ_OpReplyÚ_RawBatchGetMore)ÚPinnedResponse)Ú_ConnectionManager)Ú_AddressÚ_DocumentOutÚ_DocumentType)ÚClientSession)Ú
Collection)Ú
ConnectionTc                  ó„  — e Zd ZdZeZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zd d„Zd!d„Zd"d„Z	e
d#d„«       Zd$d„Z	 	 d%	 	 	 	 	 	 	 	 	 	 	 d&d	„Ze
d"d
„«       Ze
d'd„«       Ze
d(d„«       Ze
d)d„«       Zd*d„Zd d„Zd d„Zd d„Zd d„Zd+d„Zd'd„Zd,d„Zd-d„Zd-d„Zd.d„Zd/d0d„Zd1d„Zd2d„Zd3d„Z e!jD                  d/d4d„«       Z#y)5ÚCommandCursorz)A cursor / iterator over command cursors.Nc                óŽ  — d| _         || _        |d   | _        t        |d   «      | _        |j                  d«      | _        || _        || _        || _	        | j                  j                  j                  j                  j                  | _        || _        | j                  �d| j                  _        | j                  dk(  | _        || _        | j"                  r| j'                  «        d|v r|d   | _        n|j*                  | _        | j-                  |«       t/        |t0        «      s|�t3        dt5        |«      › �«      ‚yy)	zCreate a new command cursor.NÚidÚ
firstBatchÚpostBatchResumeTokenTr   Únsz2max_await_time_ms must be an integer or None, not )Ú	_sock_mgrÚ_collectionÚ_idr   Ú_dataÚgetÚ_postbatchresumetokenÚ_addressÚ_batch_sizeÚ_max_await_time_msÚdatabaseÚclientÚoptionsÚtimeoutÚ_timeoutÚ_sessionÚ_attached_to_cursorÚ_killedÚ_commentÚ_end_sessionÚ_nsÚ	full_nameÚ
batch_sizeÚ
isinstanceÚintÚ	TypeErrorÚtype)ÚselfÚ
collectionÚcursor_infoÚaddressr>   Úmax_await_time_msÚsessionÚcomments           úe/var/www/pod-logistic/pod-api/venv/lib/python3.12/site-packages/pymongo/synchronous/command_cursor.pyÚ__init__zCommandCursor.__init__;   s.  € ð #ˆŒØ6@ˆÔØ˜tÑ$ˆŒÜ˜; |Ñ4Ó5ˆŒ
ØBMÇ/Á/Ø"óC
ˆÔ"ð  ˆŒØ%ˆÔØ"3ˆÔØ×(Ñ(×1Ñ1×8Ñ8×@Ñ@×HÑHˆŒØˆŒØ�=‰=Ð$Ø04ˆD�M‰MÔ-Ø—x‘x 1‘}ˆŒØˆŒØ�<Š<Ø×ÑÔà�;ÑØ" 4Ñ(ˆD�Hà!×+Ñ+ˆDŒHà�‰˜
Ô#äÐ+¬SÔ1Ð6GÐ6SÜØDÄTÐJ[ÓE\ÐD]Ð^óð ð 7TÐ1ó    c                ó$   — | j                  «        y ©N)Ú_die_no_lock©rC   s    rJ   Ú__del__zCommandCursor.__del__e   s   € Ø×ÑÕrL   c                ó˜   — t        |t        «      st        dt        |«      › �«      ‚|dk  rt	        d«      ‚|dk(  xr dxs || _        | S )a±  Limits the number of documents returned in one batch. Each batch
        requires a round trip to the server. It can be adjusted to optimize
        performance and limit data transfer.

        .. note:: batch_size can not override MongoDB's internal limits on the
           amount of data it will return to the client in a single batch (i.e
           if you set batch size to 1,000,000,000, MongoDB will currently only
           return 4-16MB of results per batch).

        Raises :exc:`TypeError` if `batch_size` is not an integer.
        Raises :exc:`ValueError` if `batch_size` is less than ``0``.

        :param batch_size: The size of each batch of results requested.
        z#batch_size must be an integer, not r   zbatch_size must be >= 0é   é   )r?   r@   rA   rB   Ú
ValueErrorr0   )rC   r>   s     rJ   r>   zCommandCursor.batch_sizeh   sU   € ô ˜*¤cÔ*ÜÐAÄ$ÀzÓBRÐASÐTÓUÐUØ˜Š>ÜÐ6Ó7Ð7à%¨™?Ò0¨qÒ>°JˆÔØˆrL   c                ó2   — t        | j                  «      dkD  S )z^Returns `True` if the cursor has documents remaining from the
        previous batch.
        r   )Úlenr,   rP   s    rJ   Ú	_has_nextzCommandCursor._has_next   s   € ô �4—:‘:‹ Ñ"Ð"rL   c                ó   — | j                   S )zlRetrieve the postBatchResumeToken from the response to a
        changeStream aggregate or getMore.
        )r.   rP   s    rJ   Ú_post_batch_resume_tokenz&CommandCursor._post_batch_resume_token…   s   € ð
 ×)Ñ)Ð)rL   c                ó  — | j                   j                  j                  }|j                  | j                  «      sy | j
                  sD|j                  «        t        |d«      }| j                  dk(  r|j                  «        y || _        y y )NFr   )
r*   r2   r3   Ú_should_pin_cursorr7   r)   Ú
pin_cursorr   r+   Úclose)rC   Úconnr3   Úconn_mgrs       rJ   Ú_maybe_pin_connectionz#CommandCursor._maybe_pin_connectionŒ   sn   € Ø×!Ñ!×*Ñ*×1Ñ1ˆØ×(Ñ(¨¯©Ô7ØØ�~Š~Ø�O‰OÔÜ)¨$°Ó6ˆHð �x‰x˜1Š}Ø—‘Õ à!)�•ð rL   c                ó*   — |j                  ||||«      S rN   )Úunpack_response)rC   ÚresponseÚ	cursor_idÚcodec_optionsÚuser_fieldsÚlegacy_responses         rJ   Ú_unpack_responsezCommandCursor._unpack_responseš   s   € ð ×'Ñ'¨	°=À+ÈÓ_Ð_rL   c                ó\   — t        t        | j                  «      xs | j                   «      S )a  Does this cursor have the potential to return more data?

        Even if :attr:`alive` is ``True``, :meth:`next` can raise
        :exc:`StopIteration`. Best to use a for loop::

            for doc in collection.aggregate(pipeline):
                print(doc)

        .. note:: :attr:`alive` can 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.
        )ÚboolrW   r,   r9   rP   s    rJ   ÚalivezCommandCursor.alive¤   s#   € ô ”C˜Ÿ
™
“OÒ9¨D¯L©LÐ(8Ó:Ð:rL   c                ó   — | j                   S )zReturns the id of the cursor.)r+   rP   s    rJ   re   zCommandCursor.cursor_idµ   s   € ð �x‰xˆrL   c                ó   — | j                   S )zUThe (host, port) of the server used, or None.

        .. versionadded:: 3.0
        )r/   rP   s    rJ   rF   zCommandCursor.addressº   s   € ð �}‰}ÐrL   c                ó`   — | j                   r"| j                   j                  s| j                   S y)zmThe cursor's :class:`~pymongo.client_session.ClientSession`, or None.

        .. versionadded:: 3.6
        N)r7   Ú	_implicitrP   s    rJ   rH   zCommandCursor.sessionÂ   s$   € ð �=Š= §¡×!8Ò!8Ø—=‘=Ð ØrL   c                óÐ   — | j                   }d| _         | j                  r@|s>| j                  }| j                  €J ‚t        | j                  | j                  «      }||fS d}d }||fS )NTr   )r9   r+   r/   r   r<   )rC   Úalready_killedre   rF   s       rJ   Ú_prepare_to_diezCommandCursor._prepare_to_dieÌ   sl   € ØŸ™ˆØˆŒØ�8Š8™NØŸ™ˆIØ—=‘=Ð,Ð,Ð,Ü$ T§]¡]°D·H±HÓ=ˆGð
 ˜'Ð!Ð!ð ˆIØˆGØ˜'Ð!Ð!rL   c                ó8  — | j                  «       \  }}| j                  j                  j                  j	                  ||| j
                  | j                  «       | j                  r.| j                  j                  rd| j                  _        d| _        d| _        y)z,Closes this cursor without acquiring a lock.FN)	rs   r*   r2   r3   Ú_cleanup_cursor_no_lockr)   r7   rp   r8   ©rC   re   rF   s      rJ   rO   zCommandCursor._die_no_lockÙ   su   € à!×1Ñ1Ó3Ñˆ	�7Ø×Ñ×!Ñ!×(Ñ(×@Ñ@Ø�w §¡°·±ô	
ð �=Š=˜TŸ]™]×4Ò4Ø05ˆD�M‰MÔ-Ø ˆDŒMØˆ�rL   c                ó8  — | j                  «       \  }}| j                  j                  j                  j	                  ||| j
                  | j                  «       | j                  r.| j                  j                  rd| j                  _        d| _        d| _        y)zCloses this cursor.FN)	rs   r*   r2   r3   Ú_cleanup_cursor_lockr)   r7   rp   r8   rv   s      rJ   Ú	_die_lockzCommandCursor._die_lockä   sx   € à!×1Ñ1Ó3Ñˆ	�7Ø×Ñ×!Ñ!×(Ñ(×=Ñ=ØØØ�N‰NØ�M‰Mô		
ð �=Š=˜TŸ]™]×4Ò4Ø05ˆD�M‰MÔ-Ø ˆDŒMØˆ�rL   c                ó°   — | j                   rJ| j                   j                  r3d| j                   _        | j                   j                  «        d | _         y y y ©NF)r7   rp   r8   Ú_end_implicit_sessionrP   s    rJ   r;   zCommandCursor._end_sessionò   s?   € Ø�=Š=˜TŸ]™]×4Ò4Ø05ˆD�M‰MÔ-Ø�M‰M×/Ñ/Ô1Ø ˆD�Mð 5ˆ=rL   c                ó$   — | j                  «        y)z$Explicitly close / kill this cursor.N)ry   rP   s    rJ   r^   zCommandCursor.closeø   s   € à�‰ÕrL   c                ó¦  — | j                   j                  j                  }	 |j                  || j                  | j
                  ¬«      }t        |t         «      r1| j"                  s%t%        |j&                  |j(                  «      | _        |j*                  r8|j,                  d   d   }|d   }|j/                  d«      | _        |d   | _        nC|j,                  }t        |j4                  t6        «      sJ ‚|j4                  j8                  | _        | j2                  dk(  r| j                  «        t;        |«      | _        y# t        $ rL}|j                  t        v rd| _	        |j                  r| j                  «        ‚ | j                  «        ‚ d}~wt        $ r d| _	        | j                  «        ‚ t        $ r | j                  «        ‚ w xY w)	z/Send a getmore message and handle the response.)rF   TNr   ÚcursorÚ	nextBatchr'   r%   )r*   r2   r3   Ú_run_operationri   r/   r   Úcoder   r9   r5   rO   r^   r   Ú	Exceptionr?   r   r)   r   r_   Úmore_to_comeÚfrom_commandÚdocsr-   r.   r+   Údatar   re   r   r,   )rC   Ú	operationr3   rd   Úexcr   Ú	documentss          rJ   Ú_send_messagezCommandCursor._send_messageü   s|  € à×!Ñ!×*Ñ*×1Ñ1ˆð	Ø×,Ñ,Ø˜4×0Ñ0¸$¿-¹-ð -ó ˆHô. �h¤Ô/Ø—>’>Ü!3°H·M±MÀ8×CXÑCXÓ!Y�”Ø× Ò Ø—]‘] 1Ñ% hÑ/ˆFØ˜{Ñ+ˆIØ)/¯©Ð4JÓ)KˆDÔ&Ø˜d‘|ˆD�Hà Ÿ™ˆIÜ˜hŸm™m¬XÔ6Ð6Ð6Ø—}‘}×.Ñ.ˆDŒHà�8‰8�qŠ=Ø�J‰JŒLÜ˜9Ó%ˆ�
øôG  ò 		Ø�x‰xÔ0Ñ0à#�”Ø�{Š{Ø×!Ñ!Ô#ð ð —
‘
”ØûÜ ò 	àˆDŒLà�J‰JŒLØÜò 	Ø�J‰JŒLØð	ús   ¢(E Å	GÅAFÆ>Gc                óŒ  — t        | j                  «      s| j                  rt        | j                  «      S | j                  rÞ| j                  j                  dd«      \  }}| j                  j                  | j                  «      }| j                  | j                  ||| j                  | j                  | j                  j                  || j                  | j                  j                  j                  | j                   | j"                  d| j$                  «      «       n| j'                  «        t        | j                  «      S )a  Refreshes the cursor with more data from the server.

        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.
        ú.rS   F)rW   r,   r9   r+   r<   Úsplitr*   Ú_read_preference_forrH   r‹   Ú_getmore_classr0   rf   r7   r2   r3   r1   r)   r:   ry   )rC   ÚdbnameÚcollnameÚ	read_prefs       rJ   Ú_refreshzCommandCursor._refresh(  sñ   € ô ˆt�z‰zŒ?˜dŸlšlÜ�t—z‘z“?Ð"à�8Š8Ø#Ÿx™xŸ~™~¨c°1Ó5ÑˆF�HØ×(Ñ(×=Ñ=¸d¿l¹lÓKˆIØ×ÑØ×#Ñ#ØØØ×$Ñ$Ø—H‘HØ×$Ñ$×2Ñ2ØØ—M‘MØ×$Ñ$×-Ñ-×4Ñ4Ø×+Ñ+Ø—N‘NØØ—M‘Móõð" �N‰NÔä�4—:‘:‹ÐrL   c                ó   — | S rN   © rP   s    rJ   Ú__iter__zCommandCursor.__iter__J  ó   € ØˆrL   c                ój   — | j                   r"| j                  d«      }|�|S | j                   rŒ"t        ‚)zAdvance the cursor.T)rl   Ú	_try_nextÚStopIteration)rC   Údocs     rJ   ÚnextzCommandCursor.nextM  s4   € ð �jŠjØ—.‘. Ó&ˆCØˆØ�
ð �j‹jô
 ÐrL   c                ó"   — | j                  «       S rN   )r�   rP   s    rJ   Ú__next__zCommandCursor.__next__W  s   € Ø�y‰y‹{ÐrL   c                óÈ   — t        | j                  «      s| j                  s|r| j                  «        t        | j                  «      r| j                  j	                  «       S y)z<Advance the cursor blocking for at most one getMore command.N)rW   r,   r9   r”   Úpopleft)rC   Úget_more_alloweds     rJ   rš   zCommandCursor._try_nextZ  s@   € ä�4—:‘:Œ t§|¢|Ñ8HØ�M‰MŒOÜˆt�z‰zŒ?Ø—:‘:×%Ñ%Ó'Ð'àrL   c                ó®  — t        | j                  «      s| j                  s| j                  «        t        | j                  «      r�|€6|j	                  | j                  «       | j                  j                  «        yt        t        t        | j                  «      |«      «      D ]+  }|j                  | j                  j                  «       «       Œ- yy)z4Get all or some available documents from the cursor.TF)
rW   r,   r9   r”   ÚextendÚclearÚrangeÚminÚappendr¡   )rC   ÚresultÚtotalÚ_s       rJ   Ú_next_batchzCommandCursor._next_batchc  s•   € ä�4—:‘:Œ t§|¢|Ø�M‰MŒOÜˆt�z‰zŒ?Øˆ}Ø—‘˜dŸj™jÔ)Ø—
‘
× Ñ Ô"ð ô œs¤3 t§z¡z£?°EÓ:Ó;ò 8�AØ—M‘M $§*¡*×"4Ñ"4Ó"6Õ7ð8ààrL   c                ó&   — | j                  d¬«      S )ar  Advance the cursor without blocking indefinitely.

        This method returns the next document without waiting
        indefinitely for data.

        If no document is cached locally then this method runs a single
        getMore command. If the getMore yields any documents, the next
        document is returned, otherwise, if the getMore returns no documents
        (because there is no additional data) then ``None`` is returned.

        :return: The next document or ``None`` when no document is available
          after running a single getMore or when the cursor is closed.

        .. versionadded:: 4.5
        T)r¢   )rš   rP   s    rJ   Útry_nextzCommandCursor.try_nextr  s   € ð  �~‰~¨tˆ~Ó4Ð4rL   c                ó   — | S rN   r–   rP   s    rJ   Ú	__enter__zCommandCursor.__enter__„  r˜   rL   c                ó$   — | j                  «        y rN   )r^   )rC   Úexc_typeÚexc_valÚexc_tbs       rJ   Ú__exit__zCommandCursor.__exit__‡  s   € Ø�
‰
�rL   c                óÚ   — g }|}t        |t        «      r|dk  rt        d«      ‚| j                  r:| j	                  ||«      s	 |S |�|t        |«      z
  }|dk(  r	 |S | j                  rŒ:|S )ak  Converts the contents of this cursor to a list more efficiently than ``[doc for doc in cursor]``.

        To use::

          >>> cursor.to_list()

        Or, so 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
        rS   z'to_list() length must be greater than 0r   )r?   r@   rU   rl   r¬   rW   )rC   ÚlengthÚresÚ	remainings       rJ   Úto_listzCommandCursor.to_listŠ  s€   € ð  $&ˆØˆ	Ü�fœcÔ" v°¢zÜÐFÓGÐGØ�jŠjØ×#Ñ# C¨Ô3Øð
 ˆ
ð	 Ð!Ø"¤S¨£XÑ-�	Ø ’>ØØˆ
ð �j‹jð ˆ
rL   ©r   NNN©rD   zCollection[_DocumentType]rE   zMapping[str, Any]rF   úOptional[_Address]r>   r@   rG   úOptional[int]rH   úOptional[ClientSession]rI   r   ÚreturnÚNone)rÀ   rÁ   )r>   r@   rÀ   úCommandCursor[_DocumentType])rÀ   rk   )rÀ   úOptional[Mapping[str, Any]])r_   r!   rÀ   rÁ   r{   )rd   úUnion[_OpReply, _OpMsg]re   r¾   rf   zCodecOptions[Mapping[str, Any]]rg   rÃ   rh   rk   rÀ   zSequence[_DocumentOut])rÀ   r@   )rÀ   r½   )rÀ   r¿   )rÀ   z$tuple[int, Optional[_CursorAddress]])rˆ   r   rÀ   rÁ   )rÀ   zIterator[_DocumentType])rÀ   r   )r¢   rk   rÀ   úOptional[_DocumentType]rN   )r©   Úlistrª   r¾   rÀ   rk   )rÀ   rÅ   )rÀ   rÂ   )r²   r   r³   r   r´   r   rÀ   rÁ   )r·   r¾   rÀ   zlist[_DocumentType])$Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r�   rK   rQ   r>   rX   ÚpropertyrZ   ra   ri   rl   re   rF   rH   rs   rO   ry   r;   r^   r‹   r”   r—   r�   rŸ   rš   r¬   r®   r°   rµ   r   Úapplyrº   r–   rL   rJ   r#   r#   6   s—  „ Ù3à€Nð Ø+/Ø+/Øð(à-ð(ð 'ð(ð $ð	(ð
 ð(ð )ð(ð )ð(ð ð(ð 
ó(óTóó.#ð ò*ó ð*ó*ð& 48Ø %ð`à)ð`ð !ð`ð 7ð	`ð
 1ð`ð ð`ð 
 ó`ð ò;ó ð;ð  òó ðð òó ðð òó ðó"ó	óó!óó*&óX óDóóóôó5ó$óð ‡[�[óó ñrL   r#   c                  óx   ‡ — e Zd ZeZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Z	 	 d	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zˆ xZS )	ÚRawBatchCommandCursorc           	     óV   •— |j                  d«      rJ ‚t        ‰| �	  |||||||«       y)aL  Create a new cursor / iterator over raw batches of BSON data.

        Should not be called directly by application developers -
        see :meth:`~pymongo.collection.Collection.aggregate_raw_batches`
        instead.

        .. seealso:: The MongoDB documentation on `cursors <https://dochub.mongodb.org/core/cursors>`_.
        r&   N)r-   ÚsuperrK   )	rC   rD   rE   rF   r>   rG   rH   rI   Ú	__class__s	           €rJ   rK   zRawBatchCommandCursor.__init__«  s9   ø€ ð$ —?‘? <Ô0Ð0Ð0Ü‰ÑØØØØØØØõ	
rL   c                óL   — |j                  ||¬«      }|st        |d   «       |S )N)rg   r   )Úraw_responser   )rC   rd   re   rf   rg   rh   rÓ   s          rJ   ri   z&RawBatchCommandCursor._unpack_responseÈ  s0   € ð  ×,Ñ,¨YÀKÐ,ÓPˆÙô 3°<À±?ÔCØÐrL   c                ó   — t        d«      ‚)Nz0Cannot call __getitem__ on RawBatchCommandCursor)r   )rC   Úindexs     rJ   Ú__getitem__z!RawBatchCommandCursor.__getitem__×  s   € ÜÐQÓRÐRrL   r»   r¼   r{   )rd   rÄ   re   r¾   rf   zCodecOptions[dict[str, Any]]rg   rÃ   rh   rk   rÀ   zlist[Mapping[str, Any]])rÕ   r@   rÀ   r
   )	rÇ   rÈ   rÉ   r   r�   rK   ri   rÖ   Ú__classcell__)rÑ   s   @rJ   rÎ   rÎ   ¨  s·   ø„ Ø%€Nð Ø+/Ø+/Øð
à-ð
ð 'ð
ð $ð	
ð
 ð
ð )ð
ð )ð
ð ð
ð 
õ
ðD 48Ø %ðà)ðð !ðð 4ð	ð
 1ðð ðð 
!ó÷SrL   rÎ   N)1rÊ   Ú
__future__r   Úcollectionsr   Útypingr   r   r   r   r	   r
   r   r   r   Úbsonr   r   Úpymongor   Úpymongo.cursor_sharedr   Úpymongo.errorsr   r   r   Úpymongo.messager   r   r   r   r   Úpymongo.responser   Úpymongo.synchronous.cursorr   Úpymongo.typingsr   r   r   Ú"pymongo.synchronous.client_sessionr   Úpymongo.synchronous.collectionr    Úpymongo.synchronous.poolr!   Ú_IS_SYNCr#   rÎ   r–   rL   rJ   ú<module>rç      s�   ðñ ;Ý "å ÷
÷ 
õ 
÷ FÝ Ý 7ß PÑ P÷õ õ ,Ý 9ß AÑ AáÝ@Ý9Ý3à€ôo�G˜MÑ*ô oôd0S˜M¨-Ñ8õ 0SrL   