From 277017aea4cf72a1797102e6d129165181d04e17 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Thu, 4 Oct 2018 17:28:03 +0500 Subject: [PATCH] Simplified utils.text.StreamingBuffer. --- django/utils/text.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/django/utils/text.py b/django/utils/text.py index 8e0014fd0a..44007beb0f 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -280,26 +280,13 @@ def compress_string(s): return zbuf.getvalue() -class StreamingBuffer: - def __init__(self): - self.vals = [] - - def write(self, val): - self.vals.append(val) - +class StreamingBuffer(BytesIO): def read(self): - if not self.vals: - return b'' - ret = b''.join(self.vals) - self.vals = [] + ret = self.getvalue() + self.seek(0) + self.truncate() return ret - def flush(self): - return - - def close(self): - return - # Like compress_string, but for iterators of strings. def compress_sequence(sequence):