Ë
    ¹ÿjÝ3  ã                   óÌ  — 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__© ó    úO/root/telegram-saas/.venv/lib/python3.12/site-packages/firebase_admin/_utils.pyÚget_metrics_headerr   Q   s    € ØœÓ(Ð)¨´n×6PÑ6PÐ5QÐRÐRr   c                 óò   — | €t        j                  «       S t        | t         j                  «      r0t        j                  | j                  «      }| |urt        d«      ‚| S t        dt        | «      › d�«      ‚)z3Returns a reference to an initialized App instance.zKIllegal 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Ñ0°·±Ó:ˆØ�oÑ%Üð Dó Eð Eàˆ
ä
ð	Ü�‹Iˆ;�bð	óð r   c                 ó<   — t        | «      } | j                  ||«      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                  «       }|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-   r/   r1   Ú
error_dictÚmessageÚexcs           r   Ú#handle_platform_error_from_requestsr:   k   s   € ð ‡~�~ÐÜ$ UÓ+Ð+à�~‰~€HØ×Ñ×%Ñ%Ó'€GØ×&Ñ&€KÜ/°¸ÓEÑ€J�Ø
€CÙÙ˜% ¨*Ó5ˆáˆ3ÐLÔ0°¸ÀÓLÐLr   r5   r6   .Ú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-   r/   r0   r1   r2   Ú_handle_func_httpxÚhandle_httpx_errorr4   s           r   Ú handle_platform_error_from_httpxrA   †   s…   € ô$ �%œ×.Ñ.Ô/Ø—>‘>ˆØ×"Ñ"×)Ñ)Ó+ˆØ×*Ñ*ˆÜ3°G¸[ÓIÑˆ
�GØˆÙÙ˜e W¨jÓ9ˆCáˆsÐMÔ1°%¸À*ÓMÐMÜ˜eÓ$Ð$r   c                 óØ   — t        | t        «      st        j                  d| › �| ¬«      S | j	                  d«      }| j	                  d«      }t        |«      }t        |«      } ||¬«      S )zêConstructs 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   ¥   sk   € ô �eœTÔ"Ü×&Ñ&ØHÈÈÐPØôð 	ð �y‰y˜Ó €HØ�i‰i˜	Ó"€GÜ(¨Ó2€JÜ,¨ZÓ8€HÙ˜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)rI   r.   ©r5   r8   r7   rF   s       r   r3   r3   º   s!   € ð �>‰>˜(Ó#€DÜ  ¨°Ó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: rC   ©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Ñ4Ô5Ü×/Ñ/Ø:¸5¸'ÐBØôð 	ô �%œ×,Ñ,×<Ñ<Ô=Ü×*Ñ*Ø8¸¸Ð@Øôð 	ð ‡~�~ÐÜ×&Ñ&ØHÈÈÐPØôð 	ñ Ü)¨%¯.©.×*DÑ*DÓEˆÙÜ�e“*ˆä,¨TÓ2€HÙ˜G¨5ÀÇÁÔ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.
    rQ   )rI   r@   rR   s       r   r?   r?   ð   s!   € ð �>‰>˜(Ó#€DÜ˜e W¨dÓ3Ð3r   c                 óÖ  — t        | t        j                  «      rt        j                  d| › �| ¬«      S t        | t        j
                  «      rt        j                  d| › �| ¬«      S t        | t        j                  «      rN|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   rV   rC   )r   r=   ÚTimeoutExceptionr   rZ   ÚConnectErrorr\   r>   r]   r-   r1   r^   rK   rH   r_   s       r   r@   r@   ÿ   sØ   € ô$ �%œ×/Ñ/Ô0Ü×/Ñ/Ø:¸5¸'ÐBØôð 	ô �%œ×+Ñ+Ô,Ü×*Ñ*Ø8¸¸Ð@Øôð 	ô �%œ×.Ñ.Ô/ÙÜ-¨e¯n©n×.HÑ.HÓIˆDÙÜ˜%“jˆGä0°Ó6ˆÙ ¨uÀEÇNÁNÔSÐSä×"Ñ"ØDÀUÀGÐLØôð r   c                 óJ   — t         j                  | 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Ñ2DÓEÐEr   c                 óJ   — t         j                  | t        j                  «      S )z*Maps an RPC code to a platform error code.)Ú_RPC_CODE_TO_ERROR_CODErI   r   rf   )rL   s    r   rJ   rJ   *  s   € ä"×&Ñ& x´×1CÑ1CÓDÐDr   c                 óJ   — t         j                  | 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Ñ3JÓKÐKr   c                 óÖ   — i }	 t        j                  | «      }t        |t        «      r|}|j                  di «      }|j                  d«      }|sd|› d| › �}||fS # t        $ r Y Œ<w 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.
    r5   r8   z&Unexpected HTTP response with status: z; body: )ÚjsonÚloadsr   rG   r"   rI   )r/   r1   ÚdataÚparsed_bodyr7   Úmsgs         r   r2   r2   3  s~   € ð €DðÜ—j‘j Ó)ˆÜ�k¤4Ô(ØˆDð —‘˜' 2Ó&€JØ
�.‰.˜Ó
#€CÙØ6°{°mÀ8ÈGÈ9ÐUˆØ�sˆ?Ðøô ò Ùðús   „'A Á	A(Á'A(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   ry   z!EmulatorAdminCredentials.__init__V  s'   € Ü�‰×Ñ×+Ñ+×4Ñ4°TÔ:Øˆ�
r   c                  ó   — y r(   r   )r{   Úrequests     r   Úrefreshz EmulatorAdminCredentials.refreshZ  s   € Ør   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ry   r~   r   r   r   rr   rr   P  s   „ ñò
ór   rr   r(   )NN)Dr‚   rl   Úplatformr   Útypingr   r   Úgoogle.authru   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ÚDataLossErrorrf   rH   ÚINTERNALÚInternalErrorÚUNAVAILABLEr\   ÚDEADLINE_EXCEEDEDrZ   rj   re   rh   r   r&   r+   r:   Ú	HTTPErrorÚFirebaseErrorrA   rO   r3   r.   r?   r@   r]   rJ   rK   r2   rv   rw   rx   rr   r   r   r   ú<module>r¤      sq  ðñ 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òò$/ó
Mð: TXñ%Ø�‰ð%à˜h s¨H°Z×5MÑ5MÑ,NÐ'NÑOÑPð%ð ×Ñó%ò>%ò*7ó%PðN4˜eŸo™oð 4Àz×G_ÑG_ó 4ñ%˜eŸo™oð %È:×KcÑKcó %òNFòEòLò
ô:˜vŸ{™{×6Ñ6×BÑBõ r   