o
    C©ÌhC3  ã                   @  sº   d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
 G dd„ dƒZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )z{Result class definitions.

.. seealso:: This module is compatible with both the synchronous and asynchronous PyMongo APIs.
é    )Úannotations)ÚAnyÚMappingÚMutableMappingÚOptionalÚcast)ÚInvalidOperationc                   @  s@   e Zd ZdZdZddd„Zdd
d„Zddd„Zeddd„ƒZ	dS )Ú_WriteResultz$Base class for write result classes.)Ú__acknowledgedÚacknowledgedÚboolÚreturnÚNonec                 C  s
   || _ d S ©N©Ú_WriteResult__acknowledged)Úselfr   © r   ú^/var/www/html/Moveonwheels/move_on_wheels/venv/lib/python3.10/site-packages/pymongo/results.pyÚ__init__   s   
z_WriteResult.__init__Ústrc                 C  s   | j j› d| j› d�S )Nú(ú))Ú	__class__Ú__name__r   ©r   r   r   r   Ú__repr__"   s   z_WriteResult.__repr__Úproperty_namec                 C  ó   | j std|› d�ƒ‚dS )z8Raise an exception on property access if unacknowledged.úA value for zi is not available when the write is unacknowledged. Check the acknowledged attribute to avoid this error.N)r   r   ©r   r   r   r   r   Ú_raise_if_unacknowledged%   ó
   
ÿÿz%_WriteResult._raise_if_unacknowledgedc                 C  ó   | j S )aC  Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attributes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        r   r   r   r   r   r   /   s   z_WriteResult.acknowledgedN)r   r   r   r   ©r   r   ©r   r   r   r   ©r   r   )
r   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r!   Úpropertyr   r   r   r   r   r	      s    



r	   c                      ó>   e Zd ZdZdZd‡ fd	d
„Zddd„Zeddd„ƒZ‡  Z	S )ÚInsertOneResultz“The return type for :meth:`~pymongo.collection.Collection.insert_one`
    and as part of :meth:`~pymongo.mongo_client.MongoClient.bulk_write`.
    )Ú__inserted_idÚinserted_idr   r   r   r   r   c                   ó   || _ tƒ  |¡ d S r   )Ú_InsertOneResult__inserted_idÚsuperr   )r   r/   r   ©r   r   r   r   J   ó   zInsertOneResult.__init__r   c                 C  ó   | j j› d| j›d| j› d�S ©Nr   z, acknowledged=r   )r   r   r1   r   r   r   r   r   r   N   ó   ÿzInsertOneResult.__repr__c                 C  r#   )zThe inserted document's _id.)r1   r   r   r   r   r/   S   ó   zInsertOneResult.inserted_id)r/   r   r   r   r   r   r$   ©r   r   )
r   r'   r(   r)   r*   r   r   r+   r/   Ú__classcell__r   r   r3   r   r-   C   s    
r-   c                      r,   )ÚInsertManyResultzGThe return type for :meth:`~pymongo.collection.Collection.insert_many`.)Ú__inserted_idsÚinserted_idsú	list[Any]r   r   r   r   c                   r0   r   )Ú_InsertManyResult__inserted_idsr2   r   )r   r=   r   r3   r   r   r   ^   r4   zInsertManyResult.__init__r   c                 C  r5   r6   )r   r   r?   r   r   r   r   r   r   b   r7   zInsertManyResult.__repr__c                 C  r#   )a@  A list of _ids of the inserted documents, in the order provided.

        .. note:: If ``False`` is passed for the `ordered` parameter to
          :meth:`~pymongo.collection.Collection.insert_many` the server
          may have inserted the documents in a different order than what
          is presented here.
        )r?   r   r   r   r   r=   g   s   	zInsertManyResult.inserted_ids)r=   r>   r   r   r   r   r$   )r   r>   )
r   r'   r(   r)   r*   r   r   r+   r=   r:   r   r   r3   r   r;   Y   s    
r;   c                      sz   e Zd ZdZdZ	dd‡ fd	d
„Zddd„Zeddd„ƒZeddd„ƒZ	eddd„ƒZ
ed dd„ƒZed!dd„ƒZ‡  ZS )"ÚUpdateResulta  The return type for :meth:`~pymongo.collection.Collection.update_one`,
    :meth:`~pymongo.collection.Collection.update_many`, and
    :meth:`~pymongo.collection.Collection.replace_one`, and as part of
    :meth:`~pymongo.mongo_client.MongoClient.bulk_write`.
    )Ú__raw_resultÚ__in_client_bulkFÚ
raw_resultúOptional[Mapping[str, Any]]r   r   Úin_client_bulkc                   s   || _ || _tƒ  |¡ d S r   )Ú_UpdateResult__raw_resultÚ_UpdateResult__in_client_bulkr2   r   )r   rC   r   rE   r3   r   r   r      s   zUpdateResult.__init__r   r   c                 C  r5   r6   )r   r   rF   r   r   r   r   r   r   ‰   ó   zUpdateResult.__repr__c                 C  r#   ©z/The raw result document returned by the server.©rF   r   r   r   r   rC   Œ   r8   zUpdateResult.raw_resultÚintc                 C  s:   |   d¡ | jdusJ ‚| js| jdurdS | j dd¡S )z0The number of documents matched for this update.Úmatched_countNr   Ún)r!   rF   rG   Úupserted_idÚgetr   r   r   r   rL   ‘   s
   
zUpdateResult.matched_countc                 C  s*   |   d¡ | jdusJ ‚tt| j d¡ƒS )ú!The number of documents modified.Úmodified_countNÚ	nModified)r!   rF   r   rK   rO   r   r   r   r   rQ   š   s   
zUpdateResult.modified_countr   c                 C  sF   |   d¡ | jdusJ ‚| jr| j d¡r| jd d S | j dd¡S )z^The _id of the inserted document if an upsert took place. Otherwise
        ``None``.
        rN   NÚupsertedÚ_id)r!   rF   rG   rO   r   r   r   r   rN   ¡   s
   
zUpdateResult.upserted_idc                 C  s   | j dusJ ‚d| j v S )zEWhether an upsert took place.

        .. versionadded:: 4.9
        NrS   rJ   r   r   r   r   Ú
did_upsert¬   s   
zUpdateResult.did_upsert)F)rC   rD   r   r   rE   r   r$   )r   rD   ©r   rK   r9   r&   )r   r'   r(   r)   r*   r   r   r+   rC   rL   rQ   rN   rU   r:   r   r   r3   r   r@   s   s     	ü


r@   c                      sL   e Zd ZdZdZd‡ fd	d
„Zddd„Zeddd„ƒZeddd„ƒZ	‡  Z
S )ÚDeleteResultzÎThe return type for :meth:`~pymongo.collection.Collection.delete_one`
    and :meth:`~pymongo.collection.Collection.delete_many`
    and as part of :meth:`~pymongo.mongo_client.MongoClient.bulk_write`.
    )rA   rC   úMapping[str, Any]r   r   r   r   c                   r0   r   )Ú_DeleteResult__raw_resultr2   r   )r   rC   r   r3   r   r   r   ¾   r4   zDeleteResult.__init__r   c                 C  r5   r6   )r   r   rY   r   r   r   r   r   r   Â   rH   zDeleteResult.__repr__c                 C  r#   rI   )rY   r   r   r   r   rC   Å   r8   zDeleteResult.raw_resultrK   c                 C  s   |   d¡ | j dd¡S )ú The number of documents deleted.Údeleted_countrM   r   )r!   rY   rO   r   r   r   r   r[   Ê   s   
zDeleteResult.deleted_count)rC   rX   r   r   r   r   r$   )r   rX   rV   )r   r'   r(   r)   r*   r   r   r+   rC   r[   r:   r   r   r3   r   rW   ¶   s    
rW   c                      s„   e Zd ZdZdZd‡ fd	d
„Zddd„Zeddd„ƒZeddd„ƒZ	eddd„ƒZ
eddd„ƒZeddd„ƒZeddd„ƒZ‡  ZS )Ú_BulkWriteResultBasez.Private base class for bulk write API results.)Ú__bulk_api_resultÚbulk_api_resultúdict[str, Any]r   r   r   r   c                   r0   r   )Ú%_BulkWriteResultBase__bulk_api_resultr2   r   ©r   r^   r   r3   r   r   r   Ö   r4   z_BulkWriteResultBase.__init__r   c                 C  r5   r6   )r   r   r`   r   r   r   r   r   r   Ú   rH   z_BulkWriteResultBase.__repr__c                 C  r#   )zThe raw bulk write API result.)r`   r   r   r   r   r^   Ý   r8   z$_BulkWriteResultBase.bulk_api_resultrK   c                 C  ó   |   d¡ tt| j d¡ƒS )z!The number of documents inserted.Úinserted_countÚ	nInserted©r!   r   rK   r`   rO   r   r   r   r   rc   â   ó   
z#_BulkWriteResultBase.inserted_countc                 C  rb   )z.The number of documents matched for an update.rL   ÚnMatchedre   r   r   r   r   rL   è   rf   z"_BulkWriteResultBase.matched_countc                 C  rb   )rP   rQ   rR   re   r   r   r   r   rQ   î   rf   z#_BulkWriteResultBase.modified_countc                 C  s8   |   d¡ d| jv rtt| j d¡ƒS tt| j d¡ƒS )rZ   r[   ÚnRemovedÚnDeleted)r!   r`   r   rK   rO   r   r   r   r   r[   ô   s   

z"_BulkWriteResultBase.deleted_countc                 C  rb   )z!The number of documents upserted.Úupserted_countÚ	nUpsertedre   r   r   r   r   rj   ý   rf   z#_BulkWriteResultBase.upserted_count©r^   r_   r   r   r   r   r$   )r   r_   rV   )r   r'   r(   r)   r*   r   r   r+   r^   rc   rL   rQ   r[   rj   r:   r   r   r3   r   r\   Ñ   s"    
r\   c                      s>   e Zd ZdZdZd‡ fd	d
„Zddd„Zeddd„ƒZ‡  Z	S )ÚBulkWriteResultz>An object wrapper for collection-level bulk write API results.r   r^   r_   r   r   r   r   c                   s   t ƒ  ||¡ dS )a@  Create a BulkWriteResult instance.

        :param bulk_api_result: A result dict from the collection-level bulk write API
        :param acknowledged: Was this write result acknowledged? If ``False``
            then all properties of this object will raise
            :exc:`~pymongo.errors.InvalidOperation`.
        N)r2   r   ra   r3   r   r   r   	  s   zBulkWriteResult.__init__r   c                 C  r5   r6   )r   r   r^   r   r   r   r   r   r     r7   zBulkWriteResult.__repr__úOptional[dict[int, Any]]c                 C  s(   |   d¡ | jrdd„ | jd D ƒS dS )z=A map of operation index to the _id of the upserted document.Úupserted_idsc                 S  s   i | ]	}|d  |d “qS )ÚindexrT   r   )Ú.0Úupsertr   r   r   Ú
<dictcomp>  s    z0BulkWriteResult.upserted_ids.<locals>.<dictcomp>rS   N)r!   r^   r   r   r   r   ro     s   
zBulkWriteResult.upserted_idsrl   r$   )r   rn   )
r   r'   r(   r)   r*   r   r   r+   ro   r:   r   r   r3   r   rm     s    

rm   c                      sr   e Zd ZdZdZd‡ fd
d„Zddd„Zddd„Zed dd„ƒZ	ed!dd„ƒZ
ed"dd„ƒZed#dd„ƒZ‡  ZS )$ÚClientBulkWriteResultz:An object wrapper for client-level bulk write API results.)Ú__has_verbose_resultsr^   úMutableMapping[str, Any]r   r   Úhas_verbose_resultsr   r   c                   s   || _ tƒ  ||¡ dS )aU  Create a ClientBulkWriteResult instance.

        :param bulk_api_result: A result dict from the client-level bulk write API
        :param acknowledged: Was this write result acknowledged? If ``False``
            then all properties of this object will raise
            :exc:`~pymongo.errors.InvalidOperation`.
        :param has_verbose_results: Should the returned result be verbose?
            If ``False``, then the ``insert_results``, ``update_results``, and
            ``delete_results`` properties of this object will raise
            :exc:`~pymongo.errors.InvalidOperation`.
        N)Ú+_ClientBulkWriteResult__has_verbose_resultsr2   r   )r   r^   r   rw   r3   r   r   r   &  s
   þzClientBulkWriteResult.__init__r   c                 C  s   d  | jj| j| j| j¡S )Nz%{}({!r}, acknowledged={}, verbose={}))Úformatr   r   r^   r   rw   r   r   r   r   r   =  s   üzClientBulkWriteResult.__repr__r   c                 C  r   )zARaise an exception on property access if verbose results are off.r   zv is not available when the results are not set to be verbose. Check the verbose_results attribute to avoid this error.N)rx   r   r    r   r   r   Ú_raise_if_not_verboseE  r"   z+ClientBulkWriteResult._raise_if_not_verbosec                 C  r#   )z/Whether the returned results should be verbose.)rx   r   r   r   r   rw   N  r8   z)ClientBulkWriteResult.has_verbose_resultsúMapping[int, InsertOneResult]c                 C  ó.   |   d¡ |  d¡ ttttf | j d¡ƒS )z:A map of successful insertion operations to their results.Úinsert_resultsÚinsertResults)r!   rz   r   r   rK   r-   r^   rO   r   r   r   r   r}   S  ó   



þz$ClientBulkWriteResult.insert_resultsúMapping[int, UpdateResult]c                 C  r|   )z7A map of successful update operations to their results.Úupdate_resultsÚupdateResults)r!   rz   r   r   rK   r@   r^   rO   r   r   r   r   r�   ]  r   z$ClientBulkWriteResult.update_resultsúMapping[int, DeleteResult]c                 C  r|   )z7A map of successful delete operations to their results.Údelete_resultsÚdeleteResults)r!   rz   r   r   rK   rW   r^   rO   r   r   r   r   r„   g  r   z$ClientBulkWriteResult.delete_results)r^   rv   r   r   rw   r   r   r   r$   r%   r&   )r   r{   )r   r€   )r   rƒ   )r   r'   r(   r)   r*   r   r   rz   r+   rw   r}   r�   r„   r:   r   r   r3   r   rt   !  s    

			rt   N)r)   Ú
__future__r   Útypingr   r   r   r   r   Úpymongo.errorsr   r	   r-   r;   r@   rW   r\   rm   rt   r   r   r   r   Ú<module>   s   )C3