chiark / gitweb /
debug good
[hippotat.git] / example.py
1 from twisted.internet import reactor, endpoints
2 from twisted.web.server import Site
3 from twisted.web.resource import Resource
4 import time
5
6 class ClockPage(Resource):
7     isLeaf = True
8     def render_GET(self, request):
9         request.setHeader("Content-Type", "text/plain; charset=utf-8")
10         return (
11             ("<html><body>%s</body></html>" % (time.ctime(),))
12             .encode('utf-8')
13         )
14
15 resource = ClockPage()
16 factory = Site(resource)
17 endpoint = endpoints.TCP4ServerEndpoint(reactor, 8880)
18 endpoint.listen(factory)
19 reactor.run()