-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.py
More file actions
28 lines (22 loc) · 771 Bytes
/
sample.py
File metadata and controls
28 lines (22 loc) · 771 Bytes
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
#-*- coding: utf-8 -*-
import pyserver
handler = pyserver.URLHandler()
@handler.url('/$')
def toppage(handler, match) :
handler.send_headers()
handler.wfile.write('<html><body><b>')
handler.wfile.write('Welcome to pyserver')
handler.wfile.write('</b></body></html>')
@handler.url('/json')
def json(handler, match) :
handler.send_headers({'Content-Type' : 'application/json'})
handler.wfile.write('{"key1" : 1, "key2" : 2}')
@handler.url('/streaming')
def streaming(handler, match) :
import time
handler.send_headers({'Content-Type' : 'text/event-stream'})
for i in range(10) :
handler.wfile.write('response %d\r\n' % i)
time.sleep(1)
if __name__ == '__main__' :
pyserver.runserver(handler, 'localhost', 8080)