blob: 2583f475ddd17402abc7b974a508c62cc3808244 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
from __future__ import annotations
import logging
import textwrap
from pathlib import Path
from . import _types as _t
log = logging.getLogger(__name__)
def data_from_mime(path: _t.PathT) -> dict[str, str]:
content = Path(path).read_text(encoding="utf-8")
log.debug("mime %s content:\n%s", path, textwrap.indent(content, " "))
# the complex conditions come from reading pseudo-mime-messages
data = dict(x.split(": ", 1) for x in content.splitlines() if ": " in x)
log.debug("mime %s data:\n%s", path, data)
return data
|