Coverage for src / kdbxtool / models / attachment.py: 82%
17 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-19 21:22 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-19 21:22 +0000
1"""Attachment model for KDBX binary attachments."""
3from __future__ import annotations
5from dataclasses import dataclass
6from typing import TYPE_CHECKING
8if TYPE_CHECKING:
9 from .entry import Entry
12@dataclass
13class Attachment:
14 """An attachment (binary file) associated with an entry.
16 Attachments represent files attached to entries in the database. The binary
17 data is stored at the database level and referenced by ID.
19 Attributes:
20 filename: Name of the attached file
21 id: Reference ID to the binary data in the database
22 entry: The entry this attachment belongs to
23 """
25 filename: str
26 id: int
27 entry: Entry
29 @property
30 def data(self) -> bytes | None:
31 """Get the binary data for this attachment.
33 Returns:
34 Binary data if available, None if not found or entry has no database
35 """
36 if self.entry.database is None:
37 return None
38 return self.entry.database.get_binary(self.id)
40 def __str__(self) -> str:
41 return f"Attachment: '{self.filename}' -> {self.id}"
43 def __repr__(self) -> str:
44 return f"Attachment(filename={self.filename!r}, id={self.id})"