def __call__(self, *args, **kwargs): out = Out(self) args = args[:2] if len(args) == 2: if isinstance(args[0], (str, unicode)): self.content_type = args[0].strip() if isinstance(args[1], dict): kwargs.update(args[1]) if len(args) == 1: if isinstance(args[0], (str, unicode)): self.content_type = args[0].strip() if isinstance(args[0], dict): kwargs.update(args[0]) self.content_type = kwargs.pop("Content_Type", None) or self.content_type self.fvars = dict(self.fvars, **kwargs) from pweb import http if 'headers' in http.request and self.content_type: http.header("Content-type", self.content_type, unique=True) env = self.make_env(out, *args, **self.fvars) if isinstance(self.source_code, (str, unicode)): code = compile(self.source_code, self.filename, 'exec') exec(code, env) return out.getvalue()
def wsgi(env, start_resp): # clear threadlocal to avoid inteference of previous requests self._cleanup() self.load(env) try: # allow uppercase methods only if http.request.method.upper() != http.request.method: raise http.nomethod() result = self.handle_with_processors() if isinstance(result, tuple) and len(result)==2: content_type, result = result[0], [result[1]] http.header("Content-type", content_type, unique=True) elif is_generator(result): result = peep(result) else: result = [result] except http.HTTPError, e: result = [e.data]