
    hrD                        d Z ddlmZ ddlm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e      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)zOperation class definitions.    )string_type)helpers)validate_booleanvalidate_is_mappingvalidate_list)validate_collation_or_none)_gen_index_name_index_document_index_listc                   2    e Zd ZdZdZd Zd Zd Zd Zd Z	y)		InsertOnez#Represents an insert_one operation._docc                     || _         y)zCreate 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documents     U/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/pymongo/operations.py__init__zInsertOne.__init__   s     	    c                 :    |j                  | j                         y)3Add this operation to the _Bulk instance `bulkobj`.N)
add_insertr   r   bulkobjs     r   _add_to_bulkzInsertOne._add_to_bulk)   s    499%r   c                 "    d| j                   dS )Nz
InsertOne()r   r   s    r   __repr__zInsertOne.__repr__-   s    "&))--r   c                 n    t        |      t        |       k(  r|j                  | j                  k(  S t        S N)typer   NotImplementedr   others     r   __eq__zInsertOne.__eq__0   s+    ;$t*$::**r   c                     | |k(   S r!    r$   s     r   __ne__zInsertOne.__ne__5       5=  r   N
__name__
__module____qualname____doc__	__slots__r   r   r   r&   r)   r(   r   r   r   r      s#    -I	&.
!r   r   c                   4    e Zd ZdZdZd	dZd Zd Zd Zd Z	y)
	DeleteOnez"Represents a delete_one operation._filter
_collation_hintNc                     |t        d|       |%t        |t              st        j                  |      }|| _        || _        || _        y)ac  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.
          - `hint` (optional): An index to use to support the query
            predicate specified either by its string name, or in the same
            format as passed to
            :meth:`~pymongo.collection.Collection.create_index` (e.g.
            ``[('field', ASCENDING)]``). This option is only supported on
            MongoDB 4.4 and above.

        .. versionchanged:: 3.11
           Added the ``hint`` option.
        .. versionchanged:: 3.5
           Added the `collation` option.
        Nfilterr   
isinstancer   r   r
   r4   r5   r6   r   r8   	collationhints       r   r   zDeleteOne.__init__>   I    , &1dK0..t4#
r   c                 j    |j                  | j                  d| j                  | j                         y)r      r<   r=   N
add_deleter4   r5   r6   r   s     r   r   zDeleteOne._add_to_bulk]   *    4<<doo $

 	 	,r   c                 <    d| j                   d| j                  dS )Nz
DeleteOne(, r   r4   r5   r   s    r   r   zDeleteOne.__repr__b   s    &*llDOODDr   c                     t        |      t        |       k(  r1|j                  |j                  f| j                  | j                  fk(  S t        S r!   r"   r4   r5   r#   r$   s     r   r&   zDeleteOne.__eq__e   D    ;$t*$]]E$4$45\\4??34 5r   c                     | |k(   S r!   r(   r$   s     r   r)   zDeleteOne.__ne__k   r*   r   NNr+   r(   r   r   r2   r2   9   s$    ,2I>,
E!r   r2   c                   4    e Zd ZdZdZd	dZd Zd Zd Zd Z	y)

DeleteManyz#Represents a delete_many operation.r3   Nc                     |t        d|       |%t        |t              st        j                  |      }|| _        || _        || _        y)ae  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.
          - `hint` (optional): An index to use to support the query
            predicate specified either by its string name, or in the same
            format as passed to
            :meth:`~pymongo.collection.Collection.create_index` (e.g.
            ``[('field', ASCENDING)]``). This option is only supported on
            MongoDB 4.4 and above.

        .. versionchanged:: 3.11
           Added the ``hint`` option.
        .. versionchanged:: 3.5
           Added the `collation` option.
        Nr8   r9   r;   s       r   r   zDeleteMany.__init__t   r>   r   c                 j    |j                  | j                  d| j                  | j                         y)r   r   rA   NrB   r   s     r   r   zDeleteMany._add_to_bulk   rD   r   c                 <    d| j                   d| j                  dS )NzDeleteMany(rF   r   rG   r   s    r   r   zDeleteMany.__repr__   s    '+||T__EEr   c                     t        |      t        |       k(  r1|j                  |j                  f| j                  | j                  fk(  S t        S r!   rI   r$   s     r   r&   zDeleteMany.__eq__   rJ   r   c                     | |k(   S r!   r(   r$   s     r   r)   zDeleteMany.__ne__   r*   r   rL   r+   r(   r   r   rN   rN   o   s$    -2I>,
F!r   rN   c                   8    e Zd ZdZdZ	 	 d	dZd Zd Zd Zd Z	y)

ReplaceOnez#Represents a replace_one operation.)r4   r   _upsertr5   r6   Nc                     |t        d|       |t        d|       |%t        |t              st	        j
                  |      }|| _        || _        || _        || _	        || _
        y)a  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.
          - `hint` (optional): An index to use to support the query
            predicate specified either by its string name, or in the same
            format as passed to
            :meth:`~pymongo.collection.Collection.create_index` (e.g.
            ``[('field', ASCENDING)]``). This option is only supported on
            MongoDB 4.2 and above.

        .. versionchanged:: 3.11
           Added the ``hint`` option.
        .. versionchanged:: 3.5
           Added the ``collation`` option.
        Nr8   upsert)r   r   r:   r   r   r
   r4   r   rV   r5   r6   )r   r8   replacementrX   r<   r=   s         r   r   zReplaceOne.__init__   sg    4 &1Xv.dK0..t4	#
r   c                     |j                  | j                  | j                  | j                  | j                  | j
                         y)r   rA   N)add_replacer4   r   rV   r5   r6   r   s     r   r   zReplaceOne._add_to_bulk   s5    DLL$))T\\&*ooDJJ 	 	Hr   c                 "   t        |      t        |       k(  rs|j                  |j                  |j                  |j                  |j
                  f| j                  | j                  | j                  | j                  |j
                  fk(  S t        S r!   )r"   r4   r   rV   r5   r6   r#   r$   s     r   r&   zReplaceOne.__eq__   ss    ;$t*$

EMM5;K;K"&,,		4<<"&//5;;"@@A r   c                     | |k(   S r!   r(   r$   s     r   r)   zReplaceOne.__ne__   r*   r   c                     | j                   j                  d| j                  d| j                  d| j                  d| j
                  d| j                  dS N(rF   r   )	__class__r,   r4   r   rV   r5   r6   r   s    r   r   zReplaceOne.__repr__   s8    NN##T\\499dllOOTZZ) 	)r   )FNN)
r,   r-   r.   r/   r0   r   r   r&   r)   r   r(   r   r   rU   rU      s+    -EIDH&PH
!)r   rU   c                   ,    e Zd ZdZdZd Zd Zd Zd Zy)	_UpdateOpz)Private base class for update operations.)r4   r   rV   r5   _array_filtersr6   c                     |t        d|       |t        d|       |t        d|       |%t        |t              st        j                  |      }|| _        || _        || _	        || _
        || _        || _        y )Nr8   rX   array_filters)r   r   r   r:   r   r   r
   r4   r   rV   r5   rd   r6   )r   r8   docrX   r<   rf   r=   s          r   r   z_UpdateOp.__init__   s    &1Xv.$/=9dK0..t4 	#+
r   c                 N   t        |      t        |       k(  r|j                  |j                  |j                  |j                  |j
                  |j                  f| j                  | j                  | j                  | j                  | j
                  | j                  fk(  S t        S r!   )r"   r4   r   rV   r5   rd   r6   r#   r$   s     r   r&   z_UpdateOp.__eq__  s    ;$t*$

EMM5;K;K%%u{{4tyy$,,$$djj223
 r   c                     | |k(   S r!   r(   r$   s     r   r)   z_UpdateOp.__ne__
  r*   r   c                     | j                   j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  dS r_   )ra   r,   r4   r   rV   r5   rd   r6   r   s    r   r   z_UpdateOp.__repr__  s@    NN##T\\499dllOOT00$**> 	>r   N)	r,   r-   r.   r/   r0   r   r&   r)   r   r(   r   r   rc   rc      s     3I&!>r   rc   c                   2     e Zd ZdZdZ	 	 d fd	Zd Z xZS )	UpdateOnez#Represents an update_one operation.r(   c                 6    t         t        |   ||||||       y)aM  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+.
          - `hint` (optional): An index to use to support the query
            predicate specified either by its string name, or in the same
            format as passed to
            :meth:`~pymongo.collection.Collection.create_index` (e.g.
            ``[('field', ASCENDING)]``). This option is only supported on
            MongoDB 4.2 and above.

        .. versionchanged:: 3.11
           Added the `hint` option.
        .. 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)superrl   r   r   r8   updaterX   r<   rf   r=   ra   s          r   r   zUpdateOne.__init__  s"    @ 	i'	(5t	=r   c           	          |j                  | j                  | j                  d| j                  | j                  | j
                  | j                         y)r   Fr<   rf   r=   N
add_updater4   r   rV   r5   rd   r6   r   s     r   r   zUpdateOne._add_to_bulk;  s@    4<<E4<<%)__)-)<)< $

 	 	,r   FNNNr,   r-   r.   r/   r0   r   r   __classcell__ra   s   @r   rl   rl     s    -I?C*.!=F,r   rl   c                   2     e Zd ZdZdZ	 	 d fd	Zd Z xZS )
UpdateManyz$Represents an update_many operation.r(   c                 6    t         t        |   ||||||       y)aI  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+.
          - `hint` (optional): An index to use to support the query
            predicate specified either by its string name, or in the same
            format as passed to
            :meth:`~pymongo.collection.Collection.create_index` (e.g.
            ``[('field', ASCENDING)]``). This option is only supported on
            MongoDB 4.2 and above.

        .. versionchanged:: 3.11
           Added the `hint` option.
        .. 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)rn   rz   r   ro   s          r   r   zUpdateMany.__init__H  s"    @ 	j$()6	>r   c           	          |j                  | j                  | j                  d| j                  | j                  | j
                  | j                         y)r   Trr   Nrs   r   s     r   r   zUpdateMany._add_to_bulkk  s@    4<<D$,,%)__)-)<)< $

 	 	,r   ru   rv   rx   s   @r   rz   rz   C  s    .I?C*.!>F,r   rz   c                   *    e Zd ZdZdZd Zed        Zy)
IndexModelzRepresents an index to create.)
__documentc                     t        |      }d|vrt        |      |d<   t        |      |d<   t        |j	                  dd            }|| _        ||| j
                  d<   yy)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 MongoDB >= 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 MongoDB >= 4.2.
          - `hidden`: if ``True``, this index will be hidden from the query
            planner and will not be evaluated as part of query plan
            selection. Requires MongoDB >= 4.4.

        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.11
           Added the ``hidden`` option.
        .. versionchanged:: 3.2
           Added the ``partialFilterExpression`` option to support partial
           indexes.

        .. _wildcard index: https://docs.mongodb.com/master/core/index-wildcard/#wildcard-index-core
        namekeyr<   N)r   r	   r
   r   pop_IndexModel__document)r   keyskwargsr<   s       r   r   zIndexModel.__init__x  sh    | 4 ,T2F6N'-u.vzz+t/LM	  +4DOOK( !r   c                     | j                   S )zUAn index document suitable for passing to the createIndexes
        command.
        )r   r   s    r   r   zIndexModel.document  s    
 r   N)r,   r-   r.   r/   r0   r   propertyr   r(   r   r   r~   r~   s  s%    (IE5N  r   r~   N)r/   bson.py3compatr   pymongor   pymongo.commonr   r   r   pymongo.collationr   pymongo.helpersr	   r
   r   objectr   r2   rN   rU   rc   rl   rz   r~   r(   r   r   <module>r      s    # &  O O 8 I I! !@3! 3!l3! 3!l@) @)F(> (>V-,	 -,`-, -,`Q Qr   