forked from PoolC/Yuzuki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (26 loc) · 1.04 KB
/
main.py
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
import logging
from twisted.web.resource import NoResource
from twisted.internet import reactor, endpoints
from route import ROUTE
from helper.site import YuzukiSite
from helper.resource import YuzukiResource
from resource.util import PageNotFound
class Main(YuzukiResource):
isLeaf = False
def __init__(self):
YuzukiResource.__init__(self)
for path in ROUTE:
self.putChild(path, ROUTE[path])
self.page_not_found = PageNotFound()
def getChildWithDefault(self, path, request):
resource = YuzukiResource.getChildWithDefault(self, path, request)
request.logger = logging.getLogger(resource.__class__.__module__)
log_str = request.method + " " + request.get_path_and_query()
if request.user:
log_str += " " + request.user.username
request.logger.info(log_str)
if isinstance(resource, NoResource):
return self.page_not_found
return resource
endpoints.serverFromString(reactor, "tcp:8080").listen(YuzukiSite(Main()))
reactor.run()