o
    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.)Z__acknowledgedacknowledgedboolreturnNonec                 C  s
   || _ d S N_WriteResult__acknowledged)selfr
    r   B/var/www/html/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 )InsertOneResultzThe return type for :meth:`~pymongo.collection.Collection.insert_one`
    and as part of :meth:`~pymongo.mongo_client.MongoClient.bulk_write`.
    )Z__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   r/   r
   r   r   r   r   r   N      zInsertOneResult.__repr__c                 C  r"   )zThe inserted document's _id.)r/   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   r1   r   r,   C   s    
r,   c                      r+   )InsertManyResultzGThe return type for :meth:`~pymongo.collection.Collection.insert_many`.)Z__inserted_idsinserted_ids	list[Any]r
   r   r   r   c                   r.   r   )_InsertManyResult__inserted_idsr0   r   )r   r:   r
   r1   r   r   r   ^   r2   zInsertManyResult.__init__r   c                 C  r3   r4   )r   r   r<   r
   r   r   r   r   r   b   r5   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:   r8   r   r   r1   r   r9   Y   s    
r9   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_resultZ__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_bulkr0   r   )r   r?   r
   rA   r1   r   r   r      s   zUpdateResult.__init__r   r   c                 C  r3   r4   )r   r   rB   r
   r   r   r   r   r         zUpdateResult.__repr__c                 C  r"   z/The raw result document returned by the server.rB   r   r   r   r   r?      r6   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    rB   rC   upserted_idgetr   r   r   r   rH      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    rB   r   rG   rK   r   r   r   r   rM      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``.
        rJ   Nupserted_id)r    rB   rC   rK   r   r   r   r   rJ      s
   
zUpdateResult.upserted_idc                 C  s   | j dusJ d| j v S )zEWhether an upsert took place.

        .. versionadded:: 4.9
        NrO   rF   r   r   r   r   
did_upsert   s   
zUpdateResult.did_upsert)F)r?   r@   r
   r   rA   r   r#   )r   r@   r   rG   r7   r%   )r   r&   r'   r(   r)   r   r   r*   r?   rH   rM   rJ   rQ   r8   r   r   r1   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 )DeleteResultzThe 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`.
    )r>   r?   Mapping[str, Any]r
   r   r   r   c                   r.   r   )_DeleteResult__raw_resultr0   r   )r   r?   r
   r1   r   r   r      r2   zDeleteResult.__init__r   c                 C  r3   r4   )r   r   rU   r
   r   r   r   r   r      rD   zDeleteResult.__repr__c                 C  r"   rE   )rU   r   r   r   r   r?      r6   zDeleteResult.raw_resultrG   c                 C  s   |  d | jddS ) The number of documents deleted.deleted_countrI   r   )r    rU   rK   r   r   r   r   rW      s   
zDeleteResult.deleted_count)r?   rT   r
   r   r   r   r#   )r   rT   rR   )r   r&   r'   r(   r)   r   r   r*   r?   rW   r8   r   r   r1   r   rS      s    
rS   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.)Z__bulk_api_resultbulk_api_resultdict[str, Any]r
   r   r   r   c                   r.   r   )%_BulkWriteResultBase__bulk_api_resultr0   r   r   rY   r
   r1   r   r   r      r2   z_BulkWriteResultBase.__init__r   c                 C  r3   r4   )r   r   r[   r
   r   r   r   r   r      rD   z_BulkWriteResultBase.__repr__c                 C  r"   )zThe raw bulk write API result.)r[   r   r   r   r   rY      r6   z$_BulkWriteResultBase.bulk_api_resultrG   c                 C     |  d tt| jdS )z!The number of documents inserted.inserted_countZ	nInsertedr    r   rG   r[   rK   r   r   r   r   r^         
z#_BulkWriteResultBase.inserted_countc                 C  r]   )z.The number of documents matched for an update.rH   ZnMatchedr_   r   r   r   r   rH      r`   z"_BulkWriteResultBase.matched_countc                 C  r]   )rL   rM   rN   r_   r   r   r   r   rM      r`   z#_BulkWriteResultBase.modified_countc                 C  s8   |  d d| jv rtt| jdS tt| jdS )rV   rW   ZnRemovedZnDeleted)r    r[   r   rG   rK   r   r   r   r   rW      s   

z"_BulkWriteResultBase.deleted_countc                 C  r]   )z!The number of documents upserted.upserted_countZ	nUpsertedr_   r   r   r   r   ra      r`   z#_BulkWriteResultBase.upserted_countrY   rZ   r
   r   r   r   r#   )r   rZ   rR   )r   r&   r'   r(   r)   r   r   r*   rY   r^   rH   rM   rW   ra   r8   r   r   r1   r   rX      s"    
rX   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   rY   rZ   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)r0   r   r\   r1   r   r   r   	  s   zBulkWriteResult.__init__r   c                 C  r3   r4   )r   r   rY   r
   r   r   r   r   r     r5   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 )indexrP   r   ).0Zupsertr   r   r   
<dictcomp>  s    z0BulkWriteResult.upserted_ids.<locals>.<dictcomp>rO   N)r    rY   r   r   r   r   re     s   
zBulkWriteResult.upserted_idsrb   r#   )r   rd   )
r   r&   r'   r(   r)   r   r   r*   re   r8   r   r   r1   r   rc     s    

rc   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.)Z__has_verbose_resultsrY   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_resultsr0   r   )r   rY   r
   rk   r1   r   r   r   &  s
   zClientBulkWriteResult.__init__r   c                 C  s   d | jj| j| j| jS )Nz%{}({!r}, acknowledged={}, verbose={}))formatr   r   rY   r
   rk   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)rl   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.)rl   r   r   r   r   rk   N  r6   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_resultsZinsertResults)r    rn   r   r   rG   r,   rY   rK   r   r   r   r   rq   S     



z$ClientBulkWriteResult.insert_resultsMapping[int, UpdateResult]c                 C  rp   )z7A map of successful update operations to their results.update_resultsZupdateResults)r    rn   r   r   rG   r=   rY   rK   r   r   r   r   rt   ]  rr   z$ClientBulkWriteResult.update_resultsMapping[int, DeleteResult]c                 C  rp   )z7A map of successful delete operations to their results.delete_resultsZdeleteResults)r    rn   r   r   rG   rS   rY   rK   r   r   r   r   rv   g  rr   z$ClientBulkWriteResult.delete_results)rY   rj   r
   r   rk   r   r   r   r#   r$   r%   )r   ro   )r   rs   )r   ru   )r   r&   r'   r(   r)   r   r   rn   r*   rk   rq   rt   rv   r8   r   r   r1   r   ri   !  s    

			ri   N)r(   
__future__r   typingr   r   r   r   r   Zpymongo.errorsr   r	   r,   r9   r=   rS   rX   rc   ri   r   r   r   r   <module>   s   )C3