Use tempfile.SpooledTemporaryFile() instead of raw BytesIO (#767)

* Use tempfile.SpooledTemporaryFile() instead of raw BytesIO
* Fix test to call .read() instead of .getvalue()
This commit is contained in:
Kevin Chung
2018-11-29 23:45:23 -05:00
committed by GitHub
parent f03c304286
commit c342ca85b4
2 changed files with 3 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ import os
import re
import six
import zipfile
import tempfile
class CTFdSerializer(JSONSerializer):
@@ -56,7 +57,7 @@ def export_ctf():
db = dataset.connect(get_app_config('SQLALCHEMY_DATABASE_URI'))
# Backup database
backup = six.BytesIO()
backup = tempfile.SpooledTemporaryFile()
backup_zip = zipfile.ZipFile(backup, 'w')

View File

@@ -27,7 +27,7 @@ def test_export_ctf():
backup = export_ctf()
with open('export.zip', 'wb') as f:
f.write(backup.getvalue())
f.write(backup.read())
os.remove('export.zip')
destroy_ctfd(app)