ai-server/source/utils/mimetypes.py

21 lines
No EOL
579 B
Python

def is_textlike(mimetype: str) -> bool:
"""
Determinate if a mimetype is considered as holding text
:param mimetype: the mimetype to check
:return: True if the mimetype represent text, False otherwise
"""
# check the family of the mimetype
if mimetype.startswith("text/"):
return True
# check applications formats that are text formatted
if mimetype in [
"application/xml",
"application/json",
"application/javascript"
]:
return True
# otherwise consider the file as non-text
return False