-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathextras.py
61 lines (38 loc) · 1.58 KB
/
extras.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
FORMAT_HTML = "html"
FORMAT_IMAGE = "image"
FORMAT_JSON = "json"
FORMAT_TEXT = "text"
FORMAT_URL = "url"
FORMAT_VIDEO = "video"
FORMAT_BINARY = "binary"
def extra(content, format_type, name=None, mime_type=None, extension=None):
return {
"name": name,
"format_type": format_type,
"content": content,
"mime_type": mime_type,
"extension": extension,
}
def html(content):
return extra(content, FORMAT_HTML)
def image(content, name="Image", mime_type="image/png", extension="png"):
return extra(content, FORMAT_IMAGE, name, mime_type, extension)
def png(content, name="Image"):
return image(content, name, mime_type="image/png", extension="png")
def jpg(content, name="Image"):
return image(content, name, mime_type="image/jpeg", extension="jpg")
def svg(content, name="Image"):
return image(content, name, mime_type="image/svg+xml", extension="svg")
def json(content, name="JSON"):
return extra(content, FORMAT_JSON, name, "application/json", "json")
def text(content, name="Text"):
return extra(content, FORMAT_TEXT, name, "text/plain", "txt")
def url(content, name="URL"):
return extra(content, FORMAT_URL, name)
def video(content, name="Video", mime_type="video/mp4", extension="mp4"):
return extra(content, FORMAT_VIDEO, name, mime_type, extension)
def mp4(content, name="Video"):
return video(content, name)