o
    ˷eI                     @   s  U d Z ddlmZ ddlmZ ddlZddlmZ ddlmZ ddl	Z	ddl
mZ z ddlZzddlmZ W n eyG   e	d	e dZY nw W n eyT   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r|ejD ]	Zeeejd < qrG 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&Z0G d7d8 d8e&Z1G d9d: d:e1Z2G d;d< d<e1Z3G d=d> d>e&Z4G d?d@ d@e&Z5G dAdB dBe&Z6G dCdD dDe&Z7G dEdF dFe7Z8G dGdH dHe&Z9G dIdJ dJe Z:G dKdL dLe:Z;G dMdN dNe:Z<G dOdP dPe:Z=G dQdR dRe:Z>G dSdT dTe:Z?G dUdV dVe:Z@G dWdX dXe:ZAG dYdZ dZeAZBd[d\ ZCd]d^ ZDd_d` ZEdadb ZFdcdd ZGdedf ZHdgdh ZIdidj ZJdS )kzExceptions 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)Dict)Union)error_details_pb2)
rpc_statuszCPlease install grpcio-status to obtain helpful grpc error messages._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   Q/var/www/ideatree/venv/lib/python3.10/site-packages/google/api_core/exceptions.pyr   ;       r   c                   @   r
   )DuplicateCredentialArgsz,Raised when multiple credentials are passed.Nr   r   r   r   r   r   A   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 retring the
            function.
    c                    s    t t| | || _|| _d S N)superr   __init__message_cause)selfr   cause	__class__r   r   r   P   s   
zRetryError.__init__c                 C      | j S )z5The last exception raised when retrying the function.)r   r   r   r   r   r   U   s   zRetryError.causec                 C   s   d | j| jS )Nz{}, last exception: {})formatr   r   r    r   r   r   __str__Z   s   zRetryError.__str__)	r   r   r   r   r   propertyr   r"   __classcell__r   r   r   r   r   G   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'   a   s   

z_GoogleAPICallErrorMeta.__new__N)r   r   r   r   r'   r   r   r   r   r%   ^       r%   c                       s   e Zd ZU dZdZeedf ed< 	 dZ	 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(   r   c                    s4   t t| | || _	 || _|| _|| _|| _d S r   )r   r1   r   r   _errors_details	_response_error_info)r   r   errorsdetailsresponse
error_infor   r   r   r      s   
zGoogleAPICallError.__init__c                 C   s*   | j rd| j| j| j S d| j| jS )Nz{} {} {}z{} {})r7   r!   r(   r   r    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)r5   reasonr    r   r   r   r;         
zGoogleAPICallError.reasonc                 C   r:   )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)r5   domainr    r   r   r   r=      r<   zGoogleAPICallError.domainc                 C   r:   )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)r5   metadatar    r   r   r   r>      r<   zGoogleAPICallError.metadatac                 C   
   t | jS )zuDetailed error information.

        Returns:
            Sequence[Any]: A list of additional error details.
        )listr2   r    r   r   r   r6      s   
zGoogleAPICallError.errorsc                 C   r?   )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
        )r@   r3   r    r   r   r   r7      s   
zGoogleAPICallError.detailsc                 C   r   )zYOptional[Union[requests.Request, grpc.Call]]: The response or
        gRPC call metadata.)r4   r    r   r   r   r8      s   zGoogleAPICallError.response)r   r   NN)r   r   r   r   r(   r   int__annotations__r*   r   r"   r#   r;   r=   r>   r6   r7   r8   r$   r   r   r   r   r1   j   s(   
 	




r1   )	metaclassc                   @   r
   )Redirectionz8Base class for for all redirection (HTTP 3xx) responses.Nr   r   r   r   r   rD          rD   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   rG      r0   rG   c                   @   rF   )NotModifiedz2Exception mapping a ``304 Not Modified`` response.N)r   r   r   r   rH   rI   NOT_MODIFIEDr(   r   r   r   r   rK      r0   rK   c                   @   rF   )TemporaryRedirectz8Exception mapping a ``307 Temporary Redirect`` response.N)r   r   r   r   rH   rI   TEMPORARY_REDIRECTr(   r   r   r   r   rM      r0   rM   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   rO      s    rO   c                   @   r
   )ClientErrorz5Base class for all client error (HTTP 4xx) responses.Nr   r   r   r   r   rP      rE   rP   c                   @   rF   )
BadRequestz1Exception mapping a ``400 Bad Request`` response.N)r   r   r   r   rH   rI   BAD_REQUESTr(   r   r   r   r   rQ      r0   rQ   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   rT         rT   c                   @   rS   )FailedPreconditionzJException mapping a :attr:`grpc.StatusCode.FAILED_PRECONDITION`
    error.N)r   r   r   r   rU   rV   FAILED_PRECONDITIONr*   r   r   r   r   rY     s    rY   c                   @   rS   )
OutOfRangez?Exception mapping a :attr:`grpc.StatusCode.OUT_OF_RANGE` error.N)r   r   r   r   rU   rV   OUT_OF_RANGEr*   r   r   r   r   r[     rX   r[   c                   @   rF   )Unauthorizedz2Exception mapping a ``401 Unauthorized`` response.N)r   r   r   r   rH   rI   UNAUTHORIZEDr(   r   r   r   r   r]     r0   r]   c                   @   rS   )UnauthenticatedzBException mapping a :attr:`grpc.StatusCode.UNAUTHENTICATED` error.N)r   r   r   r   rU   rV   UNAUTHENTICATEDr*   r   r   r   r   r_     rX   r_   c                   @   rF   )	Forbiddenz/Exception mapping a ``403 Forbidden`` response.N)r   r   r   r   rH   rI   	FORBIDDENr(   r   r   r   r   ra      r0   ra   c                   @   rS   )PermissionDeniedzDException mapping a :attr:`grpc.StatusCode.PERMISSION_DENIED` error.N)r   r   r   r   rU   rV   PERMISSION_DENIEDr*   r   r   r   r   rc   &  rX   rc   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   rH   rI   	NOT_FOUNDr(   rU   rV   r*   r   r   r   r   re   ,      re   c                   @   rF   )MethodNotAllowedz8Exception mapping a ``405 Method Not Allowed`` response.N)r   r   r   r   rH   rI   METHOD_NOT_ALLOWEDr(   r   r   r   r   rh   4  r0   rh   c                   @   rF   )Conflictz.Exception mapping a ``409 Conflict`` response.N)r   r   r   r   rH   rI   CONFLICTr(   r   r   r   r   rj   :  r0   rj   c                   @   rS   )AlreadyExistszAException mapping a :attr:`grpc.StatusCode.ALREADY_EXISTS` error.N)r   r   r   r   rU   rV   ALREADY_EXISTSr*   r   r   r   r   rl   @  rX   rl   c                   @   rS   )Abortedz:Exception mapping a :attr:`grpc.StatusCode.ABORTED` error.N)r   r   r   r   rU   rV   ABORTEDr*   r   r   r   r   rn   F  rX   rn   c                   @   rF   )LengthRequiredz5Exception mapping a ``411 Length Required`` response.N)r   r   r   r   rH   rI   LENGTH_REQUIREDr(   r   r   r   r   rp   L  r0   rp   c                   @   rF   )PreconditionFailedz9Exception mapping a ``412 Precondition Failed`` response.N)r   r   r   r   rH   rI   PRECONDITION_FAILEDr(   r   r   r   r   rr   R  r0   rr   c                   @   rF   )RequestRangeNotSatisfiablezCException mapping a ``416 Request Range Not Satisfiable`` response.N)r   r   r   r   rH   rI   REQUESTED_RANGE_NOT_SATISFIABLEr(   r   r   r   r   rt   X  r0   rt   c                   @   rF   )TooManyRequestsz7Exception mapping a ``429 Too Many Requests`` response.N)r   r   r   r   rH   rI   TOO_MANY_REQUESTSr(   r   r   r   r   rv   ^  r0   rv   c                   @   rS   )ResourceExhaustedzEException mapping a :attr:`grpc.StatusCode.RESOURCE_EXHAUSTED` error.N)r   r   r   r   rU   rV   RESOURCE_EXHAUSTEDr*   r   r   r   r   rx   d  rX   rx   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(   rU   rV   	CANCELLEDr*   r   r   r   r   rz   j  s    rz   c                   @   r
   )ServerErrorzBase for 5xx responses.Nr   r   r   r   r   r|   s  rE   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   rH   rI   INTERNAL_SERVER_ERRORr(   rU   rV   INTERNALr*   r   r   r   r   r~   w  rg   r~   c                   @   rS   )Unknownz:Exception mapping a :attr:`grpc.StatusCode.UNKNOWN` error.N)r   r   r   r   rU   rV   UNKNOWNr*   r   r   r   r   r     rX   r   c                   @   rS   )DataLossz<Exception mapping a :attr:`grpc.StatusCode.DATA_LOSS` error.N)r   r   r   r   rU   rV   	DATA_LOSSr*   r   r   r   r   r     rX   r   c                   @   r}   )MethodNotImplementedzjException mapping a ``501 Not Implemented`` response or a
    :attr:`grpc.StatusCode.UNIMPLEMENTED` error.N)r   r   r   r   rH   rI   NOT_IMPLEMENTEDr(   rU   rV   UNIMPLEMENTEDr*   r   r   r   r   r     rg   r   c                   @   rF   )
BadGatewayz1Exception mapping a ``502 Bad Gateway`` response.N)r   r   r   r   rH   rI   BAD_GATEWAYr(   r   r   r   r   r     r0   r   c                   @   r}   )ServiceUnavailablezlException mapping a ``503 Service Unavailable`` response or a
    :attr:`grpc.StatusCode.UNAVAILABLE` error.N)r   r   r   r   rH   rI   SERVICE_UNAVAILABLEr(   rU   rV   UNAVAILABLEr*   r   r   r   r   r     rg   r   c                   @   rF   )GatewayTimeoutz5Exception mapping a ``504 Gateway Timeout`` response.N)r   r   r   r   rH   rI   GATEWAY_TIMEOUTr(   r   r   r   r   r     r0   r   c                   @   rS   )DeadlineExceededzDException mapping a :attr:`grpc.StatusCode.DEADLINE_EXCEEDED` error.N)r   r   r   r   rU   rV   DEADLINE_EXCEEDEDr*   r   r   r   r   r     rX   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   getr1   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_classerrorr   r   r   from_http_status  s
   
r   c                 C   s   z|   }W n ty   dd| jpdii}Y nw |di dd}|di dd}|di dd}ttdd |}|rF|d	 nd
}dj| jj| jj	|d}t
| j|||| |d}|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   zunknown errorr6   r   r7   c                 S   s   |  dddkS )Nz@type z(type.googleapis.com/google.rpc.ErrorInfo)r   detailr   r   r   <lambda>  s   
 z$from_http_response.<locals>.<lambda>r   Nz{method} {url}: {error})methodurlr   r6   r7   r8   r9   )json
ValueErrortextr   r@   filterr!   requestr   r   r   r   )r8   payloaderror_messager6   r7   r9   r   	exceptionr   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   r1   r   r   r   r   exception_class_for_grpc_status  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)
isinstancerA   _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(   r7   )hasattr)rpc_excr   r   r   _is_informative_grpc_error#  s   r   c              
      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rN }n
|d  } | || t|tjre|}q8||fS )Nc                    s     | jS r   )Is
DESCRIPTOR)xr   r   r   r   @  s    z+_parse_grpc_error_details.<locals>.<lambda>r   )r   	from_callNotImplementedErrorr   rQ   PreconditionFailureQuotaFailure	ErrorInfo	RetryInfoResourceInfoRequestInfo	DebugInfoHelpLocalizedMessager7   r@   r   lenUnpackappendr   )r   statuspossible_errorsr9   error_detailsmatched_detail_clsinfor   r   r   _parse_grpc_error_details'  sB   



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   )r6   r8   )
rU   r   Callr   r   r   r(   r7   r1   str)r   r7   err_infor   r   r   from_grpc_errorN  s   	r   )Kr   
__future__r   r   http.clientrH   typingr   r   warnings
google.rpcr   rU   grpc_statusr   ImportErrorwarnImportWarningr   rA   	ExceptionrB   r	   r   rV   r   valuer   r   r   r&   r%   r1   rD   rG   rK   rM   rO   rP   rQ   rT   rY   r[   r]   r_   ra   rc   re   rh   rj   rl   rn   rp   rr   rt   rv   rx   rz   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   
m
	.'