def __call__(self, environ, start_response): now = time.time() if is_gui_url(environ): gui = DebugGui(self) return gui(environ, start_response) request_id = id(environ) request_info = self.get_request_info(environ) request_info['begin'] = now self.log_request_begin(request_id, request_info) entry = {} entry['id'] = request_id entry['request'] = request_info if self.keep: self.lock.acquire() try: if len(self.entries) >= self.keep: self.entries.pop(0) self.entries.append(entry) finally: self.lock.release() catch_response = [] written = [] def replace_start_response(status, headers, exc_info=None): catch_response.append([status, headers]) start_response(status, headers, exc_info) return written.append app_iter = self.application(environ, replace_start_response) received_response = time.time() if catch_response: status, headers = catch_response[0] else: status = '500 Start Response Not Called' headers = [] response_info = self.get_response_info(status, headers) response_info['begin'] = received_response entry['response'] = response_info close = getattr(app_iter, 'close', None) body = itertools.chain(written, app_iter) body = self.log_response(request_id, request_info, response_info, body, close) return body
def _callFUT(self, environ): from repoze.debug.ui import is_gui_url return is_gui_url(environ)