o
    Åîï]‘6  ã                   @   s¼   d Z ddlmZmZmZ ddlmZ ddlmZm	Z	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G dd„ deƒZG dd„ deƒZdS )zOperation class definitions.é    )Úvalidate_booleanÚvalidate_is_mappingÚvalidate_list)Úvalidate_collation_or_none)Ú_gen_index_nameÚ_index_documentÚ_index_listc                   @   s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )Ú	InsertOnez#Represents an insert_one operation.©Ú_docc                 C   s
   || _ dS )züCreate an InsertOne instance.

        For use with :meth:`~pymongo.collection.Collection.bulk_write`.

        :Parameters:
          - `document`: The document to insert. If the document is missing an
            _id field one will be added.
        Nr
   )ÚselfÚdocument© r   úD/var/www/html/env/lib/python3.10/site-packages/pymongo/operations.pyÚ__init__   s   
	zInsertOne.__init__c                 C   s   |  | j¡ dS )ú3Add this operation to the _Bulk instance `bulkobj`.N)Ú
add_insertr   ©r   Úbulkobjr   r   r   Ú_add_to_bulk&   s   zInsertOne._add_to_bulkc                 C   s   d| j f S )NzInsertOne(%r)r
   ©r   r   r   r   Ú__repr__*   s   zInsertOne.__repr__c                 C   s    t |ƒt | ƒkr|j| jkS tS ©N)Útyper   ÚNotImplemented©r   Úotherr   r   r   Ú__eq__-   s   zInsertOne.__eq__c                 C   ó
   | |k S r   r   r   r   r   r   Ú__ne__2   ó   
zInsertOne.__ne__N©
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   r   r   r   r   r   r	      s    r	   c                   @   ó>   e Zd ZdZdZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )Ú	DeleteOnez"Represents a delete_one operation.©Ú_filterÚ
_collationNc                 C   ó"   |dur	t d|ƒ || _|| _dS )a»  Create a DeleteOne instance.

        For use with :meth:`~pymongo.collection.Collection.bulk_write`.

        :Parameters:
          - `filter`: A query that matches the document to delete.
          - `collation` (optional): An instance of
            :class:`~pymongo.collation.Collation`. This option is only
            supported on MongoDB 3.4 and above.

        .. versionchanged:: 3.5
           Added the `collation` option.
        NÚfilter©r   r*   r+   ©r   r-   Ú	collationr   r   r   r   ;   ó   

zDeleteOne.__init__c                 C   ó   |j | jd| jd� dS )r   é   ©r0   N©Ú
add_deleter*   r+   r   r   r   r   r   N   ó   zDeleteOne._add_to_bulkc                 C   ó   d| j | jf S )NzDeleteOne(%r, %r)r)   r   r   r   r   r   R   ó   zDeleteOne.__repr__c                 C   ó,   t |ƒt | ƒkr|j|jf| j| jfkS tS r   ©r   r*   r+   r   r   r   r   r   r   U   ó
   

ÿzDeleteOne.__eq__c                 C   r   r   r   r   r   r   r   r   [   r    zDeleteOne.__ne__r   r!   r   r   r   r   r(   6   ó    
r(   c                   @   r'   )Ú
DeleteManyz#Represents a delete_many operation.r)   Nc                 C   r,   )a½  Create a DeleteMany instance.

        For use with :meth:`~pymongo.collection.Collection.bulk_write`.

        :Parameters:
          - `filter`: A query that matches the documents to delete.
          - `collation` (optional): An instance of
            :class:`~pymongo.collation.Collation`. This option is only
            supported on MongoDB 3.4 and above.

        .. versionchanged:: 3.5
           Added the `collation` option.
        Nr-   r.   r/   r   r   r   r   d   r1   zDeleteMany.__init__c                 C   r2   )r   r   r4   Nr5   r   r   r   r   r   w   r7   zDeleteMany._add_to_bulkc                 C   r8   )NzDeleteMany(%r, %r)r)   r   r   r   r   r   {   r9   zDeleteMany.__repr__c                 C   r:   r   r;   r   r   r   r   r   ~   r<   zDeleteMany.__eq__c                 C   r   r   r   r   r   r   r   r   „   r    zDeleteMany.__ne__r   r!   r   r   r   r   r>   _   r=   r>   c                   @   s>   e Zd ZdZdZddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )Ú
ReplaceOnez#Represents a replace_one operation.)r*   r   Ú_upsertr+   FNc                 C   s@   |dur	t d|ƒ |durtd|ƒ || _|| _|| _|| _dS )aX  Create a ReplaceOne instance.

        For use with :meth:`~pymongo.collection.Collection.bulk_write`.

        :Parameters:
          - `filter`: A query that matches the document to replace.
          - `replacement`: The new document.
          - `upsert` (optional): If ``True``, perform an insert if no documents
            match the filter.
          - `collation` (optional): An instance of
            :class:`~pymongo.collation.Collation`. This option is only
            supported on MongoDB 3.4 and above.

        .. versionchanged:: 3.5
           Added the `collation` option.
        Nr-   Úupsert)r   r   r*   r   r@   r+   )r   r-   ÚreplacementrA   r0   r   r   r   r   �   s   


zReplaceOne.__init__c                 C   s   |j | j| j| j| jd� dS )r   r4   N)Úadd_replacer*   r   r@   r+   r   r   r   r   r   §   s   
ÿzReplaceOne._add_to_bulkc                 C   s<   t |ƒt | ƒkr|j|j|j|jf| j| j| j| jfkS tS r   )r   r*   r   r@   r+   r   r   r   r   r   r   ¬   s   ÿÿzReplaceOne.__eq__c                 C   r   r   r   r   r   r   r   r   ³   r    zReplaceOne.__ne__c                 C   s   d| j j| j| j| j| jf S )Nz%s(%r, %r, %r, %r))Ú	__class__r"   r*   r   r@   r+   r   r   r   r   r   ¶   s   þzReplaceOne.__repr__)FN)
r"   r#   r$   r%   r&   r   r   r   r   r   r   r   r   r   r?   ˆ   s    
r?   c                   @   s4   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú	_UpdateOpz)Private base class for update operations.)r*   r   r@   r+   Ú_array_filtersc                 C   sX   |d ur	t d|ƒ |d urtd|ƒ |d urtd|ƒ || _|| _|| _|| _|| _d S )Nr-   rA   Úarray_filters)r   r   r   r*   r   r@   r+   rF   )r   r-   ÚdocrA   r0   rG   r   r   r   r   Á   s   



z_UpdateOp.__init__c                 C   sD   t |ƒt | ƒkr |j|j|j|j|jf| j| j| j| j| jfkS tS r   )r   r*   r   r@   r+   rF   r   r   r   r   r   r   Î   s   ÿÿþÿz_UpdateOp.__eq__c                 C   r   r   r   r   r   r   r   r   ×   r    z_UpdateOp.__ne__c                 C   s"   d| j j| j| j| j| j| jf S )Nz%s(%r, %r, %r, %r, %r))rD   r"   r*   r   r@   r+   rF   r   r   r   r   r   Ú   s   þz_UpdateOp.__repr__N)	r"   r#   r$   r%   r&   r   r   r   r   r   r   r   r   rE   ¼   s    	rE   c                       ó2   e Zd ZdZdZ		d	‡ fdd„	Zdd„ Z‡  ZS )
Ú	UpdateOnez#Represents an update_one operation.r   FNc                    ó   t t| ƒ |||||¡ dS )a§  Represents an update_one operation.

        For use with :meth:`~pymongo.collection.Collection.bulk_write`.

        :Parameters:
          - `filter`: A query that matches the document to update.
          - `update`: The modifications to apply.
          - `upsert` (optional): If ``True``, perform an insert if no documents
            match the filter.
          - `collation` (optional): An instance of
            :class:`~pymongo.collation.Collation`. This option is only
            supported on MongoDB 3.4 and above.
          - `array_filters` (optional): A list of filters specifying which
            array elements an update should apply. Requires MongoDB 3.6+.

        .. versionchanged:: 3.9
           Added the ability to accept a pipeline as the `update`.
        .. versionchanged:: 3.6
           Added the `array_filters` option.
        .. versionchanged:: 3.5
           Added the `collation` option.
        N)ÚsuperrJ   r   ©r   r-   ÚupdaterA   r0   rG   ©rD   r   r   r   å   ó   ÿzUpdateOne.__init__c                 C   ó$   |j | j| jd| j| j| jd� dS )r   F©r0   rG   N©Ú
add_updater*   r   r@   r+   rF   r   r   r   r   r      ó   
þzUpdateOne._add_to_bulk©FNN©r"   r#   r$   r%   r&   r   r   Ú__classcell__r   r   rO   r   rJ   à   ó    ÿrJ   c                       rI   )
Ú
UpdateManyz$Represents an update_many operation.r   FNc                    rK   )a£  Create an UpdateMany instance.

        For use with :meth:`~pymongo.collection.Collection.bulk_write`.

        :Parameters:
          - `filter`: A query that matches the documents to update.
          - `update`: The modifications to apply.
          - `upsert` (optional): If ``True``, perform an insert if no documents
            match the filter.
          - `collation` (optional): An instance of
            :class:`~pymongo.collation.Collation`. This option is only
            supported on MongoDB 3.4 and above.
          - `array_filters` (optional): A list of filters specifying which
            array elements an update should apply. Requires MongoDB 3.6+.

        .. versionchanged:: 3.9
           Added the ability to accept a pipeline as the `update`.
        .. versionchanged:: 3.6
           Added the `array_filters` option.
        .. versionchanged:: 3.5
           Added the `collation` option.
        N)rL   rZ   r   rM   rO   r   r   r     rP   zUpdateMany.__init__c                 C   rQ   )r   TrR   NrS   r   r   r   r   r   '  rU   zUpdateMany._add_to_bulkrV   rW   r   r   rO   r   rZ     rY   rZ   c                   @   s(   e Zd ZdZdZdd„ Zedd„ ƒZdS )Ú
IndexModelzRepresents an index to create.)Ú
__documentc                 K   sX   t |ƒ}d|vrt|ƒ|d< t|ƒ|d< t| dd¡ƒ}|| _|dur*|| jd< dS dS )a£
  Create an Index instance.

        For use with :meth:`~pymongo.collection.Collection.create_indexes`.

        Takes either a single key or a list of (key, direction) pairs.
        The key(s) must be an instance of :class:`basestring`
        (:class:`str` in python 3), and the direction(s) must be one of
        (:data:`~pymongo.ASCENDING`, :data:`~pymongo.DESCENDING`,
        :data:`~pymongo.GEO2D`, :data:`~pymongo.GEOHAYSTACK`,
        :data:`~pymongo.GEOSPHERE`, :data:`~pymongo.HASHED`,
        :data:`~pymongo.TEXT`).

        Valid options include, but are not limited to:

          - `name`: custom name to use for this index - if none is
            given, a name will be generated.
          - `unique`: if ``True`` creates a uniqueness constraint on the index.
          - `background`: if ``True`` this index should be created in the
            background.
          - `sparse`: if ``True``, omit from the index any documents that lack
            the indexed field.
          - `bucketSize`: for use with geoHaystack indexes.
            Number of documents to group together within a certain proximity
            to a given longitude and latitude.
          - `min`: minimum value for keys in a :data:`~pymongo.GEO2D`
            index.
          - `max`: maximum value for keys in a :data:`~pymongo.GEO2D`
            index.
          - `expireAfterSeconds`: <int> Used to create an expiring (TTL)
            collection. MongoDB will automatically delete documents from
            this collection after <int> seconds. The indexed field must
            be a UTC datetime or the data will not expire.
          - `partialFilterExpression`: A document that specifies a filter for
            a partial index. Requires server version >= 3.2.
          - `collation`: An instance of :class:`~pymongo.collation.Collation`
            that specifies the collation to use in MongoDB >= 3.4.
          - `wildcardProjection`: Allows users to include or exclude specific
            field paths from a `wildcard index`_ using the { "$**" : 1} key
            pattern. Requires server version >= 4.2.

        See the MongoDB documentation for a full list of supported options by
        server version.

        :Parameters:
          - `keys`: a single key or a list of (key, direction)
            pairs specifying the index to create
          - `**kwargs` (optional): any additional index creation
            options (see the above list) should be passed as keyword
            arguments

        .. versionchanged:: 3.2
            Added partialFilterExpression to support partial indexes.

        .. _wildcard index: https://docs.mongodb.com/master/core/index-wildcard/#wildcard-index-core
        ÚnameÚkeyr0   N)r   r   r   r   ÚpopÚ_IndexModel__document)r   ÚkeysÚkwargsr0   r   r   r   r   3  s   8ÿzIndexModel.__init__c                 C   s   | j S )zUAn index document suitable for passing to the createIndexes
        command.
        )r`   r   r   r   r   r   t  s   zIndexModel.documentN)r"   r#   r$   r%   r&   r   Úpropertyr   r   r   r   r   r[   .  s    Ar[   N)r%   Úpymongo.commonr   r   r   Úpymongo.collationr   Úpymongo.helpersr   r   r   Úobjectr	   r(   r>   r?   rE   rJ   rZ   r[   r   r   r   r   Ú<module>   s    ))4$''