ilias-sync2/ilias_sync2/utils.py
Johannes Erwerle 0849c0363a squashed all commits
added parsing for mathematical foundations recordings

added filepath sanitization

worked around the changing login URL

added streaming of requests for large downloads

added gitignore

added example
2022-11-03 15:18:14 +01:00

40 lines
937 B
Python

import re
from typing import Optional
from dataclasses import dataclass
from pathvalidate import sanitize_filepath
@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 sanitize_filepath(heading)