ilias-sync2/ilias_sync2/utils.py
2022-03-29 15:13:31 +02:00

37 lines
873 B
Python

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<type>(inline)|(attachment))(;\\s*(filename=\"(?P<filename>.+)\"\\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