PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/web/acldemo.py

https://bitbucket.org/prologic/circuits/
Python | 35 lines | 17 code | 10 blank | 8 comment | 3 complexity | c469d37e3fa33cbf808ca92ca6c80312 MD5 | raw file
 1#!/usr/bin/env python
 2
 3from circuits import handler, Component
 4from circuits.web.errors import Forbidden
 5from circuits.web import Server, Controller
 6
 7
 8class ACL(Component):
 9
10    allowed = ["127.0.0.1"]
11
12    @handler("request", priority=1.0)
13    def on_request(self, event, request, response):
14        """Filter Requests applying IP based Authorization
15
16        Filter any incoming requests at a higher priority than the
17        default dispatcher and apply IP based Authorization returning
18        a 403 Forbidden response if the Remote IP Address does not
19        match the allowed set.
20        """
21
22        if not request.remote.ip in self.allowed:
23            event.stop()
24            return Forbidden(request, response)
25
26
27class Root(Controller):
28
29    def index(self):
30        return "Hello World!"
31
32app = Server(("0.0.0.0", 8000))
33ACL().register(app)
34Root().register(app)
35app.run()