]> jfr.im git - irc/quakenet/qwebirc.git/blame - qwebirc/engines/staticengine.py
Merge pull request #402 from retropc/reqs
[irc/quakenet/qwebirc.git] / qwebirc / engines / staticengine.py
CommitLineData
99844c15 1from twisted.web import resource, server, static, error
85f01e3f
CP
2import qwebirc.util as util
3import pprint
4from adminengine import AdminEngineAction
40a2a18f
CP
5try:
6 from twisted.web.server import GzipEncoderFactory
7 GZIP_ENCODER = GzipEncoderFactory()
8except ImportError:
9 GZIP_ENCODER = None
85f01e3f
CP
10
11# TODO, cache gzip stuff
12cache = {}
13def clear_cache():
14 global cache
15 cache = {}
16
85f01e3f
CP
17class StaticEngine(static.File):
18 isLeaf = False
19 hit = util.HitCounter()
20
21 def __init__(self, *args, **kwargs):
22 static.File.__init__(self, *args, **kwargs)
40a2a18f 23
85f01e3f
CP
24 def render(self, request):
25 self.hit(request)
40a2a18f
CP
26# temporarily disabled -- seems to eat big pages
27# if GZIP_ENCODER:
28# request._encoder = GZIP_ENCODER.encoderForRequest(request) # HACK
85f01e3f
CP
29 return static.File.render(self, request)
30
31 @property
32 def adminEngine(self):
33 return {
34 #"GZip cache": [
35 #("Contents: %s" % pprint.pformat(list(cache.keys())),)# AdminEngineAction("clear", d))
36 #],
37 "Hits": [
38 (self.hit,),
39 ]
40 }
99844c15
CP
41
42 def directoryListing(self):
43 return error.ForbiddenResource()