Ë
    ö%9jÚ  ã                   ód   — d Z ddlZddlZddlZddlZddlZddlmZ ddlmZ d	d„Z	d„ Z
d
d„Zd„ Zy)z:Internal utilities for interacting with Google API client.é    N)Ú
exceptions)Ú_utilsc                 óJ  — t        | t        j                  j                  «      st	        | «      S | j
                  j                  «       }| j                  j                  }t        j                  ||«      \  }}t        | «      }d}|r || |||«      }|r|S t        | |||«      S )au  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           úW/var/www/html/truck-me/venv/lib/python3.12/site-packages/firebase_admin/_gapic_utils.pyÚ*handle_platform_error_from_googleapiclientr      s™   € ô �eœ_×3Ñ3×=Ñ=Ô>Ü+¨EÓ2Ð2à�m‰m×"Ñ"Ó$€GØ—*‘*×#Ñ#€KÜ ×6Ñ6°wÀÓLÑ€J�Ü=¸eÓD€MØ
€CÙÙ˜% ¨*°mÓDˆáˆ3ÐbÔ7¸¸wÈ
ÐTaÓbÐbó    c                 ó@   — |j                  d«      }t        | |||«      S )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Ü'¨¨w¸¸mÓLÐLr   c                 ó®  — t        | t        j                  «      s't        | t        j                  «      r3dt	        | «      v r&t        j                  dj                  | «      | ¬«      S t        | t        j                  «      r&t        j                  dj                  | «      | ¬«      S t        | t        j                  j                  «      s&t        j                  dj                  | «      | ¬«      S |s)t        j                   | j"                  j$                  «      }|st	        | «      }|st'        | «      }t        j(                  |«      } ||| |¬«      S )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  € ô( �%œŸ™Ô(Ü�uœfŸl™lÔ+°¼sÀ5»zÑ0IÜ×/Ñ/Ø=×DÑDÀUÓKØôð 	ô �%œ×5Ñ5Ô6Ü×*Ñ*Ø;×BÑBÀ5ÓIØôð 	ô �eœ_×3Ñ3×=Ñ=Ô>Ü×&Ñ&ØK×RÑRÐSXÓYØôð 	ñ Ü×0Ñ0°·±×1BÑ1BÓCˆÙÜ�e“*ˆÙÜAÀ%ÓHˆä×3Ñ3°DÓ9€HÙ˜G¨5ÀÔNÐNr   c                 óÀ   — t         j                  j                  «       }t        j                  | j
                  «      |_        | j                  j                  |_	        |S )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Ü�z‰z˜%Ÿ-™-Ó(€D„HØ—z‘z×(Ñ(€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   