diff options
-rw-r--r-- | wsgitools/filters.py | 19 |
1 files 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 |