]>
jfr.im git - irc/quakenet/qwebirc.git/blob - qwebirc/root.py
1 from twisted
.web
import resource
, server
, static
, http
2 from twisted
.internet
import error
, reactor
8 class RootResource(resource
.Resource
):
9 def getChild(self
, name
, request
):
12 return self
.primaryChild
.getChild(name
, request
)
14 # we do NOT use the built-in timeOut mixin as it's very very buggy!
15 class TimeoutHTTPChannel(http
.HTTPChannel
):
16 timeout
= config
.HTTP_REQUEST_TIMEOUT
18 def connectionMade(self
):
19 self
.customTimeout
= reactor
.callLater(self
.timeout
, self
.timeoutOccured
)
20 http
.HTTPChannel
.connectionMade(self
)
22 def timeoutOccured(self
):
23 self
.customTimeout
= None
24 self
.transport
.loseConnection()
26 def cancelTimeout(self
):
27 if self
.customTimeout
is not None:
29 self
.customTimeout
.cancel()
30 self
.customTimeout
= None
31 except error
.AlreadyCalled
:
34 def connectionLost(self
, reason
):
36 http
.HTTPChannel
.connectionLost(self
, reason
)
38 class RootSite(server
.Site
):
39 # we do this ourselves as the built in timeout stuff is really really buggy
40 protocol
= TimeoutHTTPChannel
42 def __init__(self
, path
, *args
, **kwargs
):
44 server
.Site
.__init
__(self
, root
, *args
, **kwargs
)
47 services
["StaticEngine"] = root
.primaryChild
= engines
.StaticEngine(path
)
49 def register(service
, path
, *args
, **kwargs
):
50 sobj
= service("/" + path
, *args
, **kwargs
)
51 services
[service
.__name
__] = sobj
52 root
.putChild(path
, sobj
)
54 register(engines
.AJAXEngine
, "e")
55 register(engines
.FeedbackEngine
, "feedback")
56 register(engines
.AuthgateEngine
, "auth")
57 register(engines
.AdminEngine
, "adminengine", services
)
59 mimetypes
.types_map
[".ico"] = "image/vnd.microsoft.icon"