403Webshell
Server IP : 66.29.153.156  /  Your IP : 216.73.216.223
Web Server : LiteSpeed
System : Linux premium322.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User : lastyfjz ( 1521)
PHP Version : 8.1.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /././opt/hc_python/lib64/python3.12/site-packages/sentry_sdk/integrations/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /././opt/hc_python/lib64/python3.12/site-packages/sentry_sdk/integrations/excepthook.py
import sys
from typing import TYPE_CHECKING

import sentry_sdk
from sentry_sdk.integrations import Integration
from sentry_sdk.utils import (
    capture_internal_exceptions,
    event_from_exception,
)

if TYPE_CHECKING:
    from types import TracebackType
    from typing import Any, Callable, Optional, Type

    Excepthook = Callable[
        [Type[BaseException], BaseException, Optional[TracebackType]],
        Any,
    ]


class ExcepthookIntegration(Integration):
    identifier = "excepthook"

    always_run = False

    def __init__(self, always_run: bool = False) -> None:
        if not isinstance(always_run, bool):
            raise ValueError(
                "Invalid value for always_run: %s (must be type boolean)"
                % (always_run,)
            )
        self.always_run = always_run

    @staticmethod
    def setup_once() -> None:
        sys.excepthook = _make_excepthook(sys.excepthook)


def _make_excepthook(old_excepthook: "Excepthook") -> "Excepthook":
    def sentry_sdk_excepthook(
        type_: "Type[BaseException]",
        value: BaseException,
        traceback: "Optional[TracebackType]",
    ) -> None:
        integration = sentry_sdk.get_client().get_integration(ExcepthookIntegration)

        # Note: If  we replace this with ensure_integration_enabled then
        # we break the exceptiongroup backport;
        # See: https://github.com/getsentry/sentry-python/issues/3097
        if integration is None:
            return old_excepthook(type_, value, traceback)

        if _should_send(integration.always_run):
            with capture_internal_exceptions():
                event, hint = event_from_exception(
                    (type_, value, traceback),
                    client_options=sentry_sdk.get_client().options,
                    mechanism={"type": "excepthook", "handled": False},
                )
                sentry_sdk.capture_event(event, hint=hint)

        return old_excepthook(type_, value, traceback)

    return sentry_sdk_excepthook


def _should_send(always_run: bool = False) -> bool:
    if always_run:
        return True

    if hasattr(sys, "ps1"):
        # Disable the excepthook for interactive Python shells, otherwise
        # every typo gets sent to Sentry.
        return False

    return True

Youez - 2016 - github.com/yon3zu
LinuXploit