o Sb* @s.dZddlmZmZmZmZmZmZmZm Z ddl m Z zddl m ZWn#eyGzddl mZWneyDGdddeZYnwYnwGdd d eZGd d d eZGd d d eZGdddeZGdddeZGdddeZddZGdddeZGdddeZGdddeZGdddeZGdddeZGd d!d!eZGd"d#d#eZ Gd$d%d%eZ!Gd&d'd'e Z"Gd(d)d)e!Z#d*ed+e$fd,d-Z%Gd.d/d/eZ&Gd0d1d1eZ'Gd2d3d3eZ(Gd4d5d5eZ)Gd6d7d7eZ*Gd8d9d9e Z+Gd:d;d;eZ,GdS)?zExceptions raised by PyMongo.)AnyIterableListMappingOptionalSequenceTupleUnion)InvalidDocument)SSLCertVerificationError)CertificateErrorc@s eZdZdS)_CertificateErrorN)__name__ __module__ __qualname__rr5/tmp/pip-target-onvjaxws/lib/python/pymongo/errors.pyr sr csleZdZdZddedeeeddffdd Zd edefd d Z d d Z ddZ e defddZ ZS) PyMongoErrorz&Base class for all PyMongo exceptions.Nmessage error_labelsreturncs(tt||||_t|pg|_dSN)superr__init___messageset _error_labels)selfrr __class__rrr#szPyMongoError.__init__labelcCs ||jvS)z[Return True if this error contains the given label. .. versionadded:: 3.7 )rrr!rrrhas_error_label(s zPyMongoError.has_error_labelcC|j|dS)z"Add the given label to this error.N)raddr"rrr_add_error_label/zPyMongoError._add_error_labelcCr$)z'Remove the given label from this error.N)rdiscardr"rrr_remove_error_label3r'z PyMongoError._remove_error_labelcCdS)zSTrue if this error was caused by a timeout. .. versionadded:: 4.2 Frrrrrtimeout7szPyMongoError.timeoutrN)rrr__doc__strrrrboolr#r&r)propertyr, __classcell__rrrrr s$rc@eZdZdZdS) ProtocolErrorz1Raised for failures related to the wire protocol.Nrrrr.rrrrr4@r4c@r3)ConnectionFailurezCRaised when a connection to the database cannot be made or is lost.Nr5rrrrr7Dr6r7c@"eZdZdZedefddZdS)WaitQueueTimeoutErrorzRaised when an operation times out waiting to checkout a connection from the pool. Subclass of :exc:`~pymongo.errors.ConnectionFailure`. .. versionadded:: 4.2 rcCr*NTrr+rrrr,PzWaitQueueTimeoutError.timeoutNrrrr.r1r0r,rrrrr9Hsr9c sxeZdZUdZeeeefefe d<eeeefefe d< d dede eeeefefddffdd Z Z S) AutoReconnectaRaised 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`. errorsdetailsrNrrcsFd}|durt|tr|d}tt||||pg|_|_dS)N errorLabels) isinstancedictgetrr=rr>r?)rrr>rrrrres   zAutoReconnect.__init__r-) rrrr.r rr/rr__annotations__rrr2rrrrr=Us  r=c@r8)NetworkTimeoutaAn 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`. rcCr*r:rr+rrrr,yr;zNetworkTimeout.timeoutNr<rrrrrEprEcCs|dur d||f}|S)Nz%s, full error: %sr)rr?rrr_format_detailed_error~s rGc sFeZdZdZ d dedeeeeefe fddffdd Z Z S) NotPrimaryErroraJThe 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 rNrr>rcstt|jt|||ddS)N)r>)rrHrrG)rrr>rrrrs   zNotPrimaryError.__init__r-) rrrr.r/rr rrrrr2rrrrrHsrHc@r8)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. rcCr*r:rr+rrrr,r;z#ServerSelectionTimeoutError.timeoutNr<rrrrrIs rIc@r3)ConfigurationErrorz0Raised when something is incorrectly configured.Nr5rrrrrJr6rJc seZdZdZ   ddedeedeeeefdeeddf fdd Z e d d Z e deefd d Z e deeeeffddZ e defddZZS)OperationFailurezmRaised when a database operation fails. .. versionadded:: 2.7 The :attr:`details` attribute. Nerrorcoder?max_wire_versionrcsFd}|dur |d}tt|jt|||d||_||_||_dS)Nr@)r)rCrrKrrG_OperationFailure__code_OperationFailure__details#_OperationFailure__max_wire_version)rrLrMr?rNrrrrrs    zOperationFailure.__init__cC|jSr)rQr+rrr_max_wire_versionsz"OperationFailure._max_wire_versioncCrR)z.The error code returned by the server, if any.rOr+rrrrMzOperationFailure.codecCrR)aVThe 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. )rPr+rrrr?s zOperationFailure.detailscCs |jdvS)N)2rTr+rrrr,s zOperationFailure.timeout)NNN)rrrr.r/rintrrrr1rSrMr?r0r,r2rrrrrKs0   rKc@r3)CursorNotFoundztRaised while iterating query results if the cursor is invalidated on the server. .. versionadded:: 2.7 Nr5rrrrrXr6rXc@r8)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 rcCr*r:rr+rrrr,r;zExecutionTimeout.timeoutNr<rrrrrYrFrYc@r3)WriteConcernErrorz[Base exception type for errors raised due to write concern. .. versionadded:: 3.0 Nr5rrrrrZr6rZc@r3) WriteErrorz^Base exception type for errors raised during write operations. .. versionadded:: 3.0 Nr5rrrrr[r6r[c@r8) WTimeoutErroraRaised 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 rcCr*r:rr+rrrr,r;zWTimeoutError.timeoutNr<rrrrr\s r\c@r3)DuplicateKeyErrorzCRaised when an insert or update fails due to a duplicate key error.Nr5rrrrr]r6r]rLrcCs$|ddkpd|vo|ddS)zCReturn True if this writeConcernError doc is a caused by a timeout.rMrVZerrInfoZwtimeout)rC)rLrrr_wtimeout_errors$r^csleZdZUdZeeefed<deeefddffdd Zde eeffdd Z e de fd d Z ZS) BulkWriteErrorzFException class for bulk write errors. .. versionadded:: 2.7 r?resultsrNcstt|dd|dS)Nzbatch op errors occurredA)rr_r)rr`rrrr'szBulkWriteError.__init__cCs|j|jffSr)r r?r+rrr __reduce__*szBulkWriteError.__reduce__cCsN|jdg}|rt|drdS|jdg}|r%|dddkr%dSdS)NZwriteConcernErrorsTZ writeErrorsrMrVF)r?rCr^)rZwcesZwerrsrrrr,-szBulkWriteError.timeout)rrrr.rr/rrDrrrbr1r0r,r2rrrrr_s r_c@r3)InvalidOperationz>Raised when a client attempts to perform an invalid operation.Nr5rrrrrd;r6rdc@r3) InvalidNamez$Raised when an invalid name is used.Nr5rrrrre?r6rec@r3)CollectionInvalidz(Raised when collection validation fails.Nr5rrrrrfCr6rfc@r3) InvalidURIz3Raised when trying to parse an invalid mongodb URI.Nr5rrrrrgGr6rgc@r3)DocumentTooLargezFRaised when an encoded document is too large for the connected server.Nr5rrrrrhKrhcsNeZdZdZdeddffdd ZedefddZedefd 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 causerNcstt|t|||_dSr)rrjrr/_EncryptionError__cause)rrkrrrrZs zEncryptionError.__init__cCrR)z>The exception that caused this encryption or decryption error.)rlr+rrrrk^rUzEncryptionError.causecCst|jtr |jjSdS)NF)rArlrr,r+rrrr,cs zEncryptionError.timeout) rrrr. Exceptionrr1rkr0r,r2rrrrrjQsrjc@r3)_OperationCancelledz;Internal error raised when a socket operation is cancelled.Nr5rrrrrnjrirnN).r.typingrrrrrrrr Z bson.errorsr sslr r ImportErrorr ValueErrorrmrr4r7r9r=rErGrHrIrJrKrXrYrZr[r\r]r0r^r_rdrerfrgrhrjrnrrrrsN(      2