mirror of
https://github.com/django/django.git
synced 2025-09-23 02:33:31 +00:00
Fixed #7581 -- Added streaming responses.
Thanks mrmachine and everyone else involved on this long-standing ticket.
This commit is contained in:
parent
300d052713
commit
4b27813198
18 changed files with 533 additions and 75 deletions
|
@ -288,6 +288,37 @@ def compress_string(s):
|
|||
zfile.close()
|
||||
return zbuf.getvalue()
|
||||
|
||||
class StreamingBuffer(object):
|
||||
def __init__(self):
|
||||
self.vals = []
|
||||
|
||||
def write(self, val):
|
||||
self.vals.append(val)
|
||||
|
||||
def read(self):
|
||||
ret = b''.join(self.vals)
|
||||
self.vals = []
|
||||
return ret
|
||||
|
||||
def flush(self):
|
||||
return
|
||||
|
||||
def close(self):
|
||||
return
|
||||
|
||||
# Like compress_string, but for iterators of strings.
|
||||
def compress_sequence(sequence):
|
||||
buf = StreamingBuffer()
|
||||
zfile = GzipFile(mode='wb', compresslevel=6, fileobj=buf)
|
||||
# Output headers...
|
||||
yield buf.read()
|
||||
for item in sequence:
|
||||
zfile.write(item)
|
||||
zfile.flush()
|
||||
yield buf.read()
|
||||
zfile.close()
|
||||
yield buf.read()
|
||||
|
||||
ustring_re = re.compile("([\u0080-\uffff])")
|
||||
|
||||
def javascript_quote(s, quote_double_quotes=False):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue