
    ci#                        d Z ddlmZ ddl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 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 G d$ d%e      Zy&)'zExceptions for ExceptionToStatusInterceptor.

See https://grpc.github.io/grpc/core/md_doc_statuscodes.html for the source of truth
on status code meanings.
    )Optional)
StatusCodec                   ~    e Zd ZU dZej
                  Zeed<   dZe	ed<   	 d
de
e	   de
e   fdZde	fdZed	        Zy)GrpcExceptionaQ  Base class for gRPC exceptions.

    Generally you would not use this class directly, but rather use a subclass
    representing one of the standard gRPC status codes (see:
    https://grpc.github.io/grpc/core/md_doc_statuscodes.html for the official list).

    Attributes:
        status_code: A grpc.StatusCode other than OK. The only use case for this
            is if gRPC adds a new status code that isn't represented by one of the
            subclasses of GrpcException. Must not be OK, because gRPC will not
            raise an RpcError to the client if the status code is OK.
        details: A string with additional informantion about the error.
    Args:
        details: If not None, specifies a custom error message.
        status_code: If not None, sets the status code.

    Raises:
        ValueError: If status_code is OK.
    status_codezUnknown exception occurreddetailsNc                 f    |%|t         j                  k(  rt        d      || _        ||| _        y y )Nz-The status code for an exception cannot be OK)r   OK
ValueErrorr   r   )selfr   r   s      B/tmp/pip-target-z3e9_cxr/lib/python/grpc_interceptor/exceptions.py__init__zGrpcException.__init__$   s<     "jmm+ !PQQ*D"DL     returnc                     | j                   j                  }| j                  j                  }| d| d| j                  dS )zShow the status code and details.

        Returns:
            A string displaying the class name, status code, and details.
        z(status_code=z
, details=))	__class____name__r   namer   )r   clsnamescs      r   __repr__zGrpcException.__repr__.   sB     ..))""-t:dll5EQGGr   c                 .    | j                   j                  S )zReturn status_code as a string.

        Returns:
            The status code as a string.

        Example:
            >>> GrpcException(status_code=StatusCode.NOT_FOUND).status_string
            'NOT_FOUND'
        )r   r   )r   s    r   status_stringzGrpcException.status_string8   s     $$$r   )NN)r   
__module____qualname____doc__r   UNKNOWNr   __annotations__r   strr   r   r   propertyr    r   r   r   r      sj    ( )00K0/GS/ RV#}#:B::N#H# H 
% 
%r   r   c                   ,    e Zd ZdZej
                  ZdZy)AbortedzThe operation was aborted.

    Typically this is due to a concurrency issue such as a sequencer check failure or
    transaction abort. See the guidelines on other exceptions for deciding between
    FAILED_PRECONDITION, ABORTED, and UNAVAILABLE.
    zThe operation was abortedN)r   r   r   r   r   ABORTEDr   r   r"   r   r   r$   r$   F   s     $$K)Gr   r$   c                   ,    e Zd ZdZej
                  ZdZy)AlreadyExistszThe entity that a client attempted to create already exists.

    E.g., a file or directory that a client is trying to create already exists.
    z1The entity attempted to be created already existsN)r   r   r   r   r   ALREADY_EXISTSr   r   r"   r   r   r'   r'   R   s    
 ++KAGr   r'   c                   ,    e Zd ZdZej
                  ZdZy)	Cancelledz5The operation was cancelled, typically by the caller.zThe operation was cancelledN)r   r   r   r   r   	CANCELLEDr   r   r"   r   r   r*   r*   \   s    ?&&K+Gr   r*   c                   ,    e Zd ZdZej
                  ZdZy)DataLossz&Unrecoverable data loss or corruption.z/There was unrecoverable data loss or corruptionN)r   r   r   r   r   	DATA_LOSSr   r   r"   r   r   r-   r-   c   s    0&&K?Gr   r-   c                   ,    e Zd ZdZej
                  ZdZy)DeadlineExceededa  The deadline expired before the operation could complete.

    For operations that change the state of the system, this error may be returned even
    if the operation has completed successfully. For example, a successful response
    from a server could have been delayed long.
    z0Deadline expired before operation could completeN)r   r   r   r   r   DEADLINE_EXCEEDEDr   r   r"   r   r   r0   r0   j   s     ..K@Gr   r0   c                   ,    e Zd ZdZej
                  ZdZy)FailedPreconditiona|  The operation failed because the system is in an invalid state for execution.

    For example, the directory to be deleted is non-empty, an rmdir operation is
    applied to a non-directory, etc. Service implementors can use the following
    guidelines to decide between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
    (a) Use UNAVAILABLE if the client can retry just the failing call. (b) Use ABORTED
    if the client should retry at a higher level (e.g., when a client-specified
    test-and-set fails, indicating the client should restart a read-modify-write
    sequence). (c) Use FAILED_PRECONDITION if the client should not retry until the
    system state has been explicitly fixed. E.g., if an "rmdir" fails because the
    directory is non-empty, FAILED_PRECONDITION should be returned since the client
    should not retry unless the files are deleted from the directory.
    zVThe operation was rejected because the system is not in a state required for executionN)r   r   r   r   r   FAILED_PRECONDITIONr   r   r"   r   r   r3   r3   v   s     00K	- r   r3   c                   ,    e Zd ZdZej
                  ZdZy)InvalidArgumentzThe client specified an invalid argument.

    Note that this differs from FAILED_PRECONDITION. INVALID_ARGUMENT indicates
    arguments that are problematic regardless of the state of the system (e.g., a
    malformed file name).
    z(The client specified an invalid argumentN)r   r   r   r   r   INVALID_ARGUMENTr   r   r"   r   r   r6   r6      s     --K8Gr   r6   c                   ,    e Zd ZdZej
                  ZdZy)InternalzInternal errors.

    This means that some invariants expected by the underlying system have been broken.
    This error code is reserved for serious errors.
    zInternal errorN)r   r   r   r   r   INTERNALr   r   r"   r   r   r9   r9      s     %%KGr   r9   c                   ,    e Zd ZdZej
                  ZdZy)
OutOfRangea  The operation was attempted past the valid range.

    E.g., seeking or reading past end-of-file. Unlike INVALID_ARGUMENT, this error
    indicates a problem that may be fixed if the system state changes. For example, a
    32-bit file system will generate INVALID_ARGUMENT if asked to read at an offset
    that is not in the range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to
    read from an offset past the current file size. There is a fair bit of overlap
    between FAILED_PRECONDITION and OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the
    more specific error) when it applies so that callers who are iterating through a
    space can easily look for an OUT_OF_RANGE error to detect when they are done.
    z0The operation was attempted past the valid rangeN)r   r   r   r   r   OUT_OF_RANGEr   r   r"   r   r   r<   r<      s    
 ))K@Gr   r<   c                   ,    e Zd ZdZej
                  ZdZy)NotFoundax  Some requested entity (e.g., file or directory) was not found.

    Note to server developers: if a request is denied for an entire class of users,
    such as gradual feature rollout or undocumented whitelist, NOT_FOUND may be used.
    If a request is denied for some users within a class of users, such as user-based
    access control, PERMISSION_DENIED must be used.
    z"The requested entity was not foundN)r   r   r   r   r   	NOT_FOUNDr   r   r"   r   r   r?   r?      s     &&K2Gr   r?   c                   ,    e Zd ZdZej
                  ZdZy)PermissionDenieda  The caller does not have permission to execute the specified operation.

    PERMISSION_DENIED must not be used for rejections caused by exhausting some
    resource (use RESOURCE_EXHAUSTED instead for those errors). PERMISSION_DENIED
    must not be used if the caller can not be identified (use UNAUTHENTICATED instead
    for those errors). This error code does not imply the request is valid or the
    requested entity exists or satisfies other pre-conditions.
    zFThe caller does not have permission to execute the specified operationN)r   r   r   r   r   PERMISSION_DENIEDr   r   r"   r   r   rB   rB      s     ..KVGr   rB   c                   ,    e Zd ZdZej
                  ZdZy)ResourceExhaustedzxSome resource has been exhausted.

    Perhaps a per-user quota, or perhaps the entire file system is out of space.
    zA resource has been exhaustedN)r   r   r   r   r   RESOURCE_EXHAUSTEDr   r   r"   r   r   rE   rE      s    
 //K-Gr   rE   c                   ,    e Zd ZdZej
                  ZdZy)UnauthenticatedzMThe request does not have valid authentication credentials for the operation.zLThe request does not have valid authentication credentials for the operationN)r   r   r   r   r   UNAUTHENTICATEDr   r   r"   r   r   rH   rH      s    W,,KV r   rH   c                   ,    e Zd ZdZej
                  ZdZy)UnavailablezThe service is currently unavailable.

    This is most likely a transient condition, which can be corrected by retrying with
    a backoff. Note that it is not always safe to retry non-idempotent operations.
    z$The service is currently unavailableN)r   r   r   r   r   UNAVAILABLEr   r   r"   r   r   rK   rK      s     ((K4Gr   rK   c                   ,    e Zd ZdZej
                  ZdZy)UnimplementedzMThe operation is not implemented or is not supported/enabled in this service.zIThe operation is not implemented or not supported/enabled in this serviceN)r   r   r   r   r   UNIMPLEMENTEDr   r   r"   r   r   rN   rN      s    W**KS r   rN   c                       e Zd ZdZy)Unknowna.  Unknown error.

    For example, this error may be returned when a Status value received from another
    address space belongs to an error space that is not known in this address space.
    Also errors raised by APIs that do not return enough error information may be
    converted to this error.
    N)r   r   r   r   r"   r   r   rQ   rQ      s     	r   rQ   N)r   typingr   grpcr   	Exceptionr   r$   r'   r*   r-   r0   r3   r6   r9   r<   r?   rB   rE   rH   rK   rN   rQ   r"   r   r   <module>rU      s     7%I 7%t	*m 	*BM B, ,@} @	A} 	A ,	9m 	9} A A"
3} 
3W} W. .m 5- 5M 		m 		r   