-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
35 lines (25 loc) · 840 Bytes
/
Copy pathserver.py
File metadata and controls
35 lines (25 loc) · 840 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
29
30
31
32
33
34
35
from random import choice
from twisted.web import server, resource
from twisted.internet import reactor
import time
class Uninspiring(Exception):
pass
class Magnificent(resource.Resource):
isLeaf = True
def render_GET(self, request):
if choice([True, True, True, False]):
if choice([True, True, False]):
print('Magnificent')
return "Magnificent!".encode('utf-8') # Twisted expects bytes.
else:
print('Something else')
return "Something else".encode('utf-8') # Twisted expects bytes.
else:
raise Uninspiring()
class run():
site = server.Site(Magnificent())
# https://www.youtube.com/watch?v=a6iW-8xPw3k
reactor.listenTCP(12345, site)
reactor.run()
if __name__ == "__main__":
run()