
    h4                     R   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j        ej        ej        ej        ej        ej        ej        ej        ej         ej!        ej"        ej#        ej$        ej%        ej&        ej'        ej(        ej)        ej*        ej+        ej,        Z-ej        ej        ej        ej        ej        ej        ej        ej'        ej)        d	Z.ej!        ej%        ej        ej+        ej        ej        ej        ej        ej        ej        ej        ej'        ej)        ej#        ej        dZ/d Z0d	 Z1d
 Z2ddZ3	 dde
j4        deedeej5                 f                  dej5        fdZ6d Z7d Z8ddZ9de
j4        dej5        fdZ:dde
j4        dej5        fdZ;d Z<d Z=d Z>d Z? G d dej@        jA        jB                  ZCdS )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__     Y/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/firebase_admin/_utils.pyget_metrics_headerr   Q   s!    R((RRn6PRRRr   c                     | t          j                    S t          | t           j                  r.t          j        | j                  }| |urt          d          | S t          dt          |            d          )z3Returns a reference to an initialized App instance.NzKIllegal app argument. App instance not initialized via the firebase module.zNIllegal app argument. Argument must be of type firebase_admin.App, but given "z".)r   get_app
isinstanceAppname
ValueErrortype)appinitialized_apps     r   _get_initialized_appr&   T   s    
{%'''#~)** (0::o%% D E E E

	II	 	 	  r   c                 L    t          |           } |                     ||          S N)r&   _get_service)r$   r!   initializers      r   get_app_servicer+   f   s%    
s
#
#CD+...r   c                     | j         t          |           S | j         }|j                                        }|j        }t          ||          \  }}d}|r || ||          }|r|n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-   r/   r1   
error_dictmessageexcs           r   #handle_platform_error_from_requestsr:   k   s     ~$U+++~H%%''G&K/EEJ
C 6k%*55L330LLLr   r5   r6   .returnc                    t          | t          j                  r`| j        }|j                                        }|j        }t          ||          \  }}d}|r || ||          }|r|n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-   r/   r0   r1   r2   _handle_func_httpxhandle_httpx_errorr4   s           r    handle_platform_error_from_httpxrA      s    $ %.// 	N>"))++*3G[II
G 	:+eWj99CMss1%*MMMe$$$r   c                    t          | t                    st          j        d|  |           S |                     d          }|                     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.
    2Unknown error while making a remote service call: r8   causecoder8   )r8   )r   dictr   UnknownErrorget_rpc_code_to_error_code_error_code_to_exception_type)r5   rpc_coder8   
error_codeerr_types        r   handle_operation_errorrO      s     eT"" &PPP   	 yy  Hii	""G(22J,Z88H8G$$$$r   c                 N    |                     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)rI   r.   r5   r8   r7   rF   s       r   r3   r3      s'     >>(##D 666r   c                    t          | t          j        j                  rt          j        d|  |           S t          | t          j        j                  rt          j        d|  |           S | j        t          j        d|  |           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: rD   "Failed to establish a connection: NrC   r8   rE   http_response)r   requestsr   TimeoutDeadlineExceededErrorConnectionErrorUnavailableErrorr-   rH   _http_status_to_error_coder1   strrK   r5   r8   rF   rN   s       r   r.   r.      s   $ %,455 /B5BB   	 %,<== *@@@   	 ~&PPP   	  F)%.*DEE e**,T22H8G5OOOOr   c                 N    |                     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.
    rQ   )rI   r@   rR   s       r   r?   r?      s'     >>(##DeWd333r   c                    t          | t          j                  rt          j        d|  |           S t          | t          j                  rt          j        d|  |           S t          | t          j                  r^t          d|            |st          | j
        j                  }|st          |           }t          |          } ||| | j
                  S t          j        d|  |           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.
    rT   rD   rU   zprinting status errorrV   rC   )r   r=   TimeoutExceptionr   rZ   ConnectErrorr\   r>   printr]   r-   r1   r^   rK   rH   r_   s       r   r@   r@      s%   $ %/00 /B5BB   	 %+,, *@@@   	 %.// T%u--- 	J-en.HIID 	!%jjG066xuENSSSS"LULL   r   c                 L    t                               | t          j                  S )z-Maps an HTTP status to a platform error code.)_HTTP_STATUS_TO_ERROR_CODErI   r   UNKNOWN)rQ   s    r   r]   r]   '  s    %))&*2DEEEr   c                 L    t                               | t          j                  S )z*Maps an RPC code to a platform error code.)_RPC_CODE_TO_ERROR_CODErI   r   rg   )rL   s    r   rJ   rJ   +  s    "&&x1CDDDr   c                 L    t                               | t          j                  S )z0Maps a platform error code to an exception type.)_ERROR_CODE_TO_EXCEPTION_TYPErI   r   rH   )rF   s    r   rK   rK   /  s    (,,T:3JKKKr   c                     i }	 t          j        |           }t          |t                    r|}n# t          $ r Y nw xY w|                    di           }|                    d          }|sd| d|  }||fS )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.
    r5   r8   z&Unexpected HTTP response with status: z; body: )jsonloadsr   rG   r"   rI   )r/   r1   dataparsed_bodyr7   msgs         r   r2   r2   4  s     Dj))k4(( 	D    '2&&J
..
#
#C VU{UUGUUs?s   +0 
==c                       e Zd ZdZd Zd ZdS )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                 f    t           j        j        j                            |            d| _        d S )Nowner)googleauthcredentialsCredentials__init__token)selfs    r   rz   z!EmulatorAdminCredentials.__init__W  s)    +44T:::


r   c                     d S r(   r   )r|   requests     r   refreshz EmulatorAdminCredentials.refresh[  s    r   N)__name__
__module____qualname____doc__rz   r   r   r   r   rs   rs   Q  s<         
      r   rs   r(   )NN)Dr   rm   platformr   typingr   r   google.authrv   rX   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DataLossErrorrg   rH   INTERNALInternalErrorUNAVAILABLEr\   DEADLINE_EXCEEDEDrZ   rk   rf   ri   r   r&   r+   r:   	HTTPErrorFirebaseErrorrA   rO   r3   r.   r?   r@   r]   rJ   rK   r2   rw   rx   ry   rs   r   r   r   <module>r      s   0 /  # # # # # # % % % % % % % %           % % % % % %!!@!"J$F! Z7! 
 ?	!
  *"B! *2! 
/! z<! 1! !:#D! *3! *2! 
/! 1! J7!   *"B!! * 
	$		#		%						'		&				
 
  "# #$%"  $S S S  $/ / /
M M M M: TX% %%hsHZ5M,N'NOP% % % % %>% % %*7 7 7%P %P %P %PN4eo 4zG_ 4 4 4 4& &eo &:Kc & & & &PF F FE E EL L L
  :    v{6B     r   