From d9f8f1d19c08729b0589ffc9260b9323a7c87369 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 27 Apr 2008 00:27:13 +0200 Subject: added flush parameter to GzipWSGIFilter --- wsgitools/filters.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/wsgitools/filters.py b/wsgitools/filters.py index efba982..32a0a46 100644 --- a/wsgitools/filters.py +++ b/wsgitools/filters.py @@ -315,8 +315,22 @@ class EncodeWSGIFilter(BaseWSGIFilter): __all__.append("GzipWSGIFilter") class GzipWSGIFilter(BaseWSGIFilter): """Compresses content using gzip.""" - def __init__(self): + @classmethod + def creator(cls, flush=True): + """ + Returns a function creating GzipWSGIFilters. + @type flush: bool + @param flush: whether or not the filter should always flush the buffer + """ + return lambda:cls(flush) + def __init__(self, flush=True): + """ + @type flush: bool + @param flush: when true does not pump data necessarily immediately but + accumulate to get a better compression ratio + """ BaseWSGIFilter.__init__(self) + self.flush = flush self.compress = False self.sio = None self.gzip = None @@ -350,7 +364,8 @@ class GzipWSGIFilter(BaseWSGIFilter): if not self.compress: return data self.gzip.write(data) - self.gzip.flush() + if self.flush: + self.gzip.flush() data = self.sio.getvalue() self.sio.truncate(0) return data -- cgit v1.2.3