o
    'h5                     @  s   d Z ddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZmZmZ ddlmZ er4ddlm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dId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 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%dJd2d3Z&G d4d5 d5eZ'G d6d7 d7eZ(G d8d9 d9eZ)G d:d; d;eZ*G d<d= d=eZ+G d>d? d?eZ,G d@dA dAeZ-G dBdC dCeZ.G dDdE dEe.Z/G dFdG dGeZ0dHS )KzExceptions raised by PyMongo.

.. seealso:: This module is compatible with both the synchronous and asynchronous PyMongo APIs.
    )annotations)SSLCertVerificationError)TYPE_CHECKINGAnyIterableMappingOptionalSequenceUnion)InvalidDocumentClientBulkWriteResult)_DocumentOutc                      sP   e Zd ZdZdd fd
dZdddZdddZdddZedddZ	  Z
S )PyMongoErrorz&Base class for all PyMongo exceptions. Nmessagestrerror_labelsOptional[Iterable[str]]returnNonec                   s$   t  | || _t|pg | _d S N)super__init___messageset_error_labels)selfr   r   	__class__ J/var/www/html/olx_land/venv/lib/python3.10/site-packages/pymongo/errors.pyr   "   s   zPyMongoError.__init__labelboolc                 C  s
   || j v S )z[Return True if this error contains the given label.

        .. versionadded:: 3.7
        )r   r   r"   r    r    r!   has_error_label'   s   
zPyMongoError.has_error_labelc                 C     | j | dS )z"Add the given label to this error.N)r   addr$   r    r    r!   _add_error_label.      zPyMongoError._add_error_labelc                 C  r&   )z'Remove the given label from this error.N)r   discardr$   r    r    r!   _remove_error_label2   r)   z PyMongoError._remove_error_labelc                 C     dS )zSTrue if this error was caused by a timeout.

        .. versionadded:: 4.2
        Fr    r   r    r    r!   timeout6   s   zPyMongoError.timeoutr   N)r   r   r   r   r   r   )r"   r   r   r#   )r"   r   r   r   r   r#   )__name__
__module____qualname____doc__r   r%   r(   r+   propertyr.   __classcell__r    r    r   r!   r      s    


r   c                   @     e Zd ZdZdS )ProtocolErrorz1Raised for failures related to the wire protocol.Nr1   r2   r3   r4   r    r    r    r!   r8   ?       r8   c                   @  r7   )ConnectionFailurezCRaised when a connection to the database cannot be made or is lost.Nr9   r    r    r    r!   r;   C   r:   r;   c                   @     e Zd ZdZedddZdS )WaitQueueTimeoutErrorzRaised when an operation times out waiting to checkout a connection from the pool.

    Subclass of :exc:`~pymongo.errors.ConnectionFailure`.

    .. versionadded:: 4.2
    r   r#   c                 C  r,   NTr    r-   r    r    r!   r.   O      zWaitQueueTimeoutError.timeoutNr0   r1   r2   r3   r4   r5   r.   r    r    r    r!   r=   G   s    r=   c                      s8   e Zd ZU dZded< ded< 	dd fddZ  ZS )AutoReconnecta  Raised when a connection to the database is lost and an attempt to
    auto-reconnect will be made.

    In order to auto-reconnect you must handle this exception, recognizing that
    the operation which caused it has not necessarily succeeded. Future
    operations will attempt to open a new connection to the database (and
    will continue to raise this exception until the first successful
    connection is made).

    Subclass of :exc:`~pymongo.errors.ConnectionFailure`.
    z'Union[Mapping[str, Any], Sequence[Any]]errorsdetailsr   Nr   r   1Optional[Union[Mapping[str, Any], Sequence[Any]]]r   r   c                   sB   d }|d urt |tr|d}t || |pg  | _| _d S )NerrorLabels)
isinstancedictgetr   r   rB   rC   )r   r   rB   r   r   r    r!   r   d   s   

zAutoReconnect.__init__r/   )r   r   rB   rD   r   r   )r1   r2   r3   r4   __annotations__r   r6   r    r    r   r!   rA   T   s   
 rA   c                   @  r<   )NetworkTimeouta  An operation on an open connection exceeded socketTimeoutMS.

    The remaining connections in the pool stay open. In the case of a write
    operation, you cannot know whether it succeeded or failed.

    Subclass of :exc:`~pymongo.errors.AutoReconnect`.
    r   r#   c                 C  r,   r>   r    r-   r    r    r!   r.   x   r?   zNetworkTimeout.timeoutNr0   r@   r    r    r    r!   rJ   o       rJ   r   r   rC   -Optional[Union[Mapping[str, Any], list[Any]]]r   c                 C  s   |d ur|  d| } | S )Nz, full error: r    )r   rC   r    r    r!   _format_detailed_error}   s   rM   c                      s&   e Zd ZdZ	dd fd
dZ  ZS )NotPrimaryErroraJ  The server responded "not primary" or "node is recovering".

    These errors result from a query, write, or command. The operation failed
    because the client thought it was using the primary but the primary has
    stepped down, or the client thought it was using a healthy secondary but
    the secondary is stale and trying to recover.

    The client launches a refresh operation on a background thread, to update
    its view of the server as soon as possible after throwing this exception.

    Subclass of :exc:`~pymongo.errors.AutoReconnect`.

    .. versionadded:: 3.12
    r   Nr   r   rB   rL   r   r   c                   s   t  jt|||d d S )N)rB   )r   r   rM   )r   r   rB   r   r    r!   r      s   zNotPrimaryError.__init__r/   )r   r   rB   rL   r   r   )r1   r2   r3   r4   r   r6   r    r    r   r!   rN      s    rN   c                   @  r<   )ServerSelectionTimeoutErrora)  Thrown when no MongoDB server is available for an operation

    If there is no suitable server for an operation PyMongo tries for
    ``serverSelectionTimeoutMS`` (default 30 seconds) to find one, then
    throws this exception. For example, it is thrown after attempting an
    operation when PyMongo cannot connect to any server, or if you attempt
    an insert into a replica set that has no primary and does not elect one
    within the timeout window, or if you attempt to query with a Read
    Preference that the replica set cannot satisfy.
    r   r#   c                 C  r,   r>   r    r-   r    r    r!   r.      r?   z#ServerSelectionTimeoutError.timeoutNr0   r@   r    r    r    r!   rO      s    rO   c                   @  r7   )ConfigurationErrorz0Raised when something is incorrectly configured.Nr9   r    r    r    r!   rP      r:   rP   c                      sb   e Zd ZdZ			dd fddZedddZedddZedddZedddZ	  Z
S )OperationFailurezmRaised when a database operation fails.

    .. versionadded:: 2.7
       The :attr:`details` attribute.
    Nerrorr   codeOptional[int]rC   Optional[Mapping[str, Any]]max_wire_versionr   r   c                   sB   d }|d ur| d}t jt|||d || _|| _|| _d S )NrE   )r   )rH   r   r   rM   _OperationFailure__code_OperationFailure__details#_OperationFailure__max_wire_version)r   rR   rS   rC   rV   r   r   r    r!   r      s   

zOperationFailure.__init__c                 C     | j S r   )rY   r-   r    r    r!   _max_wire_version   s   z"OperationFailure._max_wire_versionc                 C  rZ   )z.The error code returned by the server, if any.rW   r-   r    r    r!   rS         zOperationFailure.codec                 C  rZ   )aV  The complete error document returned by the server.

        Depending on the error that occurred, the error document
        may include useful information beyond just the error
        message. When connected to a mongos the error document
        may contain one or more subdocuments if errors occurred
        on multiple shards.
        )rX   r-   r    r    r!   rC      s   
zOperationFailure.detailsr#   c                 C  s
   | j dv S )N)2   r\   r-   r    r    r!   r.      s   
zOperationFailure.timeout)NNN)
rR   r   rS   rT   rC   rU   rV   rT   r   r   )r   rT   )r   rU   r0   )r1   r2   r3   r4   r   r5   r[   rS   rC   r.   r6   r    r    r   r!   rQ      s    	rQ   c                   @  r7   )CursorNotFoundztRaised while iterating query results if the cursor is
    invalidated on the server.

    .. versionadded:: 2.7
    Nr9   r    r    r    r!   r_      r:   r_   c                   @  r<   )ExecutionTimeoutzRaised when a database operation times out, exceeding the $maxTimeMS
    set in the query or command option.

    .. note:: Requires server version **>= 2.6.0**

    .. versionadded:: 2.7
    r   r#   c                 C  r,   r>   r    r-   r    r    r!   r.      r?   zExecutionTimeout.timeoutNr0   r@   r    r    r    r!   r`      rK   r`   c                   @  r7   )WriteConcernErrorz[Base exception type for errors raised due to write concern.

    .. versionadded:: 3.0
    Nr9   r    r    r    r!   ra      r:   ra   c                   @  r7   )
WriteErrorz^Base exception type for errors raised during write operations.

    .. versionadded:: 3.0
    Nr9   r    r    r    r!   rb      r:   rb   c                   @  r<   )WTimeoutErrora  Raised when a database operation times out (i.e. wtimeout expires)
    before replication completes.

    With newer versions of MongoDB the `details` attribute may include
    write concern fields like 'n', 'updatedExisting', or 'writtenTo'.

    .. versionadded:: 2.7
    r   r#   c                 C  r,   r>   r    r-   r    r    r!   r.     r?   zWTimeoutError.timeoutNr0   r@   r    r    r    r!   rc     s    	rc   c                   @  r7   )DuplicateKeyErrorzCRaised when an insert or update fails due to a duplicate key error.Nr9   r    r    r    r!   rd     r:   rd   rR   r   r#   c                 C  s$   |  ddkpd| v o| d  dS )zCReturn True if this writeConcernError doc is a caused by a timeout.rS   r^   errInfowtimeout)rH   )rR   r    r    r!   _wtimeout_error  s   $rg   c                      sD   e Zd ZU dZded< d fddZdd
dZedddZ  Z	S )BulkWriteErrorzFException class for bulk write errors.

    .. versionadded:: 2.7
    r   rC   resultsr   r   c                   s   t  dd| d S Nzbatch op errors occurredA   )r   r   )r   ri   r   r    r!   r   $  s   zBulkWriteError.__init__tuple[Any, Any]c                 C     | j | jffS r   r   rC   r-   r    r    r!   
__reduce__'     zBulkWriteError.__reduce__r#   c                 C  sN   | j dg }|rt|d rdS | j dg }|r%|d ddkr%dS dS )NwriteConcernErrorsTwriteErrorsrS   r^   F)rC   rH   rg   )r   wceswerrsr    r    r!   r.   *  s   zBulkWriteError.timeout)ri   r   r   r   r   rl   r0   )
r1   r2   r3   r4   rI   r   ro   r5   r.   r6   r    r    r   r!   rh     s   
 
rh   c                      sv   e Zd ZU dZded< ded< d fd	d
ZdddZedddZedddZ	edddZ
edddZ  ZS ) ClientBulkWriteExceptionz3Exception class for client-level bulk write errors.r   rC   r#   verboseri   r   r   c                   s   t  dd| || _d S rj   )r   r   rx   )r   ri   rx   r   r    r!   r   >     
z!ClientBulkWriteException.__init__rl   c                 C  rm   r   rn   r-   r    r    r!   ro   B  rp   z#ClientBulkWriteException.__reduce__Optional[Any]c                 C  s   | j ddS )zA top-level error that occurred when attempting to
        communicate with the server or execute the bulk write.

        This value may not be populated if the exception was
        thrown due to errors occurring on individual writes.
        rR   NrC   rH   r-   r    r    r!   rR   E  s   zClientBulkWriteException.error!Optional[list[WriteConcernError]]c                 C  s   | j dg S )zWrite concern errors that occurred during the bulk write.

        This list may have multiple items if more than one
        server command was required to execute the bulk write.
        rq   r{   r-   r    r    r!   write_concern_errorsO  s   z-ClientBulkWriteException.write_concern_errorsOptional[list[WriteError]]c                 C  s   | j di S )zErrors that occurred during the execution of individual write operations.

        This list will contain at most one entry if the bulk write was ordered.
        rs   r{   r-   r    r    r!   write_errorsX  s   z%ClientBulkWriteException.write_errorsOptional[ClientBulkWriteResult]c                 C  s.   ddl m} | jdr|| jd| jdS dS )zoThe results of any successful operations that were
        performed before the error was encountered.
        r   r   anySuccessfulT)acknowledgedhas_verbose_resultsN)pymongo.resultsr   rC   rH   rx   )r   r   r    r    r!   partial_result`  s   z'ClientBulkWriteException.partial_result)ri   r   rx   r#   r   r   rv   )r   rz   )r   r|   )r   r~   )r   r   )r1   r2   r3   r4   rI   r   ro   r5   rR   r}   r   r   r6   r    r    r   r!   rw   8  s   
 
	rw   c                   @  r7   )InvalidOperationz>Raised when a client attempts to perform an invalid operation.Nr9   r    r    r    r!   r   p  r:   r   c                   @  r7   )InvalidNamez$Raised when an invalid name is used.Nr9   r    r    r    r!   r   t  r:   r   c                   @  r7   )CollectionInvalidz(Raised when collection validation fails.Nr9   r    r    r    r!   r   x  r:   r   c                   @  r7   )
InvalidURIz3Raised when trying to parse an invalid mongodb URI.Nr9   r    r    r    r!   r   |  r:   r   c                   @  r7   )DocumentTooLargezFRaised when an encoded document is too large for the connected server.Nr9   r    r    r    r!   r     r:   r   c                      s>   e Zd ZdZd fddZeddd	ZedddZ  ZS )EncryptionErrorzRaised when encryption or decryption fails.

    This error always wraps another exception which can be retrieved via the
    :attr:`cause` property.

    .. versionadded:: 3.9
    cause	Exceptionr   r   c                   s   t  t| || _d S r   )r   r   r   _EncryptionError__cause)r   r   r   r    r!   r     ry   zEncryptionError.__init__c                 C  rZ   )z>The exception that caused this encryption or decryption error.)r   r-   r    r    r!   r     r]   zEncryptionError.causer#   c                 C  s   t | jtr
| jjS dS )NF)rF   r   r   r.   r-   r    r    r!   r.     s   zEncryptionError.timeout)r   r   r   r   )r   r   r0   )	r1   r2   r3   r4   r   r5   r   r.   r6   r    r    r   r!   r     s    r   c                      s0   e Zd ZdZd fdd	Zedd
dZ  ZS )EncryptedCollectionErrorz^Raised when creating a collection with encrypted_fields fails.

    .. versionadded:: 4.4
    r   r   encrypted_fieldsMapping[str, Any]r   r   c                   s   t  | || _d S r   )r   r   +_EncryptedCollectionError__encrypted_fields)r   r   r   r   r    r!   r     s   
z!EncryptedCollectionError.__init__c                 C  rZ   )a  The encrypted_fields document that allows inferring which data keys are *known* to be created.

        Note that the returned document is not guaranteed to contain information about *all* of the data keys that
        were created, for example in the case of an indefinite error like a timeout. Use the `cause` property to
        determine whether a definite or indefinite error caused this error, and only rely on the accuracy of the
        encrypted_fields if the error is definite.
        )r   r-   r    r    r!   r     s   	z)EncryptedCollectionError.encrypted_fields)r   r   r   r   r   r   )r   r   )r1   r2   r3   r4   r   r5   r   r6   r    r    r   r!   r     s
    r   c                   @  r7   )_OperationCancelledz;Internal error raised when a socket operation is cancelled.Nr9   r    r    r    r!   r     r:   r   N)r   r   rC   rL   r   r   )rR   r   r   r#   )1r4   
__future__r   sslr   _CertificateErrortypingr   r   r   r   r   r	   r
   bson.errorsr   r   r   pymongo.typingsr   r   r   r8   r;   r=   rA   rJ   rM   rN   rO   rP   rQ   r_   r`   ra   rb   rc   rd   rg   rh   rw   r   r   r   r   r   r   r   r   r    r    r    r!   <module>   sH   $ 
0
8