Pyjoyment.Types - MIME types¶
from Pyjoyment.Types import Types
types = Types()
types.type('foo', 'text/foo')
print(types.type('foo'))
# Or import the module, as in Google Python Style Guide
import Pyjoyment.Types
types = Pyjoyment.Types.new()
types.type('foo', 'text/foo')
print(types.type('foo'))
Pyjoyment.Types manages MIME types for Pyjoyment.
appcache -> text/cache-manifest
atom -> application/atom+xml
bin -> application/octet-stream
css -> text/css
gif -> image/gif
gz -> application/x-gzip
htm -> text/html
html -> text/html;charset=UTF-8
ico -> image/x-icon
jpeg -> image/jpeg
jpg -> image/jpeg
js -> application/javascript
json -> application/json;charset=UTF-8
mp3 -> audio/mpeg
mp4 -> video/mp4
ogg -> audio/ogg
ogv -> video/ogg
pdf -> application/pdf
png -> image/png
rss -> application/rss+xml
sse -> text/event-stream
svg -> image/svg+xml
toml -> application/toml;charset=UTF-8
ttf -> font/ttf
txt -> text/plain;charset=UTF-8
webm -> video/webm
woff -> font/woff
woff2 -> font/woff2
xml -> application/xml,text/xml
yaml -> application/yaml;charset=UTF-8,text/yaml,application/x-yaml,text/x-yaml
zip -> application/zip
The most common ones are already defined.
See also¶
Pyjoyment, https://mojolicious.org.
Ported from Mojolicious::Types of Mojolicious 9.49.
- class Pyjoyment.Types.Pyjoyment_Types(mapping: dict[str, list[str]] | None = None)[source]¶
Pyjoyment.Typesinherits all methods fromPyjo.Baseand implements the following new ones.- content_type(c: Pyjoyment.Controller.object, *, ext: str | None = None, file: str | PathLike[str] | None = None) Pyjo.Headers.object | None[source]¶
types.content_type(Pyjoyment.Controller.new(), ext='json')
Detect MIME type for
Pyjoyment.Controllerobject unless aContent-Typeresponse header has already been set, defaults to usingapplication/octet-streamif no better alternative could be found. These options are currently available:- ext
ext='json'
File extension to get MIME type for.
- file
file='foo/bar.png'
File path to get MIME type for.
- detect(accept: str | None) list[str][source]¶
exts = types.detect('text/html, application/json;q=9')
Detect file extensions from
Acceptheader value.# List detected extensions prioritized for ext in types.detect('application/json, text/xml;q=0.1'): print(ext)
- file_type(file: str | PathLike[str]) str | None[source]¶
type = types.file_type('foo/bar.png')
Get MIME type for file path.
- mapping: dict[str, list[str]]¶
mapping = types.mapping types.mapping = {'png': ['image/png']}
MIME type mapping.