def __call__(self, environ, start_response): req = Request(environ) self.logger.log(self.loglevel, 'request started') response = req.get_response(self.app) if self.inupy_config['ipfilter'] and not check_ipfilter(environ, self.inupy_config['ipfilter']): # then we want to filter on ip and this one failed pass else: self.logger.log(self.loglevel, 'request finished') if 'content-type' in response.headers and \ response.headers['content-type'].startswith('text/html'): controls_ui = self.render_html('/controls.mako', inupy_config=self.inupy_config) replacement = r'<body\1><script type="text/javascript">inupy_js</script>{0}'.format(controls_ui) response.body = re.sub(r'<body([^>]*)>', replacement, response.body) response.body = response.body.replace('inupy_js', get_js_code(self.tmpl_dir)) return response(environ, start_response)
def render(self, name, **vars): tmpl = self.mako.get_template(name) resp = tmpl.render(**vars) # inject in the js library code return resp.replace('inupy_js', get_js_code(self.tmpl_dir))