
    (ph                     h    S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJr  S	S jr	S r
S
S jrS rg)z:Internal utilities for interacting with Google API client.    N)
exceptions)_utilsc                 ^   [        U [        R                  R                  5      (       d  [	        U 5      $ U R
                  R                  5       nU R                  R                  n[        R                  " X#5      u  pE[        U 5      nSnU(       a	  U" XXF5      nU(       a  U$ [        XXF5      $ )aQ  Constructs a ``FirebaseError`` from the given googleapiclient error.

This can be used to handle errors returned by Google Cloud Platform (GCP) APIs.

Args:
    error: An error raised by the googleapiclient while making an HTTP call to a GCP API.
    handle_func: A function that can be used to handle platform errors in a custom way. When
        specified, this function will be called with three arguments. It has the same
        signature as ```_handle_func_googleapiclient``, but may return ``None``.

Returns:
    FirebaseError: A ``FirebaseError`` that can be raised to the user code.
N)
isinstancegoogleapiclienterrors	HttpErrorhandle_googleapiclient_errorcontentdecoderespstatusr   _parse_platform_error)_http_response_from_googleapiclient_error_handle_func_googleapiclient)errorhandle_funcr   status_code
error_dictmessagehttp_responseexcs           N/var/www/html/venv/lib/python3.13/site-packages/firebase_admin/_gapic_utils.py*handle_platform_error_from_googleapiclientr      s     e_33==>>+E22mm""$G**##K 66wLJ=eDM
C%*D3b7
bb    c                 <    UR                  S5      n[        XXC5      $ )a  Constructs a ``FirebaseError`` from the given GCP error.

Args:
    error: An error raised by the googleapiclient module while making an HTTP call.
    message: A message to be included in the resulting ``FirebaseError``.
    error_dict: Parsed GCP error response.
    http_response: A requests HTTP response object to associate with the exception.

Returns:
    FirebaseError: A ``FirebaseError`` that can be raised to the user code or None.
r   )getr
   )r   r   r   r   codes        r   r   r   8   s     >>(#D'LLr   c                    [        U [        R                  5      (       d.  [        U [        R                  5      (       a3  S[	        U 5      ;   a$  [
        R                  " SR                  U 5      U S9$ [        U [        R                  5      (       a$  [
        R                  " SR                  U 5      U S9$ [        U [        R                  R                  5      (       d$  [
        R                  " SR                  U 5      U S9$ U(       d*  [        R                   " U R"                  R$                  5      nU(       d  [	        U 5      nU(       d  ['        U 5      n[        R(                  " U5      nU" XUS9$ )a  Constructs a ``FirebaseError`` from the given googleapiclient error.

This method is agnostic of the remote service that produced the error, whether it is a GCP
service or otherwise. Therefore, this method does not attempt to parse the error response in
any way.

Args:
    error: An error raised by the googleapiclient module while making an HTTP call.
    message: A message to be included in the resulting ``FirebaseError`` (optional). If not
        specified the string representation of the ``error`` argument is used as the message.
    code: A GCP error code that will be used to determine the resulting error type (optional).
        If not specified the HTTP status code on the error response is used to determine a
        suitable error code.
    http_response: A requests HTTP response object to associate with the exception (optional).
        If not specified, one will be created from the ``error``.

Returns:
    FirebaseError: A ``FirebaseError`` that can be raised to the user code.
z	timed outz'Timed out while making an API call: {0})r   causez%Failed to establish a connection: {0}z5Unknown error while making a remote service call: {0})r   r    r   )r   sockettimeoutr   strr   DeadlineExceededErrorformathttplib2ServerNotFoundErrorUnavailableErrorr   r   r	   UnknownErrorr   _http_status_to_error_coder   r   r   _error_code_to_exception_type)r   r   r   r   err_types        r   r
   r
   H   s#   ( %((ufll++s5z0I//=DDUK 	 %5566**;BB5I 	 e_33==>>&&KRRSXY 	 001B1BCe*A%H33D9HGNNr   c                     [         R                  R                  5       n[        R                  " U R
                  5      Ul        U R                  R                  Ul	        U$ )zMCreates a requests HTTP Response object from the given googleapiclient error.)
requestsmodelsResponseioBytesIOr   rawr   r   r   )r   r   s     r   r   r   u   s?    ??##%Dzz%--(DHzz((DKr   )N)NNN)__doc__r1   r!   r   r&   r.   firebase_adminr   r   r   r   r
   r    r   r   <module>r7      s8    A 	     % !c8M *OZr   