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,)
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
crons | Folder | 0755 |
|
|
integrations | Folder | 0755 |
|
|
__init__.py | File | 1.03 KB | 0644 |
|
_compat.py | File | 2.73 KB | 0644 |
|
_functools.py | File | 4.84 KB | 0644 |
|
_lru_cache.py | File | 5.26 KB | 0644 |
|
_queue.py | File | 11 KB | 0644 |
|
_types.py | File | 2.19 KB | 0644 |
|
_werkzeug.py | File | 3.7 KB | 0644 |
|
api.py | File | 6.05 KB | 0644 |
|
attachments.py | File | 1.77 KB | 0644 |
|
client.py | File | 22.35 KB | 0644 |
|
consts.py | File | 8.49 KB | 0644 |
|
debug.py | File | 1.11 KB | 0644 |
|
envelope.py | File | 9.37 KB | 0644 |
|
hub.py | File | 26.42 KB | 0644 |
|
monitor.py | File | 2.97 KB | 0644 |
|
profiler.py | File | 33.18 KB | 0644 |
|
py.typed | File | 0 B | 0644 |
|
scope.py | File | 24.26 KB | 0644 |
|
scrubber.py | File | 3.8 KB | 0644 |
|
serializer.py | File | 12.97 KB | 0644 |
|
session.py | File | 5.43 KB | 0644 |
|
sessions.py | File | 5.76 KB | 0644 |
|
tracing.py | File | 29.04 KB | 0644 |
|
tracing_utils.py | File | 12 KB | 0644 |
|
tracing_utils_py2.py | File | 1.21 KB | 0644 |
|
tracing_utils_py3.py | File | 2.1 KB | 0644 |
|
transport.py | File | 18.13 KB | 0644 |
|
utils.py | File | 45.58 KB | 0644 |
|
worker.py | File | 4.15 KB | 0644 |
|