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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yJ   e  dZY nw W n eyW   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 < quG 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 d0d1 d1e&Z-G d2d3 d3e-Z.G d4d5 d5e&Z/G d6d7 d7e&Z0G d8d9 d9e&Z1G d:d; d;e1Z2G d<d= d=e1Z3G d>d? d?e&Z4G d@dA dAe&Z5G dBdC dCe&Z6G dDdE dEe&Z7G dFdG dGe7Z8G dHdI dIe&Z9G dJdK dKe Z:G dLdM dMe:Z;G dNdO dOe:Z<G dPdQ dQe:Z=G dRdS dSe:Z>G dTdU dUe:Z?G dVdW dWe:Z@G dXdY dYe:ZAG dZd[ d[eAZBG d\d] d]eCZDd^d_ ZEd`da ZFdbdc ZG	duddeHdeeHdfee fdgdhZIdidj ZJdkdl ZKdmdn ZLdodp ZMdqdr ZNdsdt ZOdS )vzExceptions 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)Union)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   z/var/www/snowflake_co_dev_github/snow_flake_back_end_deploy/env/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   F   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   U   s   
zRetryError.__init__c                 C      | j S )z5The last exception raised when retrying the function.)r   r    r   r   r   r!   Z   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   L   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,   f   s   

z_GoogleAPICallErrorMeta.__new__N)r   r   r   r   r,   r   r   r   r   r*   c       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   r6   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)r:   reasonr%   r   r   r   rG         
zGoogleAPICallError.reasonc                 C   rF   )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)r:   domainr%   r   r   r   rI      rH   zGoogleAPICallError.domainc                 C   rF   )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)r:   metadatar%   r   r   r   rJ      rH   zGoogleAPICallError.metadatac                 C   
   t | jS )zuDetailed error information.

        Returns:
            Sequence[Any]: A list of additional error details.
        )listr7   r%   r   r   r   r;      s   
zGoogleAPICallError.errorsc                 C   rK   )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
        )rL   r8   r%   r   r   r   r<      s   
zGoogleAPICallError.detailsc                 C   r$   )zYOptional[Union[requests.Request, grpc.Call]]: The response or
        gRPC call metadata.)r9   r%   r   r   r   r=      s   zGoogleAPICallError.response)r   r   NN)r   r   r   r   r-   r   int__annotations__r/   r   r'   r(   rG   rI   rJ   r;   r<   r=   r)   r   r   r"   r   r6   o   s(   
 	




r6   )	metaclassc                   @   r   )Redirectionz8Base class for for all redirection (HTTP 3xx) responses.Nr   r   r   r   r   rP          rP   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   rS      r5   rS   c                   @   rR   )NotModifiedz2Exception mapping a ``304 Not Modified`` response.N)r   r   r   r   rT   rU   NOT_MODIFIEDr-   r   r   r   r   rW      r5   rW   c                   @   rR   )TemporaryRedirectz8Exception mapping a ``307 Temporary Redirect`` response.N)r   r   r   r   rT   rU   TEMPORARY_REDIRECTr-   r   r   r   r   rY      r5   rY   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   r[      s    r[   c                   @   r   )ClientErrorz5Base class for all client error (HTTP 4xx) responses.Nr   r   r   r   r   r\     rQ   r\   c                   @   rR   )
BadRequestz1Exception mapping a ``400 Bad Request`` response.N)r   r   r   r   rT   rU   BAD_REQUESTr-   r   r   r   r   r]     r5   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   ra   rb   FAILED_PRECONDITIONr/   r   r   r   r   re     s    re   c                   @   r_   )
OutOfRangez?Exception mapping a :attr:`grpc.StatusCode.OUT_OF_RANGE` error.N)r   r   r   r   ra   rb   OUT_OF_RANGEr/   r   r   r   r   rg     rd   rg   c                   @   rR   )Unauthorizedz2Exception mapping a ``401 Unauthorized`` response.N)r   r   r   r   rT   rU   UNAUTHORIZEDr-   r   r   r   r   ri   $  r5   ri   c                   @   r_   )UnauthenticatedzBException mapping a :attr:`grpc.StatusCode.UNAUTHENTICATED` error.N)r   r   r   r   ra   rb   UNAUTHENTICATEDr/   r   r   r   r   rk   *  rd   rk   c                   @   rR   )	Forbiddenz/Exception mapping a ``403 Forbidden`` response.N)r   r   r   r   rT   rU   	FORBIDDENr-   r   r   r   r   rm   0  r5   rm   c                   @   r_   )PermissionDeniedzDException mapping a :attr:`grpc.StatusCode.PERMISSION_DENIED` error.N)r   r   r   r   ra   rb   PERMISSION_DENIEDr/   r   r   r   r   ro   6  rd   ro   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   rT   rU   	NOT_FOUNDr-   ra   rb   r/   r   r   r   r   rq   <      rq   c                   @   rR   )MethodNotAllowedz8Exception mapping a ``405 Method Not Allowed`` response.N)r   r   r   r   rT   rU   METHOD_NOT_ALLOWEDr-   r   r   r   r   rt   D  r5   rt   c                   @   rR   )Conflictz.Exception mapping a ``409 Conflict`` response.N)r   r   r   r   rT   rU   CONFLICTr-   r   r   r   r   rv   J  r5   rv   c                   @   r_   )AlreadyExistszAException mapping a :attr:`grpc.StatusCode.ALREADY_EXISTS` error.N)r   r   r   r   ra   rb   ALREADY_EXISTSr/   r   r   r   r   rx   P  rd   rx   c                   @   r_   )Abortedz:Exception mapping a :attr:`grpc.StatusCode.ABORTED` error.N)r   r   r   r   ra   rb   ABORTEDr/   r   r   r   r   rz   V  rd   rz   c                   @   rR   )LengthRequiredz5Exception mapping a ``411 Length Required`` response.N)r   r   r   r   rT   rU   LENGTH_REQUIREDr-   r   r   r   r   r|   \  r5   r|   c                   @   rR   )PreconditionFailedz9Exception mapping a ``412 Precondition Failed`` response.N)r   r   r   r   rT   rU   PRECONDITION_FAILEDr-   r   r   r   r   r~   b  r5   r~   c                   @   rR   )RequestRangeNotSatisfiablezCException mapping a ``416 Request Range Not Satisfiable`` response.N)r   r   r   r   rT   rU   REQUESTED_RANGE_NOT_SATISFIABLEr-   r   r   r   r   r   h  r5   r   c                   @   rR   )TooManyRequestsz7Exception mapping a ``429 Too Many Requests`` response.N)r   r   r   r   rT   rU   TOO_MANY_REQUESTSr-   r   r   r   r   r   n  r5   r   c                   @   r_   )ResourceExhaustedzEException mapping a :attr:`grpc.StatusCode.RESOURCE_EXHAUSTED` error.N)r   r   r   r   ra   rb   RESOURCE_EXHAUSTEDr/   r   r   r   r   r   t  rd   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-   ra   rb   	CANCELLEDr/   r   r   r   r   r   z  s    r   c                   @   r   )ServerErrorzBase for 5xx responses.Nr   r   r   r   r   r     rQ   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   rT   rU   INTERNAL_SERVER_ERRORr-   ra   rb   INTERNALr/   r   r   r   r   r     rs   r   c                   @   r_   )Unknownz:Exception mapping a :attr:`grpc.StatusCode.UNKNOWN` error.N)r   r   r   r   ra   rb   UNKNOWNr/   r   r   r   r   r     rd   r   c                   @   r_   )DataLossz<Exception mapping a :attr:`grpc.StatusCode.DATA_LOSS` error.N)r   r   r   r   ra   rb   	DATA_LOSSr/   r   r   r   r   r     rd   r   c                   @   r   )MethodNotImplementedzjException mapping a ``501 Not Implemented`` response or a
    :attr:`grpc.StatusCode.UNIMPLEMENTED` error.N)r   r   r   r   rT   rU   NOT_IMPLEMENTEDr-   ra   rb   UNIMPLEMENTEDr/   r   r   r   r   r     rs   r   c                   @   rR   )
BadGatewayz1Exception mapping a ``502 Bad Gateway`` response.N)r   r   r   r   rT   rU   BAD_GATEWAYr-   r   r   r   r   r     r5   r   c                   @   r   )ServiceUnavailablezlException mapping a ``503 Service Unavailable`` response or a
    :attr:`grpc.StatusCode.UNAVAILABLE` error.N)r   r   r   r   rT   rU   SERVICE_UNAVAILABLEr-   ra   rb   UNAVAILABLEr/   r   r   r   r   r     rs   r   c                   @   rR   )GatewayTimeoutz5Exception mapping a ``504 Gateway Timeout`` response.N)r   r   r   r   rT   rU   GATEWAY_TIMEOUTr-   r   r   r   r   r     r5   r   c                   @   r_   )DeadlineExceededzDException mapping a :attr:`grpc.StatusCode.DEADLINE_EXCEEDED` error.N)r   r   r   r   ra   rb   DEADLINE_EXCEEDEDr/   r   r   r   r   r     rd   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   getr6   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_classrA   r   r   r   from_http_status  s
   
r   c                 C   s$   |r|  nd }dj||| d}|S )Nz{method} {url}: {error})methodurlrA   )upperr&   )rA   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.
    rA   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   rL   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.
    rA   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   r6   r   r   r   r   exception_class_for_grpc_status1  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)
isinstancerM   _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_errorW  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   w  s    z+_parse_grpc_error_details.<locals>.<lambda>r   )r   r   	from_callNotImplementedErrorr   r]   PreconditionFailureQuotaFailure	ErrorInfo	RetryInfoResourceInfoRequestInfo	DebugInfoHelpLocalizedMessager<   rL   r   lenUnpackappendr   )r   statuspossible_errorsr>   error_detailsmatched_detail_clsinfor   r   r   _parse_grpc_error_details[  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=   )
ra   r   Callr   r   r   r-   r<   r6   str)r   r<   err_infor   r   r   from_grpc_error  s   	r   r   )Pr   
__future__r   r   http.clientrT   typingr   r   r   r   
google.rpcr   r   ra   grpc_statusr   ImportErrorr   rM   	ExceptionrN   r   r   rb   r   valuer   r   r   r+   r*   r6   rP   rS   rW   rY   r[   r\   r]   r`   re   rg   ri   rk   rm   ro   rq   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   r   r   r   r   r   r   r   r   r   r   r   <module>   s   
x
	
**