9 UNKNOWN
, TEXT
, SKETCH
, CHECKLIST
= range(4)
11 class NodeFlag(object):
13 SKETCHLINES
, SKETCHGRAPH
, WORDRAP
= (1 << x
for x
in range(3))
15 class ChecklistStyle(object):
16 CHECKED
, BOLD
, STRIKE
= (1 << x
for x
in range(3))
18 class checklists(object):
30 c
= lambda a
, b
: cmp((a
.ord, a
.idx
), (b
.ord, b
.idx
))
50 c
= lambda a
, b
: cmp(a
.ord, b
.ord)
54 class MaePadServer(BaseHTTPServer
.BaseHTTPRequestHandler
):
57 def start_output(self
, status
=200, content_type
='text/html'):
58 self
.send_response(status
)
59 self
.send_header('Content-type', content_type
)
62 def send_json(self
, data
):
63 self
.start_output(content_type
='text/plain')
64 self
.wfile
.write(json
.dumps(data
))
67 def send_html(self
, data
):
68 self
.start_output(content_type
='text/html')
69 self
.wfile
.write(data
)
72 def _nodelist__json(self
):
73 self
.send_json([(x
.nodeid
, x
.name
, x
.bodytype
) for x
in self
.db
.load(MaePad
.nodes
)])
76 url
= urlparse
.urlparse(self
.path
)
77 query
= urlparse
.parse_qs(url
.query
)
78 path
= filter(None, url
.path
.split('/'))
85 self
.start_output(404, 'text/plain')
86 self
.wfile
.write("404'd!")
90 self
.send_html('<h1>yo</h1>')
92 attr_name
= '_' + mode
.replace('.', '__')
93 if hasattr(self
, attr_name
):
94 getattr(self
, attr_name
)()
97 #if __name__ == '__main__':
98 # db = minidb.Store('memos.db')
99 # for node in MaePad.nodes.sorted(db.load(MaePad.nodes)):
101 # if node.bodytype == MaePad.Node.CHECKLIST:
102 # for item in MaePad.checklists.sorted(
103 # db.load(MaePad.checklists, nodeid=node.nodeid)):
104 # if item.style == MaePad.ChecklistStyle.CHECKED:
105 # print ' XX ', item.name
107 # print ' ', item.name
109 MaePadServer
.db
= minidb
.Store('memos.db')
111 server
= BaseHTTPServer
.HTTPServer(('', 8888), MaePadServer
)
112 server
.serve_forever()