Beispiel #1
0
    def _worker(self):
        router = Router()

        for mountpoint, conf in self.config.get("locations", {}).items():
            conf.update(self.config)
            router.use(mountpoint, static(conf.get("root")))

        for code, page in self.config.get("error_pages", {}).items():
            def handler(err, req, res):
                if type(err) == HTTPError and err.code == code:
                    res.send_file(page)
                else: return True
            router.handler(handler)

        router.use(not_found)

        while True:
            req = Request(self)
            if not req or self.closed: break

            err = router(req, req.response)
            if err: break

        return self.close()