initial commit
This commit is contained in:
commit
4742e417f7
7 changed files with 345 additions and 0 deletions
37
ilias_sync2/utils.py
Normal file
37
ilias_sync2/utils.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue