gws.lib.mime¶
MIME types.
Defines constants for the MIME types used in the application (PNG, JSON, GML3
and so on) and functions to normalize MIME types and to map them to and from file extensions.
get accepts a MIME type, a content type with parameters, a known alias (e.g.
application/vnd.ogc.gml or image/jpg) or a file extension, and returns a normalized
MIME type. Lookups that are not covered by the built-in tables fall back to the standard
mimetypes module.
Example:
gws.lib.mime.get('image/jpg') # 'image/jpeg'
gws.lib.mime.get('png') # 'image/png'
gws.lib.mime.for_path('/data/report.pdf') # 'application/pdf'
gws.lib.mime.extension_for(gws.lib.mime.JPEG) # 'jpeg'
Source code: gws.lib.mime
Package Contents¶
- gws.lib.mime.BIN = 'application/octet-stream'¶
- gws.lib.mime.CSS = 'text/css'¶
- gws.lib.mime.CSV = 'text/csv'¶
- gws.lib.mime.DOC = 'application/msword'¶
- gws.lib.mime.DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'¶
- gws.lib.mime.extension_for(mt: str, default: str = 'bin') str¶
Return the file extension for a MIME type.
- Parameters:
mt – Normalized MIME type.
default – Extension to return if the MIME type is unknown.
- Returns:
The extension, without a dot.
- gws.lib.mime.for_path(path: str) str¶
Return the MIME type for a file path, based on its extension.
- Parameters:
path – File path or name.
- Returns:
The MIME type, or
BINif it is unknown.
- gws.lib.mime.GEOJSON = 'application/geo+json'¶
- gws.lib.mime.get(mt: str) str | None¶
Return the normalized MIME type.
- Parameters:
mt – MIME type, content type, alias or file extension. Case and spaces are ignored.
- Returns:
The normalized MIME type, or
Noneif it is unknown.
- gws.lib.mime.GIF = 'image/gif'¶
- gws.lib.mime.GML = 'application/gml+xml'¶
- gws.lib.mime.GML2 = 'application/gml+xml;version=2'¶
- gws.lib.mime.GML3 = 'application/gml+xml;version=3'¶
- gws.lib.mime.GZIP = 'application/gzip'¶
- gws.lib.mime.HTML = 'text/html'¶
- gws.lib.mime.JPEG = 'image/jpeg'¶
- gws.lib.mime.JS = 'application/javascript'¶
- gws.lib.mime.JSON = 'application/json'¶
- gws.lib.mime.KML = 'application/vnd.google-earth.kml+xml'¶
- gws.lib.mime.PDF = 'application/pdf'¶
- gws.lib.mime.PNG = 'image/png'¶
- gws.lib.mime.PPT = 'application/vnd.ms-powerpoint'¶
- gws.lib.mime.PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'¶
- gws.lib.mime.SVG = 'image/svg+xml'¶
- gws.lib.mime.TTF = 'application/x-font-ttf'¶
- gws.lib.mime.TXT = 'text/plain'¶
- gws.lib.mime.WEBP = 'image/webp'¶
- gws.lib.mime.XLS = 'application/vnd.ms-excel'¶
- gws.lib.mime.XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'¶
- gws.lib.mime.XML = 'text/xml'¶
- gws.lib.mime.ZIP = 'application/zip'¶