o
    +iR                     @   s  U d Z ddlmZ ddlmZ ddlZddlmZmZ ddl	Z	ddl
mZ dd ZzddlZzdd	lmZ W n eyD   e  dZY nw W n eyQ   dZY nw i Zeeef ed
< i Zeeef ed< i ZeduryejD ]	Zeeejd < qoG 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e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)G d+d, d,e%Z*G d-d. d.e*Z+G d/d0 d0e%Z,G d1d2 d2e,Z-G d3d4 d4e%Z.G d5d6 d6e%Z/G d7d8 d8e%Z0G d9d: d:e0Z1G d;d< d<e0Z2G d=d> d>e%Z3G d?d@ d@e%Z4G dAdB dBe%Z5G dCdD dDe%Z6G dEdF dFe6Z7G dGdH dHe%Z8G dIdJ dJeZ9G dKdL dLe9Z:G dMdN dNe9Z;G dOdP dPe9Z<G dQdR dRe9Z=G dSdT dTe9Z>G dUdV dVe9Z?G dWdX dXe9Z@G dYdZ dZe@ZAG d[d\ d\eBZCd]d^ ZDd_d` ZEdadb ZF	dtdceGddeGdeee fdfdgZHdhdi ZIdjdk ZJdldm ZKdndo ZLdpdq ZMdrds ZNdS )uzExceptions raised by Google API core & clients.

This module provides base classes for all errors raised by libraries based
on :mod:`google.api_core`, including both HTTP and gRPC clients.
    )absolute_import)unicode_literalsN)OptionalDict)error_details_pb2c                   C   s   t dt d S )NzCPlease install grpcio-status to obtain helpful grpc error messages.)warningswarnImportWarning r
   r
   R/home/livre-enfant/venv/lib/python3.10/site-packages/google/api_core/exceptions.py$_warn_could_not_import_grpcio_status   s   r   )
rpc_status_HTTP_CODE_TO_EXCEPTION_GRPC_CODE_TO_EXCEPTIONc                   @      e Zd ZdZdS )GoogleAPIErrorz;Base class for all exceptions raised by Google API Clients.N__name__
__module____qualname____doc__r
   r
   r
   r   r   ?       r   c                   @   r   )DuplicateCredentialArgsz,Raised when multiple credentials are passed.Nr   r
   r
   r
   r   r   E   r   r   c                       s4   e Zd ZdZ fddZedd Zdd Z  ZS )
RetryErrorzRaised when a function has exhausted all of its available retries.

    Args:
        message (str): The exception message.
        cause (Exception): The last exception raised when retrying the
            function.
    c                    s    t t| | || _|| _d S N)superr   __init__message_cause)selfr   cause	__class__r
   r   r   T   s   
zRetryError.__init__c                 C      | j S )z5The last exception raised when retrying the function.)r   r   r
   r
   r   r    Y   s   zRetryError.causec                 C   s   d | j| jS )Nz{}, last exception: {})formatr   r    r$   r
   r
   r   __str__^   s   zRetryError.__str__)	r   r   r   r   r   propertyr    r&   __classcell__r
   r
   r!   r   r   K   s    
r   c                   @   s   e Zd ZdZdd ZdS )_GoogleAPICallErrorMetaz8Metaclass for registering GoogleAPICallError subclasses.c                 C   sD   t | |||}|jd urt|j| |jd ur t|j| |S r   )type__new__coder   
setdefaultgrpc_status_coder   )mcsnamebases
class_dictclsr
   r
   r   r+   e   s   

z_GoogleAPICallErrorMeta.__new__N)r   r   r   r   r+   r
   r
   r
   r   r)   b       r)   c                       s   e Zd ZU dZdZee ed< 	 dZed ed< 	 d fdd	Z	d	d
 Z
edd Zedd Zedd Zedd Zedd Zedd Z  ZS )GoogleAPICallErrora  Base class for exceptions raised by calling API methods.

    Args:
        message (str): The exception message.
        errors (Sequence[Any]): An optional list of error details.
        details (Sequence[Any]): An optional list of objects defined in google.rpc.error_details.
        response (Union[requests.Request, grpc.Call]): The response or
            gRPC call metadata.
        error_info (Union[error_details_pb2.ErrorInfo, None]): An optional object containing error info
            (google.rpc.error_details.ErrorInfo).
    Nr,   zgrpc.StatusCoder.   r
   c                    s4   t t| | || _	 || _|| _|| _|| _d S r   )r   r5   r   r   _errors_details	_response_error_info)r   r   errorsdetailsresponse
error_infor!   r
   r   r      s   
zGoogleAPICallError.__init__c                 C   sX   d | j| j}| jrd || j}|S | jr*dd | jD }|r*d |d|}|S )Nz{} {}c                 S   s2   g | ]}t |d rt |dr|j d|j qS )r,   r   z: )hasattrr,   r   ).0errorr
   r
   r   
<listcomp>   s    z.GoogleAPICallError.__str__.<locals>.<listcomp>
)r%   r,   r   r;   r:   join)r   	error_msgr:   r
   r
   r   r&      s   zGoogleAPICallError.__str__c                 C      | j r| j jS dS )zThe reason of the error.

        Reference:
            https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112

        Returns:
            Union[str, None]: An optional string containing reason of the error.
        N)r9   reasonr$   r
   r
   r   rF         
zGoogleAPICallError.reasonc                 C   rE   )a5  The logical grouping to which the "reason" belongs.

        Reference:
            https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112

        Returns:
            Union[str, None]: An optional string containing a logical grouping to which the "reason" belongs.
        N)r9   domainr$   r
   r
   r   rH      rG   zGoogleAPICallError.domainc                 C   rE   )a.  Additional structured details about this error.

        Reference:
            https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112

        Returns:
            Union[Dict[str, str], None]: An optional object containing structured details about the error.
        N)r9   metadatar$   r
   r
   r   rI      rG   zGoogleAPICallError.metadatac                 C   
   t | jS )zuDetailed error information.

        Returns:
            Sequence[Any]: A list of additional error details.
        )listr6   r$   r
   r
   r   r:      s   
zGoogleAPICallError.errorsc                 C   rJ   )al  Information contained in google.rpc.status.details.

        Reference:
            https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto
            https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto

        Returns:
            Sequence[Any]: A list of structured objects from error_details.proto
        )rK   r7   r$   r
   r
   r   r;      s   
zGoogleAPICallError.detailsc                 C   r#   )zYOptional[Union[requests.Request, grpc.Call]]: The response or
        gRPC call metadata.)r8   r$   r
   r
   r   r<      s   zGoogleAPICallError.response)r
   r
   NN)r   r   r   r   r,   r   int__annotations__r.   r   r&   r'   rF   rH   rI   r:   r;   r<   r(   r
   r
   r!   r   r5   n   s(   
 	




r5   )	metaclassc                   @   r   )Redirectionz8Base class for for all redirection (HTTP 3xx) responses.Nr   r
   r
   r
   r   rO          rO   c                   @      e Zd ZdZejjZdS )MovedPermanentlyz7Exception mapping a ``301 Moved Permanently`` response.N)r   r   r   r   httpclientMOVED_PERMANENTLYr,   r
   r
   r
   r   rR      r4   rR   c                   @   rQ   )NotModifiedz2Exception mapping a ``304 Not Modified`` response.N)r   r   r   r   rS   rT   NOT_MODIFIEDr,   r
   r
   r
   r   rV      r4   rV   c                   @   rQ   )TemporaryRedirectz8Exception mapping a ``307 Temporary Redirect`` response.N)r   r   r   r   rS   rT   TEMPORARY_REDIRECTr,   r
   r
   r
   r   rX      r4   rX   c                   @   s   e Zd ZdZdZdS )ResumeIncompletezException mapping a ``308 Resume Incomplete`` response.

    .. note:: :attr:`http.client.PERMANENT_REDIRECT` is ``308``, but Google
        APIs differ in their use of this status code.
    i4  N)r   r   r   r   r,   r
   r
   r
   r   rZ      s    rZ   c                   @   r   )ClientErrorz5Base class for all client error (HTTP 4xx) responses.Nr   r
   r
   r
   r   r[     rP   r[   c                   @   rQ   )
BadRequestz1Exception mapping a ``400 Bad Request`` response.N)r   r   r   r   rS   rT   BAD_REQUESTr,   r
   r
   r
   r   r\   
  r4   r\   c                   @   (   e Zd ZdZedurejjZdS dZdS )InvalidArgumentzCException mapping a :attr:`grpc.StatusCode.INVALID_ARGUMENT` error.N)r   r   r   r   grpc
StatusCodeINVALID_ARGUMENTr.   r
   r
   r
   r   r_         r_   c                   @   r^   )FailedPreconditionzJException mapping a :attr:`grpc.StatusCode.FAILED_PRECONDITION`
    error.N)r   r   r   r   r`   ra   FAILED_PRECONDITIONr.   r
   r
   r
   r   rd     s    rd   c                   @   r^   )
OutOfRangez?Exception mapping a :attr:`grpc.StatusCode.OUT_OF_RANGE` error.N)r   r   r   r   r`   ra   OUT_OF_RANGEr.   r
   r
   r
   r   rf     rc   rf   c                   @   rQ   )Unauthorizedz2Exception mapping a ``401 Unauthorized`` response.N)r   r   r   r   rS   rT   UNAUTHORIZEDr,   r
   r
   r
   r   rh   #  r4   rh   c                   @   r^   )UnauthenticatedzBException mapping a :attr:`grpc.StatusCode.UNAUTHENTICATED` error.N)r   r   r   r   r`   ra   UNAUTHENTICATEDr.   r
   r
   r
   r   rj   )  rc   rj   c                   @   rQ   )	Forbiddenz/Exception mapping a ``403 Forbidden`` response.N)r   r   r   r   rS   rT   	FORBIDDENr,   r
   r
   r
   r   rl   /  r4   rl   c                   @   r^   )PermissionDeniedzDException mapping a :attr:`grpc.StatusCode.PERMISSION_DENIED` error.N)r   r   r   r   r`   ra   PERMISSION_DENIEDr.   r
   r
   r
   r   rn   5  rc   rn   c                   @   s0   e Zd ZdZejjZedurej	jZ
dS dZ
dS )NotFoundz`Exception mapping a ``404 Not Found`` response or a
    :attr:`grpc.StatusCode.NOT_FOUND` error.N)r   r   r   r   rS   rT   	NOT_FOUNDr,   r`   ra   r.   r
   r
   r
   r   rp   ;      rp   c                   @   rQ   )MethodNotAllowedz8Exception mapping a ``405 Method Not Allowed`` response.N)r   r   r   r   rS   rT   METHOD_NOT_ALLOWEDr,   r
   r
   r
   r   rs   C  r4   rs   c                   @   rQ   )Conflictz.Exception mapping a ``409 Conflict`` response.N)r   r   r   r   rS   rT   CONFLICTr,   r
   r
   r
   r   ru   I  r4   ru   c                   @   r^   )AlreadyExistszAException mapping a :attr:`grpc.StatusCode.ALREADY_EXISTS` error.N)r   r   r   r   r`   ra   ALREADY_EXISTSr.   r
   r
   r
   r   rw   O  rc   rw   c                   @   r^   )Abortedz:Exception mapping a :attr:`grpc.StatusCode.ABORTED` error.N)r   r   r   r   r`   ra   ABORTEDr.   r
   r
   r
   r   ry   U  rc   ry   c                   @   rQ   )LengthRequiredz5Exception mapping a ``411 Length Required`` response.N)r   r   r   r   rS   rT   LENGTH_REQUIREDr,   r
   r
   r
   r   r{   [  r4   r{   c                   @   rQ   )PreconditionFailedz9Exception mapping a ``412 Precondition Failed`` response.N)r   r   r   r   rS   rT   PRECONDITION_FAILEDr,   r
   r
   r
   r   r}   a  r4   r}   c                   @   rQ   )RequestRangeNotSatisfiablezCException mapping a ``416 Request Range Not Satisfiable`` response.N)r   r   r   r   rS   rT   REQUESTED_RANGE_NOT_SATISFIABLEr,   r
   r
   r
   r   r   g  r4   r   c                   @   rQ   )TooManyRequestsz7Exception mapping a ``429 Too Many Requests`` response.N)r   r   r   r   rS   rT   TOO_MANY_REQUESTSr,   r
   r
   r
   r   r   m  r4   r   c                   @   r^   )ResourceExhaustedzEException mapping a :attr:`grpc.StatusCode.RESOURCE_EXHAUSTED` error.N)r   r   r   r   r`   ra   RESOURCE_EXHAUSTEDr.   r
   r
   r
   r   r   s  rc   r   c                   @   s,   e Zd ZdZdZedurejjZdS dZdS )	Cancelledz<Exception mapping a :attr:`grpc.StatusCode.CANCELLED` error.i  N)	r   r   r   r   r,   r`   ra   	CANCELLEDr.   r
   r
   r
   r   r   y  s    r   c                   @   r   )ServerErrorzBase for 5xx responses.Nr   r
   r
   r
   r   r     rP   r   c                   @   0   e Zd ZdZejjZedurej	j
ZdS dZdS )InternalServerErrorzlException mapping a ``500 Internal Server Error`` response. or a
    :attr:`grpc.StatusCode.INTERNAL` error.N)r   r   r   r   rS   rT   INTERNAL_SERVER_ERRORr,   r`   ra   INTERNALr.   r
   r
   r
   r   r     rr   r   c                   @   r^   )Unknownz:Exception mapping a :attr:`grpc.StatusCode.UNKNOWN` error.N)r   r   r   r   r`   ra   UNKNOWNr.   r
   r
   r
   r   r     rc   r   c                   @   r^   )DataLossz<Exception mapping a :attr:`grpc.StatusCode.DATA_LOSS` error.N)r   r   r   r   r`   ra   	DATA_LOSSr.   r
   r
   r
   r   r     rc   r   c                   @   r   )MethodNotImplementedzjException mapping a ``501 Not Implemented`` response or a
    :attr:`grpc.StatusCode.UNIMPLEMENTED` error.N)r   r   r   r   rS   rT   NOT_IMPLEMENTEDr,   r`   ra   UNIMPLEMENTEDr.   r
   r
   r
   r   r     rr   r   c                   @   rQ   )
BadGatewayz1Exception mapping a ``502 Bad Gateway`` response.N)r   r   r   r   rS   rT   BAD_GATEWAYr,   r
   r
   r
   r   r     r4   r   c                   @   r   )ServiceUnavailablezlException mapping a ``503 Service Unavailable`` response or a
    :attr:`grpc.StatusCode.UNAVAILABLE` error.N)r   r   r   r   rS   rT   SERVICE_UNAVAILABLEr,   r`   ra   UNAVAILABLEr.   r
   r
   r
   r   r     rr   r   c                   @   rQ   )GatewayTimeoutz5Exception mapping a ``504 Gateway Timeout`` response.N)r   r   r   r   rS   rT   GATEWAY_TIMEOUTr,   r
   r
   r
   r   r     r4   r   c                   @   r^   )DeadlineExceededzDException mapping a :attr:`grpc.StatusCode.DEADLINE_EXCEEDED` error.N)r   r   r   r   r`   ra   DEADLINE_EXCEEDEDr.   r
   r
   r
   r   r     rc   r   c                   @   r   )"AsyncRestUnsupportedParameterErrorzPRaised when an unsupported parameter is configured against async rest transport.Nr   r
   r
   r
   r   r     r   r   c                 C      t | tS )zReturn the exception class for a specific HTTP status code.

    Args:
        status_code (int): The HTTP status code.

    Returns:
        :func:`type`: the appropriate subclass of :class:`GoogleAPICallError`.
    )r   getr5   status_coder
   r
   r   exception_class_for_http_status     	r   c                 K   s,   t | }||fi |}|jdu r| |_|S )a  Create a :class:`GoogleAPICallError` from an HTTP status code.

    Args:
        status_code (int): The HTTP status code.
        message (str): The exception message.
        kwargs: Additional arguments passed to the :class:`GoogleAPICallError`
            constructor.

    Returns:
        GoogleAPICallError: An instance of the appropriate subclass of
            :class:`GoogleAPICallError`.
    N)r   r,   r   r   kwargserror_classr@   r
   r
   r   from_http_status  s
   
r   c                 C   s$   |r|  nd }dj||| d}|S )Nz{method} {url}: {error})methodurlr@   )upperr%   )r@   r   r   r   r
   r
   r   _format_rest_error_message  s   r   r   r   payloadc                 C   s   |si n|}| di  dd}| di  dd}| di  dd}ttdd |}|r3|d	 nd
}t|||}	t| j|	||| |d}
|
S )a  Create a :class:`GoogleAPICallError` from a google auth rest response.

    Args:
        response Union[google.auth.transport.Response, google.auth.aio.transport.Response]: The HTTP response.
        method Optional(str): The HTTP request method.
        url Optional(str): The HTTP request url.
        payload Optional(dict): The HTTP response payload. If not passed in, it is read from response for a response type of google.auth.transport.Response.

    Returns:
        GoogleAPICallError: An instance of the appropriate subclass of
            :class:`GoogleAPICallError`, with the message and errors populated
            from the response.
    r@   r   unknown errorr:   r
   r;   c                 S   s   |  dddkS )Nz@type z(type.googleapis.com/google.rpc.ErrorInfo)r   detailr
   r
   r   <lambda>	  s   
 z,format_http_response_error.<locals>.<lambda>r   Nr:   r;   r<   r=   )r   rK   filterr   r   r   )r<   r   r   r   error_messager:   r;   error_info_listr=   r   	exceptionr
   r
   r   format_http_response_error  s*   r   c                 C   sH   z|   }W n ty   dd| jpdii}Y nw t| | jj| jj|S )aS  Create a :class:`GoogleAPICallError` from a :class:`requests.Response`.

    Args:
        response (requests.Response): The HTTP response.

    Returns:
        GoogleAPICallError: An instance of the appropriate subclass of
            :class:`GoogleAPICallError`, with the message and errors populated
            from the response.
    r@   r   r   )json
ValueErrortextr   requestr   r   )r<   r   r
   r
   r   from_http_response  s   r   c                 C   r   )zReturn the exception class for a specific :class:`grpc.StatusCode`.

    Args:
        status_code (grpc.StatusCode): The gRPC status code.

    Returns:
        :func:`type`: the appropriate subclass of :class:`GoogleAPICallError`.
    )r   r   r5   r   r
   r
   r   exception_class_for_grpc_status0  r   r   c                 K   sB   t | trt| | } t| }||fi |}|jdu r| |_|S )a  Create a :class:`GoogleAPICallError` from a :class:`grpc.StatusCode`.

    Args:
        status_code (Union[grpc.StatusCode, int]): The gRPC status code.
        message (str): The exception message.
        kwargs: Additional arguments passed to the :class:`GoogleAPICallError`
            constructor.

    Returns:
        GoogleAPICallError: An instance of the appropriate subclass of
            :class:`GoogleAPICallError`.
    N)
isinstancerL   _INT_TO_GRPC_CODEr   r   r.   r   r
   r
   r   from_grpc_status<  s   

r   c                 C   s   t | do	t | dS )Nr,   r;   )r>   )rpc_excr
   r
   r   _is_informative_grpc_errorV  s   r   c              
      s   t s	t  g d fS zt | }W n ty   g d f Y S w |s$g d fS tjtjtjtjtj	tj
tjtjtjtjg
}d }g }|jD ]- tt fdd|}t|dkrW }n
|d  } | || t|tjrn|}qA||fS )Nc                    s     | jS r   )Is
DESCRIPTOR)xr   r
   r   r   v  s    z+_parse_grpc_error_details.<locals>.<lambda>r   )r   r   	from_callNotImplementedErrorr   r\   PreconditionFailureQuotaFailure	ErrorInfo	RetryInfoResourceInfoRequestInfo	DebugInfoHelpLocalizedMessager;   rK   r   lenUnpackappendr   )r   statuspossible_errorsr=   error_detailsmatched_detail_clsinfor
   r   r   _parse_grpc_error_detailsZ  sH   



r   c                 C   sZ   t dur
t| t jst| r#t| \}}t|  |  | f|| |dS tt	| | f| dS )a  Create a :class:`GoogleAPICallError` from a :class:`grpc.RpcError`.

    Args:
        rpc_exc (grpc.RpcError): The gRPC error.

    Returns:
        GoogleAPICallError: An instance of the appropriate subclass of
            :class:`GoogleAPICallError`.
    Nr   )r:   r<   )
r`   r   Callr   r   r   r,   r;   r5   str)r   r;   err_infor
   r
   r   from_grpc_error  s   	r   r   )Or   
__future__r   r   http.clientrS   typingr   r   r   
google.rpcr   r   r`   grpc_statusr   ImportErrorr   rL   	ExceptionrM   r   r   ra   r   valuer   r   r   r*   r)   r5   rO   rR   rV   rX   rZ   r[   r\   r_   rd   rf   rh   rj   rl   rn   rp   rs   ru   rw   ry   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r
   r
   r   <module>   s   
x
	
**