@@ -179,6 +179,8 @@ class FormDataParser:
179179 :param cls: an optional dict class to use. If this is not specified
180180 or `None` the default :class:`MultiDict` is used.
181181 :param silent: If set to False parsing errors will not be caught.
182+ :param max_form_parts: The maximum number of parts to be parsed. If this is
183+ exceeded, a :exc:`~exceptions.RequestEntityTooLarge` exception is raised.
182184 """
183185
184186 def __init__ (
@@ -190,6 +192,8 @@ def __init__(
190192 max_content_length : t .Optional [int ] = None ,
191193 cls : t .Optional [t .Type [MultiDict ]] = None ,
192194 silent : bool = True ,
195+ * ,
196+ max_form_parts : t .Optional [int ] = None ,
193197 ) -> None :
194198 if stream_factory is None :
195199 stream_factory = default_stream_factory
@@ -199,6 +203,7 @@ def __init__(
199203 self .errors = errors
200204 self .max_form_memory_size = max_form_memory_size
201205 self .max_content_length = max_content_length
206+ self .max_form_parts = max_form_parts
202207
203208 if cls is None :
204209 cls = MultiDict
@@ -281,6 +286,7 @@ def _parse_multipart(
281286 self .errors ,
282287 max_form_memory_size = self .max_form_memory_size ,
283288 cls = self .cls ,
289+ max_form_parts = self .max_form_parts ,
284290 )
285291 boundary = options .get ("boundary" , "" ).encode ("ascii" )
286292
@@ -346,10 +352,12 @@ def __init__(
346352 max_form_memory_size : t .Optional [int ] = None ,
347353 cls : t .Optional [t .Type [MultiDict ]] = None ,
348354 buffer_size : int = 64 * 1024 ,
355+ max_form_parts : t .Optional [int ] = None ,
349356 ) -> None :
350357 self .charset = charset
351358 self .errors = errors
352359 self .max_form_memory_size = max_form_memory_size
360+ self .max_form_parts = max_form_parts
353361
354362 if stream_factory is None :
355363 stream_factory = default_stream_factory
@@ -409,7 +417,9 @@ def parse(
409417 [None ],
410418 )
411419
412- parser = MultipartDecoder (boundary , self .max_form_memory_size )
420+ parser = MultipartDecoder (
421+ boundary , self .max_form_memory_size , max_parts = self .max_form_parts
422+ )
413423
414424 fields = []
415425 files = []
0 commit comments