PHP 8.0.30
Preview: attachments.py Size: 1.75 KB
/opt/alt/python37/lib/python3.7/site-packages/sentry_sdk/attachments.py

import os
import mimetypes

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

if MYPY:
    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: 2 × Files: 21

Name Size Perms Modified Actions
- drwxr-xr-x 2023-12-06 03:19:43
Edit Download
- drwxr-xr-x 2023-12-06 03:19:43
Edit Download
4.66 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
1.75 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
13.64 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
3.60 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
1.11 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
8.35 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
21.62 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
0 B lrw-r--r-- 2021-07-27 14:04:04
Edit Download
15.62 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
15.92 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
5.41 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
5.69 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
25.22 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
12.13 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
26.79 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
4.04 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
2.30 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
2.22 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
8.21 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
1.24 KB lrw-r--r-- 2021-07-27 14:04:04
Edit Download
854 B lrw-r--r-- 2021-07-27 14:04:04
Edit Download

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