U
    ð¤ùd  ã                   @   s’   d Z ddlmZ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dS )zResult class definitions.é    )ÚAnyÚDictÚListÚMappingÚOptionalÚcast)ÚInvalidOperationc                   @   sF   e Zd ZdZdZeddœdd„Zeddœdd	„Ze	ed
œdd„ƒZ
dS )Ú_WriteResultz$Base class for write result classes.)Z__acknowledgedN)ÚacknowledgedÚreturnc                 C   s
   || _ d S ©N©Ú_WriteResult__acknowledged)Úselfr
   © r   ú3/tmp/pip-unpacked-wheel-oblwsawz/pymongo/results.pyÚ__init__   s    z_WriteResult.__init__)Úproperty_namer   c                 C   s   | j std |¡ƒ‚dS )z8Raise an exception on property access if unacknowledged.zwA value for {} is not available when the write is unacknowledged. Check the acknowledged attribute to avoid this error.N)r   r   Úformat)r   r   r   r   r   Ú_raise_if_unacknowledged   s    ýÿz%_WriteResult._raise_if_unacknowledged©r   c                 C   s   | 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.acknowledged)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__Úboolr   Ústrr   Úpropertyr
   r   r   r   r   r	      s   
r	   c                       s@   e Zd ZdZdZeeddœ‡ fdd„Zeedœdd	„ƒZ	‡  Z
S )
ÚInsertOneResultzFThe return type for :meth:`~pymongo.collection.Collection.insert_one`.)Z__inserted_idN)Úinserted_idr
   r   c                    s   || _ tƒ  |¡ d S r   )Ú_InsertOneResult__inserted_idÚsuperr   )r   r!   r
   ©Ú	__class__r   r   r   @   s    zInsertOneResult.__init__r   c                 C   s   | j S )zThe inserted document's _id.)r"   r   r   r   r   r!   D   s    zInsertOneResult.inserted_id)r   r   r   r   r   r   r   r   r   r!   Ú__classcell__r   r   r$   r   r    ;   s
   r    c                       sD   e Zd ZdZdZee eddœ‡ fdd„Ze	edœdd	„ƒZ
‡  ZS )
ÚInsertManyResultzGThe return type for :meth:`~pymongo.collection.Collection.insert_many`.)Z__inserted_idsN)Úinserted_idsr
   r   c                    s   || _ tƒ  |¡ d S r   )Ú_InsertManyResult__inserted_idsr#   r   )r   r(   r
   r$   r   r   r   O   s    zInsertManyResult.__init__r   c                 C   s   | j S )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(   S   s    	zInsertManyResult.inserted_ids)r   r   r   r   r   r   r   r   r   r   r(   r&   r   r   r$   r   r'   J   s
   r'   c                       sŒ   e Zd ZdZdZeeeef  e	dœ‡ fdd„Z
eeeeef  dœdd„ƒZeedœd	d
„ƒZeedœdd„ƒZeedœdd„ƒZ‡  ZS )ÚUpdateResultz¿The return type for :meth:`~pymongo.collection.Collection.update_one`,
    :meth:`~pymongo.collection.Collection.update_many`, and
    :meth:`~pymongo.collection.Collection.replace_one`.
    ©Z__raw_result)Ú
raw_resultr
   c                    s   || _ tƒ  |¡ d S r   )Ú_UpdateResult__raw_resultr#   r   ©r   r,   r
   r$   r   r   r   g   s    zUpdateResult.__init__r   c                 C   s   | j S ©z/The raw result document returned by the server.)r-   r   r   r   r   r,   k   s    zUpdateResult.raw_resultc                 C   s4   |   d¡ | jdk	rdS | jdk	s&t‚| j dd¡S )z0The number of documents matched for this update.Úmatched_countNr   Ún)r   Úupserted_idr-   ÚAssertionErrorÚgetr   r   r   r   r0   p   s
    

zUpdateResult.matched_countc                 C   s*   |   d¡ | jdk	st‚tt| j d¡ƒS )ú!The number of documents modified.Úmodified_countNÚ	nModified)r   r-   r3   r   Úintr4   r   r   r   r   r6   y   s    
zUpdateResult.modified_countc                 C   s$   |   d¡ | jdk	st‚| j d¡S )z^The _id of the inserted document if an upsert took place. Otherwise
        ``None``.
        r2   NÚupserted)r   r-   r3   r4   r   r   r   r   r2   €   s    
zUpdateResult.upserted_id)r   r   r   r   r   r   r   r   r   r   r   r   r,   r8   r0   r6   r2   r&   r   r   r$   r   r*   _   s    r*   c                       sb   e Zd ZdZdZeeef eddœ‡ fdd„Z	e
eeef dœdd	„ƒZe
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`
    r+   N)r,   r
   r   c                    s   || _ tƒ  |¡ d S r   )Ú_DeleteResult__raw_resultr#   r   r.   r$   r   r   r   ‘   s    zDeleteResult.__init__r   c                 C   s   | j S r/   )r;   r   r   r   r   r,   •   s    zDeleteResult.raw_resultc                 C   s   |   d¡ | j dd¡S )ú The number of documents deleted.Údeleted_countr1   r   )r   r;   r4   r   r   r   r   r=   š   s    
zDeleteResult.deleted_count)r   r   r   r   r   r   r   r   r   r   r   r,   r8   r=   r&   r   r   r$   r   r:   Š   s   r:   c                       sÈ   e Zd ZdZdZeeef eddœ‡ fdd„Z	e
eeef dœdd	„ƒZe
edœd
d„ƒZe
edœdd„ƒZe
edœdd„ƒZe
edœdd„ƒZe
edœdd„ƒZe
eeeef  dœdd„ƒZ‡  ZS )ÚBulkWriteResultz-An object wrapper for bulk API write results.)Z__bulk_api_resultN)Úbulk_api_resultr
   r   c                    s   || _ tƒ  |¡ dS )a<  Create a BulkWriteResult instance.

        :Parameters:
          - `bulk_api_result`: A result dict from the bulk API
          - `acknowledged`: Was this write result acknowledged? If ``False``
            then all properties of this object will raise
            :exc:`~pymongo.errors.InvalidOperation`.
        N)Ú!_BulkWriteResult__bulk_api_resultr#   r   )r   r?   r
   r$   r   r   r   ¦   s    	zBulkWriteResult.__init__r   c                 C   s   | j S )zThe raw bulk API result.)r@   r   r   r   r   r?   ²   s    zBulkWriteResult.bulk_api_resultc                 C   s   |   d¡ tt| j d¡ƒS )z!The number of documents inserted.Úinserted_countZ	nInserted©r   r   r8   r@   r4   r   r   r   r   rA   ·   s    
zBulkWriteResult.inserted_countc                 C   s   |   d¡ tt| j d¡ƒS )z.The number of documents matched for an update.r0   ZnMatchedrB   r   r   r   r   r0   ½   s    
zBulkWriteResult.matched_countc                 C   s   |   d¡ tt| j d¡ƒS )r5   r6   r7   rB   r   r   r   r   r6   Ã   s    
zBulkWriteResult.modified_countc                 C   s   |   d¡ tt| j d¡ƒS )r<   r=   ZnRemovedrB   r   r   r   r   r=   É   s    
zBulkWriteResult.deleted_countc                 C   s   |   d¡ tt| j d¡ƒS )z!The number of documents upserted.Úupserted_countZ	nUpsertedrB   r   r   r   r   rC   Ï   s    
zBulkWriteResult.upserted_countc                 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 )ÚindexZ_idr   )Ú.0Zupsertr   r   r   Ú
<dictcomp>Ú   s      z0BulkWriteResult.upserted_ids.<locals>.<dictcomp>r9   N)r   r@   r?   r   r   r   r   rD   Õ   s    
zBulkWriteResult.upserted_ids)r   r   r   r   r   r   r   r   r   r   r   r?   r8   rA   r0   r6   r=   rC   r   rD   r&   r   r   r$   r   r>   ¡   s"   r>   N)r   Útypingr   r   r   r   r   r   Zpymongo.errorsr   r	   r    r'   r*   r:   r>   r   r   r   r   Ú<module>   s    &+