Skip to content
Myr

better replacement of original form KeyError

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent c9a1f7a · Browse files · 2 files+10 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−6 removed

  • other:+10 added−6 removed

2 files+10 added−6 removed

modified:src/flask/debughelpers.py+9 added-5 removed
69 unmodified lines
70 super().__init__("".join(buf))717273def attach_enctype_error_multidict(request):74 """Since Flask 0.8 we're monkeypatching the files object in case a75 request is detected that does not use multipart form data but the files76 object is accessed.74 """Patch ``request.files.__getitem__`` to raise a descriptive error75 about ``enctype=multipart/form-data``.7677 :param request: The request to patch.78 :meta private:79 """80 oldcls = request.files.__class__8182 class newcls(oldcls):83 def __getitem__(self, key):84 try:83 return oldcls.__getitem__(self, key)85 return super().__getitem__(key)86 except KeyError as e:87 if key not in request.form:88 raise8988 raise DebugFilesKeyError(request, key) from e90 raise DebugFilesKeyError(request, key).with_traceback(91 e.__traceback__92 ) from None9394 newcls.__name__ = oldcls.__name__95 newcls.__module__ = oldcls.__module__96 request.files.__class__ = newcls
78 unmodified lines
modified:src/flask/wrappers.py+1 added-1 removed
108 unmodified lines
109110 return _split_blueprint_path(name)111112 def _load_form_data(self) -> None:113 RequestBase._load_form_data(self)113 super()._load_form_data()114115 # In debug mode we're replacing the files multidict with an ad-hoc116 # subclass that raises a different error for key errors.117 if (
50 unmodified lines