o
    'h>                     @  sR   d Z ddlmZ ddlmZmZmZ ddlmZ dddZ	G dd dZ
e
 ZdS )zTools for working with write concerns.

.. seealso:: This module is compatible with both the synchronous and asynchronous PyMongo APIs.
    )annotations)AnyOptionalUnion)ConfigurationErroroptionstrvaluer   returnboolc                 C  s&   t |tr|S t|  d|  d| )z(Validates that 'value' is True or False.z must be True or False, was: =)
isinstancer   	TypeError)r   r	    r   Q/var/www/html/olx_land/venv/lib/python3.10/site-packages/pymongo/write_concern.pyvalidate_boolean   s   
r   c                   @  sp   e Zd ZdZdZ				d d!ddZed"ddZed#ddZed"ddZ	d$ddZ
d%ddZd%ddZdS )&WriteConcerna  WriteConcern

    :param w: (integer or string) Used with replication, write operations
          will block until they have been replicated to the specified number
          or tagged set of servers. `w=<integer>` always includes the replica
          set primary (e.g. w=3 means write to the primary and wait until
          replicated to **two** secondaries). **w=0 disables acknowledgement
          of write operations and can not be used with other write concern
          options.**
    :param wtimeout: (integer) **DEPRECATED** Used in conjunction with `w`.
          Specify a value in milliseconds to control how long to wait for write
          propagation to complete. If replication does not complete in the given
          timeframe, a timeout exception is raised.
    :param j: If ``True`` block until write operations have been committed
          to the journal. Cannot be used in combination with `fsync`. Write
          operations will fail with an exception if this option is used when
          the server is running without journaling.
    :param fsync: If ``True`` and the server is running without journaling,
          blocks until the server has synced all data files to disk. If the
          server is running with journaling, this acts the same as the `j`
          option, blocking until write operations have been committed to the
          journal. Cannot be used in combination with `j`.


    .. versionchanged:: 4.7
        Deprecated parameter ``wtimeout``, use :meth:`~pymongo.timeout`.
    )
__document__acknowledged__server_defaultNwOptional[Union[int, str]]wtimeoutOptional[int]jOptional[bool]fsyncr
   Nonec                 C  s  i | _ d| _|d ur%t|tstdt| |dk r td|| j d< |d ur3td| || j d< |d urItd| |rD|rDtd|| j d< |dkrU|du rUtd	|d urt|trl|dk rftd
|dk| _nt|t	sztdt| || j d< | j  | _
d S )NTz!wtimeout must be an integer, not r   zwtimeout cannot be less than 0r   r   r   z+Can't set both j and fsync at the same timezCannot set w to 0 and j to Truezw cannot be less than 0z$w must be an integer or string, not r   )_WriteConcern__document_WriteConcern__acknowledgedr   intr   type
ValueErrorr   r   r   _WriteConcern__server_default)selfr   r   r   r   r   r   r   __init__A   s6   








zWriteConcern.__init__r   c                 C     | j S )z0Does this WriteConcern match the server default.)r#   r$   r   r   r   is_server_defaultj   s   zWriteConcern.is_server_defaultdict[str, Any]c                 C  s
   | j  S )zThe document representation of this write concern.

        .. note::
          :class:`WriteConcern` is immutable. Mutating the value of
          :attr:`document` does not mutate this :class:`WriteConcern`.
        )r   copyr'   r   r   r   documento   s   
zWriteConcern.documentc                 C  r&   )z]If ``True`` write operations will wait for acknowledgement before
        returning.
        )r   r'   r   r   r   acknowledgedy   s   zWriteConcern.acknowledgedr   c                 C  s    d ddd | j D S )NzWriteConcern({})z, c                 s  s    | ]}d j | V  qdS )z{}={}N)format).0kvtr   r   r   	<genexpr>   s    z(WriteConcern.__repr__.<locals>.<genexpr>)r-   joinr   itemsr'   r   r   r   __repr__   s   zWriteConcern.__repr__otherr   c                 C  s   t |tr| j|jkS tS Nr   r   r   r+   NotImplementedr$   r4   r   r   r   __eq__      
zWriteConcern.__eq__c                 C  s   t |tr| j|jkS tS r5   r6   r8   r   r   r   __ne__   r:   zWriteConcern.__ne__)NNNN)
r   r   r   r   r   r   r   r   r
   r   )r
   r   )r
   r)   )r
   r   )r4   r   r
   r   )__name__
__module____qualname____doc__	__slots__r%   propertyr(   r+   r,   r3   r9   r;   r   r   r   r   r   "   s"    )	

r   N)r   r   r	   r   r
   r   )r?   
__future__r   typingr   r   r   pymongo.errorsr   r   r   DEFAULT_WRITE_CONCERNr   r   r   r   <module>   s   

n