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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
from src import formatting
from time import time
def base():
return {
"error": False
}
def response(dictionary, usermap=None):
result = base()
result.update(dictionary)
if usermap:
result["usermap"] = usermap
return result
def error(code, description):
result = base()
result.update({
"error": {
"description": description, # string
"code": code # integer
}
})
return result
def user_internal(ID, auth_hash, name, quip, bio, admin):
if not quip:
quip = ""
if not bio:
bio = ""
return {
"user_id": ID, # string
"quip": quip, # (possibly empty) string
"bio": bio, # (possibly empty) string
"name": name, # string
"admin": admin, # boolean
"auth_hash": auth_hash # SHA256 string
}
def user_external(ID, name, quip, bio, admin):
if not quip:
quip = ""
if not bio:
bio = ""
return {
"user_id": ID, # string
"quip": quip, # (possibly empty) string
"name": name, # string
"bio": bio, # string
"admin": admin # boolean
}
def thread(ID, author, body, title, tags):
if not tags:
tags = list()
body = formatting.parse(body, doquotes=False)
now = time()
return {
"thread_id": ID, # string
"post_id": 1, # integer
"author": author, # string
"body": body, # string
"title": title, # string
"tags": tags, # (possibly empty) list of strings
"replies": list(), # (possibly empty) list of reply objects
"reply_count": 0, # integer
"edited": False, # boolean
"lastmod": now, # floating point unix timestamp
"created": now # floating point unix timestamp
}
def reply(ID, author, body):
body = formatting.parse(body)
now = time()
return {
"post_id": ID, # integer
"author": author, # string
"body": body, # string
"edited": False, # boolean
"lastmod": now, # floating point unix timestamp
"created": now # floating point unix timestamp
}
|