
    ]hd4                        d Z ddlZddlmZ ddlmZmZ ddlZddl	Z	ddl
Z
ddlZddlmZ i ej                  ej                  ej                  ej                   ej"                  ej$                  ej&                  ej(                  ej*                  ej,                  ej.                  ej0                  ej2                  ej4                  ej6                  ej8                  ej:                  ej<                  ej>                  ej@                  ejB                  ejD                  ejF                  ejH                  ejJ                  ejL                  ejN                  ejP                  ejR                  ejT                  ejV                  ejX                  Z-ej                  ej&                  ej*                  ej.                  ej:                  ej                  ej>                  ejN                  ejR                  d	Z.ejB                  ejJ                  ej                  ejV                  ej.                  ej6                  ej*                  ej>                  ej                  ej2                  ej"                  ejN                  ejR                  ejF                  ej&                  dZ/d Z0d	 Z1d
 Z2ddZ3	 dde
jh                  deedeejj                     f      dejj                  fdZ6d Z7d Z8ddZ9de
jh                  dejj                  fdZ:dde
jh                  dejj                  fdZ;d Z<d Z=d Z>d Z? G d dej                  j                  j                        ZCy)z)Internal utilities common to all modules.    N)python_version)CallableOptional)
exceptions)	i  i  i  i  i  i  i  i  i  )                        	   
                  c                  >    dt                dt        j                   S )Nz
gl-python/z fire-admin/)r   firebase_admin__version__     [/var/www/html/Kila-kolis-project/venv/lib/python3.12/site-packages/firebase_admin/_utils.pyget_metrics_headerr   Q   s     ()n6P6P5QRRr   c                    | t        j                         S t        | t         j                        r0t        j                  | j                        }| |urt        d      | S t        dj                  t        |                   )z3Returns a reference to an initialized App instance.zKIllegal app argument. App instance not initialized via the firebase module.zTIllegal app argument. Argument must be of type  firebase_admin.App, but given "{0}".)r   get_app
isinstanceAppname
ValueErrorformattype)appinitialized_apps     r   _get_initialized_appr'   T   s~    
{%%''#~))*(00:o% D E E

 ==CVDI=NP Pr   c                 <    t        |       } | j                  ||      S N)r'   _get_service)r%   r!   initializers      r   get_app_servicer,   e   s    
s
#CD+..r   c                     | j                   t        |       S | j                   }|j                  j                         }|j                  }t        ||      \  }}d}|r
 || ||      }|r|S t        | ||      S )ag  Constructs a ``FirebaseError`` from the given requests error.

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

    Args:
        error: An error raised by the requests module 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_requests``, but may return ``None``.

    Returns:
        FirebaseError: A ``FirebaseError`` that can be raised to the user code.
    N)responsehandle_requests_errorcontentdecodestatus_code_parse_platform_error_handle_func_requestserrorhandle_funcr.   r0   r2   
error_dictmessageexcs           r   #handle_platform_error_from_requestsr;   j   s     ~~$U++~~H%%'G&&K/EJ
C%*53L0LLr   r6   r7   .returnc                    t        | t        j                        r`| j                  }|j                  j                         }|j                  }t        ||      \  }}d}|r
 || ||      }|r|S t        | ||      S t        |       S )a^  Constructs a ``FirebaseError`` from the given httpx error.

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

    Args:
        error: An error raised by the httpx module 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_httpx``, but may return ``None``.

    Returns:
        FirebaseError: A ``FirebaseError`` that can be raised to the user code.
    N)
r   httpxHTTPStatusErrorr.   r0   r1   r2   r3   _handle_func_httpxhandle_httpx_errorr5   s           r    handle_platform_error_from_httpxrB      s    $ %../>>""))+**3G[I
GeWj9CsM1%*MMe$$r   c                     t        | t              s&t        j                  dj	                  |       |       S | j                  d      }| j                  d      }t        |      }t        |      } ||      S )zConstructs a ``FirebaseError`` from the given operation error.

    Args:
        error: An error returned by a long running operation.

    Returns:
        FirebaseError: A ``FirebaseError`` that can be raised to the user code.
    5Unknown error while making a remote service call: {0}r9   causecoder9   )r9   )r   dictr   UnknownErrorr#   get_rpc_code_to_error_code_error_code_to_exception_type)r6   rpc_coder9   
error_codeerr_types        r   handle_operation_errorrP      sp     eT"&&KRRSXY 	 yy Hii	"G(2J,Z8HG$$r   c                 >    |j                  d      }t        | ||      S )a|  Constructs a ``FirebaseError`` from the given GCP error.

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

    Returns:
        FirebaseError: A ``FirebaseError`` that can be raised to the user code or None.
    status)rJ   r/   r6   r9   r8   rG   s       r   r4   r4      s!     >>(#D 66r   c                 *   t        | t        j                  j                        r&t        j                  dj                  |       |       S t        | t        j                  j                        r&t        j                  dj                  |       |       S | j                  &t        j                  dj                  |       |       S |st        | j                  j                        }|st        |       }t        |      } ||| | j                        S )ao  Constructs a ``FirebaseError`` from the given requests 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 requests 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.

    Returns:
        FirebaseError: A ``FirebaseError`` that can be raised to the user code.
    'Timed out while making an API call: {0}rE   %Failed to establish a connection: {0}rD   r9   rF   http_response)r   requestsr   TimeoutDeadlineExceededErrorr#   ConnectionErrorUnavailableErrorr.   rI   _http_status_to_error_coder2   strrL   r6   r9   rG   rO   s       r   r/   r/      s    $ %,,445//=DDUK 	 %,,<<=**;BB5I 	 ~~&&KRRSXY 	 )%..*D*DEe*,T2HG5OOr   c                 >    |j                  d      }t        | ||      S )ay  Constructs a ``FirebaseError`` from the given GCP error.

    Args:
        error: An error raised by the httpx module while making an HTTP call.
        message: A message to be included in the resulting ``FirebaseError``.
        error_dict: Parsed GCP error response.

    Returns:
        FirebaseError: A ``FirebaseError`` that can be raised to the user code or None.
    rR   )rJ   rA   rS   s       r   r@   r@      s!     >>(#DeWd33r   c                 6   t        | t        j                        r&t        j                  dj                  |       |       S t        | t        j                        r&t        j                  dj                  |       |       S t        | t        j                        rZt        d|        |st        | j                  j                        }|st        |       }t        |      } ||| | j                        S t        j                  dj                  |       |       S )ai  Constructs a ``FirebaseError`` from the given httpx 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 httpx 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.

    Returns:
        FirebaseError: A ``FirebaseError`` that can be raised to the user code.
    rU   rE   rV   zprinting status errorrW   rD   )r   r>   TimeoutExceptionr   r[   r#   ConnectErrorr]   r?   printr^   r.   r2   r_   rL   rI   r`   s       r   rA   rA      s    $ %//0//=DDUK 	 %++,**;BB5I 	 %../%u--enn.H.HID%jG06uENNSS""GNNuU r   c                 J    t         j                  | t        j                        S )z-Maps an HTTP status to a platform error code.)_HTTP_STATUS_TO_ERROR_CODErJ   r   UNKNOWN)rR   s    r   r^   r^   &  s    %))&*2D2DEEr   c                 J    t         j                  | t        j                        S )z*Maps an RPC code to a platform error code.)_RPC_CODE_TO_ERROR_CODErJ   r   rh   )rM   s    r   rK   rK   *  s    "&&x1C1CDDr   c                 J    t         j                  | t        j                        S )z0Maps a platform error code to an exception type.)_ERROR_CODE_TO_EXCEPTION_TYPErJ   r   rI   )rG   s    r   rL   rL   .  s    (,,T:3J3JKKr   c                     i }	 t        j                  |       }t        |t              r|}|j                  di       }|j                  d      }|sdj                  ||       }||fS # t        $ r Y Fw xY w)a(  Parses an HTTP error response from a Google Cloud Platform API and extracts the error code
    and message fields.

    Args:
        content: Decoded content of the response body.
        status_code: HTTP status code.

    Returns:
        tuple: A tuple containing error code and message.
    r6   r9   z4Unexpected HTTP response with status: {0}; body: {1})jsonloadsr   rH   r"   rJ   r#   )r0   r2   dataparsed_bodyr8   msgs         r   r3   r3   3  s     Djj)k4(D '2&J
..
#CDKKKY`as?  s   'A& &	A21A2c                       e Zd ZdZd Zd Zy)EmulatorAdminCredentialsz Credentials for use with the firebase local emulator.

    This is used instead of user-supplied credentials or ADC.  It will silently do nothing when
    asked to refresh credentials.
    c                 x    t         j                  j                  j                  j	                  |        d| _        y )Nowner)googleauthcredentialsCredentials__init__token)selfs    r   r{   z!EmulatorAdminCredentials.__init__V  s'    ++44T:
r   c                      y r)   r   )r}   requests     r   refreshz EmulatorAdminCredentials.refreshZ  s    r   N)__name__
__module____qualname____doc__r{   r   r   r   r   rt   rt   P  s    
r   rt   r)   )NN)Dr   rn   platformr   typingr   r   google.authrw   rY   r>   r   r   INVALID_ARGUMENTInvalidArgumentErrorFAILED_PRECONDITIONFailedPreconditionErrorOUT_OF_RANGEOutOfRangeErrorUNAUTHENTICATEDUnauthenticatedErrorPERMISSION_DENIEDPermissionDeniedError	NOT_FOUNDNotFoundErrorABORTEDAbortedErrorALREADY_EXISTSAlreadyExistsErrorCONFLICTConflictErrorRESOURCE_EXHAUSTEDResourceExhaustedError	CANCELLEDCancelledError	DATA_LOSSDataLossErrorrh   rI   INTERNALInternalErrorUNAVAILABLEr]   DEADLINE_EXCEEDEDr[   rl   rg   rj   r   r'   r,   r;   	HTTPErrorFirebaseErrorrB   rP   r4   r/   r@   rA   r^   rK   rL   r3   rx   ry   rz   rt   r   r   r   <module>r      sr   0  # %     %!!@!@!""J$F$F! Z77! 
 ? ?	!
   *"B"B! *22! 
//! z<<! 11! !!:#D#D! *33! *22! 
//! 11! J77!    *"B"B!! * 
	$	$		#	#		%	%								'	'		&	&						
  ""##  ##$$%%"" $SP"/
M: TX%%hsHZ5M5M,N'NOP% %>%*7%PN4eoo 4zG_G_ 4&eoo &:KcKc &PFEL
:v{{66BB r   