Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback for platform who don't have SpooledTemporaryFile #1220

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions werkzeug/formparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
"""
import re
import codecs
from tempfile import SpooledTemporaryFile
try:
from tempfile import SpooledTemporaryFile

This comment was marked as off-topic.

This comment was marked as off-topic.

except ImportError:
# some platforms might not SpooledTemporaryFile support
# in that case we revert to the old TemporaryFile code
from tempfile import TemporaryFile
SpooledTemporaryFile = None

from itertools import chain, repeat, tee
from functools import update_wrapper

Expand All @@ -37,7 +44,14 @@
def default_stream_factory(total_content_length, filename, content_type,
content_length=None):
"""The stream factory that is used per default."""
return SpooledTemporaryFile(max_size=1024 * 500, mode='wb+')
max_size = 1024 * 500
if SpooledTemporaryFile is None:
if total_content_length > max_size:
return TemporaryFile('wb+')

return BytesIO()
else:
return SpooledTemporaryFile(max_size=max_size, mode='wb+')


def parse_form_data(environ, stream_factory=None, charset='utf-8',
Expand Down