Fixed #32859 -- Simplified compress_string() by using gzip.compress().

This commit is contained in:
Illia Volochii 2021-06-17 19:36:44 +03:00 committed by Mariusz Felisiak
parent 225d96533a
commit 5a468b4c08
1 changed files with 2 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import html.entities
import re
import unicodedata
from gzip import GzipFile
from gzip import GzipFile, compress as gzip_compress
from io import BytesIO
from django.core.exceptions import SuspiciousFileOperation
@ -280,13 +280,8 @@ def phone2numeric(phone):
return ''.join(char2number.get(c, c) for c in phone.lower())
# From http://www.xhaus.com/alan/python/httpcomp.html#gzip
# Used with permission.
def compress_string(s):
zbuf = BytesIO()
with GzipFile(mode='wb', compresslevel=6, fileobj=zbuf, mtime=0) as zfile:
zfile.write(s)
return zbuf.getvalue()
return gzip_compress(s, compresslevel=6, mtime=0)
class StreamingBuffer(BytesIO):