3
OÉ6bŠ  ã               @   st   d Z ddlm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.é    )ÚInvalidOperationc               @   s0   e Zd ZdZd
Zdd„ Zdd„ Zedd„ ƒZd	S )Ú_WriteResultz$Base class for write result classes.Ú__acknowledgedc             C   s
   || _ d S )N)Ú_WriteResult__acknowledged)ÚselfÚacknowledged© r   úN/var/www/html/sandeepIITI/myenv/lib/python3.6/site-packages/pymongo/results.pyÚ__init__   s    z_WriteResult.__init__c             C   s   | j std|f ƒ‚dS )z8Raise an exception on property access if unacknowledged.zwA value for %s is not available when the write is unacknowledged. Check the acknowledged attribute to avoid this error.N)r   r   )r   Zproperty_namer   r   r	   Ú_raise_if_unacknowledged   s    z%_WriteResult._raise_if_unacknowledgedc             C   s   | j S )aB  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
          attibutes 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   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r
   r   Úpropertyr   r   r   r   r	   r      s
   r   c                   s0   e Zd ZdZdZ‡ fdd„Zedd„ ƒZ‡  ZS )	ÚInsertOneResultzKThe return type for :meth:`~pymongo.collection.Collection.insert_one`.
    Ú__inserted_idr   c                s   || _ tt| ƒj|ƒ d S )N)Ú_InsertOneResult__inserted_idÚsuperr   r
   )r   Úinserted_idr   )Ú	__class__r   r	   r
   >   s    zInsertOneResult.__init__c             C   s   | j S )zThe inserted document's _id.)r   )r   r   r   r	   r   B   s    zInsertOneResult.inserted_id)r   r   )	r   r   r   r   r   r
   r   r   Ú__classcell__r   r   )r   r	   r   8   s   r   c                   s0   e Zd ZdZdZ‡ fdd„Zedd„ ƒZ‡  ZS )	ÚInsertManyResultzLThe return type for :meth:`~pymongo.collection.Collection.insert_many`.
    Ú__inserted_idsr   c                s   || _ tt| ƒj|ƒ d S )N)Ú_InsertManyResult__inserted_idsr   r   r
   )r   Úinserted_idsr   )r   r   r	   r
   N   s    zInsertManyResult.__init__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   R   s    	zInsertManyResult.inserted_ids)r   r   )	r   r   r   r   r   r
   r   r   r   r   r   )r   r	   r   H   s   r   c                   sT   e Zd ZdZdZ‡ fdd„Zedd„ ƒZedd	„ ƒZed
d„ ƒZ	e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`.
    Ú__raw_resultr   c                s   || _ tt| ƒj|ƒ d S )N)Ú_UpdateResult__raw_resultr   r   r
   )r   Ú
raw_resultr   )r   r   r	   r
   f   s    zUpdateResult.__init__c             C   s   | j S )z/The raw result document returned by the server.)r   )r   r   r   r	   r    j   s    zUpdateResult.raw_resultc             C   s&   | j dƒ | jdk	rdS | jjddƒS )z0The number of documents matched for this update.Úmatched_countNr   Ún)r   Úupserted_idr   Úget)r   r   r   r	   r!   o   s    

zUpdateResult.matched_countc             C   s   | j dƒ | jjdƒS )a  The number of documents modified.

        .. note:: modified_count is only reported by MongoDB 2.6 and later.
          When connected to an earlier server version, or in certain mixed
          version sharding configurations, this attribute will be set to
          ``None``.
        Úmodified_countÚ	nModified)r   r   r$   )r   r   r   r	   r%   w   s    	
zUpdateResult.modified_countc             C   s   | j dƒ | jjdƒS )z^The _id of the inserted document if an upsert took place. Otherwise
        ``None``.
        r#   Úupserted)r   r   r$   )r   r   r   r	   r#   ƒ   s    
zUpdateResult.upserted_id)r   r   )r   r   r   r   r   r
   r   r    r!   r%   r#   r   r   r   )r   r	   r   ^   s   r   c                   s<   e Zd ZdZd
Z‡ fdd„Zedd„ ƒZedd	„ ƒZ‡  Z	S )ÚDeleteResultz€The return type for :meth:`~pymongo.collection.Collection.delete_one`
    and :meth:`~pymongo.collection.Collection.delete_many`r   r   c                s   || _ tt| ƒj|ƒ d S )N)Ú_DeleteResult__raw_resultr   r(   r
   )r   r    r   )r   r   r	   r
   ’   s    zDeleteResult.__init__c             C   s   | j S )z/The raw result document returned by the server.)r)   )r   r   r   r	   r    –   s    zDeleteResult.raw_resultc             C   s   | j dƒ | jjddƒS )z The number of documents deleted.Údeleted_countr"   r   )r   r)   r$   )r   r   r   r	   r*   ›   s    
zDeleteResult.deleted_count)r   r   )
r   r   r   r   r   r
   r   r    r*   r   r   r   )r   r	   r(   Œ   s
   r(   c                   sx   e Zd ZdZdZ‡ fdd„Zedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZ‡  ZS )ÚBulkWriteResultz-An object wrapper for bulk API write results.Ú__bulk_api_resultr   c                s   || _ tt| ƒj|ƒ 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   Úbulk_api_resultr   )r   r   r	   r
   §   s    	zBulkWriteResult.__init__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   | j dƒ | jjdƒS )z!The number of documents inserted.Úinserted_countZ	nInserted)r   r-   r$   )r   r   r   r	   r/   ¸   s    
zBulkWriteResult.inserted_countc             C   s   | j dƒ | jjdƒS )z.The number of documents matched for an update.r!   ZnMatched)r   r-   r$   )r   r   r   r	   r!   ¾   s    
zBulkWriteResult.matched_countc             C   s   | j dƒ | jjdƒS )a  The number of documents modified.

        .. note:: modified_count is only reported by MongoDB 2.6 and later.
          When connected to an earlier server version, or in certain mixed
          version sharding configurations, this attribute will be set to
          ``None``.
        r%   r&   )r   r-   r$   )r   r   r   r	   r%   Ä   s    	
zBulkWriteResult.modified_countc             C   s   | j dƒ | jjdƒS )z The number of documents deleted.r*   ZnRemoved)r   r-   r$   )r   r   r   r	   r*   Ð   s    
zBulkWriteResult.deleted_countc             C   s   | j dƒ | jjdƒS )z!The number of documents upserted.Úupserted_countZ	nUpserted)r   r-   r$   )r   r   r   r	   r0   Ö   s    
zBulkWriteResult.upserted_countc             C   s,   | j dƒ | jr(t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   | ]}|d  |d fV  qdS )ÚindexÚ_idNr   )Ú.0Zupsertr   r   r	   ú	<genexpr>á   s   z/BulkWriteResult.upserted_ids.<locals>.<genexpr>r'   N)r   r-   Údictr.   )r   r   r   r	   r1   Ü   s    
zBulkWriteResult.upserted_ids)r,   r   )r   r   r   r   r   r
   r   r.   r/   r!   r%   r*   r0   r1   r   r   r   )r   r	   r+   ¢   s   r+   N)
r   Zpymongo.errorsr   Úobjectr   r   r   r   r(   r+   r   r   r   r	   Ú<module>   s   $.