MCPcopy
hub / github.com/encode/starlette / _get_form

Method _get_form

starlette/requests.py:268–311  ·  view source on GitHub ↗
(
        self,
        *,
        max_files: int | float = 1000,
        max_fields: int | float = 1000,
        max_part_size: int = 1024 * 1024,
    )

Source from the content-addressed store, hash-verified

266 return self._json
267
268 async def _get_form(
269 self,
270 *,
271 max_files: int | float = 1000,
272 max_fields: int | float = 1000,
273 max_part_size: int = 1024 * 1024,
274 ) -> FormData:
275 if self._form is None: # pragma: no branch
276 assert parse_options_header is not None, (
277 "The `python-multipart` library must be installed to use form parsing."
278 )
279 content_type_header = self.headers.get("Content-Type")
280 content_type: bytes
281 content_type, _ = parse_options_header(content_type_header)
282 if content_type == b"multipart/form-data":
283 try:
284 multipart_parser = MultiPartParser(
285 self.headers,
286 self.stream(),
287 max_files=max_files,
288 max_fields=max_fields,
289 max_part_size=max_part_size,
290 )
291 self._form = await multipart_parser.parse()
292 except MultiPartException as exc:
293 if "app" in self.scope:
294 raise HTTPException(status_code=400, detail=exc.message)
295 raise exc
296 elif content_type == b"application/x-www-form-urlencoded":
297 try:
298 form_parser = FormParser(
299 self.headers,
300 self.stream(),
301 max_fields=max_fields,
302 max_part_size=max_part_size,
303 )
304 self._form = await form_parser.parse()
305 except MultiPartException as exc:
306 if "app" in self.scope:
307 raise HTTPException(status_code=400, detail=exc.message)
308 raise exc
309 else:
310 self._form = FormData()
311 return self._form
312
313 def form(
314 self,

Callers 1

formMethod · 0.95

Calls 8

streamMethod · 0.95
parseMethod · 0.95
parseMethod · 0.95
MultiPartParserClass · 0.90
HTTPExceptionClass · 0.90
FormParserClass · 0.90
FormDataClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected