PHP 8.2.30
Preview: attachments.py Size: 1.77 KB
//opt/cloudlinux/venv/lib/python3.11/site-packages/sentry_sdk/attachments.py

import os
import mimetypes

from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.envelope import Item, PayloadRef

if TYPE_CHECKING:
    from typing import Optional, Union, Callable


class Attachment(object):
    def __init__(
        self,
        bytes=None,  # type: Union[None, bytes, Callable[[], bytes]]
        filename=None,  # type: Optional[str]
        path=None,  # type: Optional[str]
        content_type=None,  # type: Optional[str]
        add_to_transactions=False,  # type: bool
    ):
        # type: (...) -> None
        if bytes is None and path is None:
            raise TypeError("path or raw bytes required for attachment")
        if filename is None and path is not None:
            filename = os.path.basename(path)
        if filename is None:
            raise TypeError("filename is required for attachment")
        if content_type is None:
            content_type = mimetypes.guess_type(filename)[0]
        self.bytes = bytes
        self.filename = filename
        self.path = path
        self.content_type = content_type
        self.add_to_transactions = add_to_transactions

    def to_envelope_item(self):
        # type: () -> Item
        """Returns an envelope item for this attachment."""
        payload = None  # type: Union[None, PayloadRef, bytes]
        if self.bytes is not None:
            if callable(self.bytes):
                payload = self.bytes()
            else:
                payload = self.bytes
        else:
            payload = PayloadRef(path=self.path)
        return Item(
            payload=payload,
            type="attachment",
            content_type=self.content_type,
            filename=self.filename,
        )

    def __repr__(self):
        # type: () -> str
        return "<Attachment %r>" % (self.filename,)

Directory Contents

Dirs: 3 × Files: 29

Name Size Perms Modified Actions
crons DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:07:29
Edit Download
6.05 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.77 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
22.35 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
8.49 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.11 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
9.37 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
26.42 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.97 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
33.18 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
0 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
24.26 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.80 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
12.97 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.43 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.76 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
29.04 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
12.00 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.21 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.10 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
18.13 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
45.58 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.15 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.73 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.84 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.26 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
11.00 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.19 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.70 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.03 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).