File: compression.py

package info (click to toggle)
circuits 3.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,980 kB
  • sloc: python: 17,583; javascript: 3,226; makefile: 100
file content (29 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
# Examples:
# curl http://127.0.0.1:8000/ -i -H 'Accept-Encoding: gzip'
# curl http://127.0.0.1:8000/ -i -H 'Accept-Encoding: deflate'
# curl http://127.0.0.1:8000/ -i -H 'Accept-Encoding: identity'

from circuits import Component, Debugger, handler
from circuits.web import Server
from circuits.web.controllers import BaseController, expose
from circuits.web.tools import gzip


class Gzip(Component):
    @handler('response', priority=1.0)
    def compress_response(self, event, response):
        event[0] = gzip(response)


class Root(BaseController):
    @expose('index')
    def index(self):
        return 'Hello World! This is some test string which is compressed using gzip-4 if you want!'


app = Server(('0.0.0.0', 8000))
Root().register(app)
Gzip().register(app)
Debugger().register(app)
app.run()