diff options
author | Helmut Grohne <helmut@subdivi.de> | 2008-04-27 00:27:13 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2008-04-27 00:27:13 +0200 |
commit | d9f8f1d19c08729b0589ffc9260b9323a7c87369 (patch) | |
tree | 30f50a7c45f8605ba3dc2f5b6333993374aee915 | |
parent | acc00d6595e238c7915ef31677ca64535d56ff13 (diff) | |
download | wsgitools-d9f8f1d19c08729b0589ffc9260b9323a7c87369.tar.gz |
added flush parameter to GzipWSGIFilter
-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 |