import re from typing import Optional from dataclasses import dataclass @dataclass class ContentDisposition: method: str filename: Optional[str] = None @classmethod def from_str(cls, disposition: str): m = re.match("(?P(inline)|(attachment))(;\\s*(filename=\"(?P.+)\"\\s*))?", disposition) if m is None: raise ValueError(f"Error while parsing disposition string '{ disposition }'.") d = m.groupdict() return cls(d["type"], d.get("filename", None)) def heading_sanitization(heading: str) -> str: """ Removes some parts of headings and path names. Currently these optimizations are done: - if the heading is "Inhalt" it is replaced by the empty string Otherwise the heading is returned as is. """ if heading == "Inhalt": return "" return heading