관리-도구
편집 파일: attachments.cpython-38.pyc
U �Mg% � @ sV d dl Z d dlZd dlmZmZ d dlmZ erDd dlmZmZm Z G dd� d�Z dS )� N)�Item� PayloadRef)� TYPE_CHECKING)�Optional�Union�Callablec @ s* e Zd ZdZd dd�Zdd� Zdd � ZdS )� Attachmenta Additional files/data to send along with an event. This class stores attachments that can be sent along with an event. Attachments are files or other data, e.g. config or log files, that are relevant to an event. Attachments are set on the ``Scope``, and are sent along with all non-transaction events (or all events including transactions if ``add_to_transactions`` is ``True``) that are captured within the ``Scope``. To add an attachment to a ``Scope``, use :py:meth:`sentry_sdk.Scope.add_attachment`. The parameters for ``add_attachment`` are the same as the parameters for this class's constructor. :param bytes: Raw bytes of the attachment, or a function that returns the raw bytes. Must be provided unless ``path`` is provided. :param filename: The filename of the attachment. Must be provided unless ``path`` is provided. :param path: Path to a file to attach. Must be provided unless ``bytes`` is provided. :param content_type: The content type of the attachment. If not provided, it will be guessed from the ``filename`` parameter, if available, or the ``path`` parameter if ``filename`` is ``None``. :param add_to_transactions: Whether to add this attachment to transactions. Defaults to ``False``. NFc C s| |d kr|d krt d��|d kr4|d k r4tj�|�}|d krDt d��|d krZt�|�d }|| _|| _|| _|| _|| _ d S )Nz)path or raw bytes required for attachmentz#filename is required for attachmentr ) � TypeError�os�path�basename� mimetypes� guess_type�bytes�filename�content_type�add_to_transactions)�selfr r r r r � r �D/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/attachments.py�__init__ s zAttachment.__init__c C sJ d}| j dk r*t| j �r"| � � }q6| j }nt| jd�}t|d| j| jd�S )z-Returns an envelope item for this attachment.N)r � attachment)�payload�typer r )r �callabler r r r r )r r r r r �to_envelope_item7 s �zAttachment.to_envelope_itemc C s d| j f S )Nz<Attachment %r>)r )r r r r �__repr__I s zAttachment.__repr__)NNNNF)�__name__� __module__�__qualname__�__doc__r r r r r r r r s � r )r r Zsentry_sdk.enveloper r �typingr r r r r r r r r �<module> s