def finish_response(self, app_iter): if not self.scale: self.start_response(self.status, self.headers) self.output = app_iter return CONTENT_LENGTH.delete(self.headers) inBuffer = StringIO() try: for s in app_iter: self.logger.debug("Writing %d bytes into image buffer." % len(s)) inBuffer.write(s) finally: if hasattr(app_iter, 'close'): app_iter.close() rawImg = Blob() rawImg.data = inBuffer.getvalue() inBuffer.close() image = Image(rawImg) self.logger.debug("Scaling image to %s" % self.scaled_size) image.scale(self.scaled_size[0]) image.write(self.outbuffer) content_length = self.outbuffer.length() CONTENT_LENGTH.update(self.headers, content_length) CACHE_CONTROL.update(self.headers, s_maxage=CACHE_CONTROL.ONE_HOUR) self.start_response(self.status, self.headers)
def scaler_start_response(self, status, headers, exc_info=None): if status.startswith('304'): CONTENT_LENGTH.delete(self.headers) if not status.startswith('2'): self.scale = False self.headers = headers self.status = status return self.outbuffer.data
def auth_form(environ, start_response): towrite = "Challenging this" content_length = CONTENT_LENGTH.tuples(str(len(towrite))) content_type = CONTENT_TYPE.tuples('text/html') headers = content_length + content_type + forget_headers start_response('200 OK', headers) return [towrite]
def process(self, compress_level, start_response): if self.app_iter is not None: output = gzip.GzipFile( mode='wb', compresslevel=compress_level, fileobj=self.buffer) if self.compressible else self.buffer [output.write(s) for s in self.app_iter] self.compressible and output.close() content_length = self.buffer.tell() CONTENT_LENGTH.update(self.headers, content_length) start_response(self.status, self.headers) content = self.content() self.append(content) else: start_response(self.status, self.headers) return
def finish_response(self, app_iter): if self.compressible: output = gzip.GzipFile(mode="wb", compresslevel=self.compress_level, fileobj=self.buffer) else: output = self.buffer try: for s in app_iter: output.write(s) if self.compressible: output.close() finally: if hasattr(app_iter, "close"): app_iter.close() content_length = self.buffer.tell() CONTENT_LENGTH.update(self.headers, content_length) self.start_response(self.status, self.headers)
def finish_response(self, app_iter): if self.compressible: output = gzip.GzipFile(mode='wb', compresslevel=self.compress_level, fileobj=self.buffer) else: output = self.buffer try: for s in app_iter: output.write(s) if self.compressible: output.close() finally: if hasattr(app_iter, 'close'): app_iter.close() content_length = self.buffer.tell() CONTENT_LENGTH.update(self.headers, content_length) self.start_response(self.status, self.headers)
def auth_resp(environ, start_response): import json resp = {"success": True} resp_str = json.dumps(resp) content_length = CONTENT_LENGTH.tuples(str(len(resp_str))) content_type = CONTENT_TYPE.tuples('application/json') headers = content_length + content_type start_response('200 OK', headers) return [resp_str]
def auth_resp(environ, start_response): import json resp = { "success": True } resp_str = json.dumps(resp) content_length = CONTENT_LENGTH.tuples(str(len(resp_str))) content_type = CONTENT_TYPE.tuples('application/json') headers = content_length + content_type start_response('200 OK', headers) return [resp_str]
def auth_form(environ, start_response): content_length = CONTENT_LENGTH.tuples(str(len(form))) content_type = CONTENT_TYPE.tuples('text/html') headers = content_length + content_type + forget_headers start_response('200 OK', headers) return [form]
def getContentLength(self, request): return CONTENT_LENGTH(request.environ())