| 39 | |
| 40 | |
| 41 | class FormDataParser: |
| 42 | file_storage_class = FileStorage |
| 43 | |
| 44 | def __init__( |
| 45 | self, |
| 46 | *, |
| 47 | cls: type[MultiDict] | None = MultiDict, |
| 48 | max_content_length: int | None = None, |
| 49 | max_form_memory_size: int | None = None, |
| 50 | max_form_parts: int | None = None, |
| 51 | silent: bool = True, |
| 52 | stream_factory: StreamFactory = default_stream_factory, |
| 53 | ) -> None: |
| 54 | self.cls = cls |
| 55 | self.max_content_length = max_content_length |
| 56 | self.max_form_memory_size = max_form_memory_size |
| 57 | self.max_form_parts = max_form_parts |
| 58 | self.silent = silent |
| 59 | self.stream_factory = stream_factory |
| 60 | |
| 61 | def get_parse_func( |
| 62 | self, mimetype: str, options: dict[str, str] |
| 63 | ) -> ParserFunc | None: |
| 64 | return self.parse_functions.get(mimetype) |
| 65 | |
| 66 | async def parse( |
| 67 | self, |
| 68 | body: Body, |
| 69 | mimetype: str, |
| 70 | content_length: int | None, |
| 71 | options: dict[str, str] | None = None, |
| 72 | ) -> tuple[MultiDict, MultiDict]: |
| 73 | if options is None: |
| 74 | options = {} |
| 75 | |
| 76 | parse_func = self.get_parse_func(mimetype, options) |
| 77 | |
| 78 | if parse_func is not None: |
| 79 | try: |
| 80 | return await parse_func(self, body, mimetype, content_length, options) |
| 81 | except ValueError: |
| 82 | if not self.silent: |
| 83 | raise |
| 84 | |
| 85 | return self.cls(), self.cls() |
| 86 | |
| 87 | async def _parse_multipart( |
| 88 | self, |
| 89 | body: Body, |
| 90 | mimetype: str, |
| 91 | content_length: int | None, |
| 92 | options: dict[str, str], |
| 93 | ) -> tuple[MultiDict, MultiDict]: |
| 94 | parser = MultiPartParser( |
| 95 | cls=self.cls, |
| 96 | file_storage_cls=self.file_storage_class, |
| 97 | max_content_length=self.max_content_length, |
| 98 | max_form_memory_size=self.max_form_memory_size, |
no outgoing calls
searching dependent graphs…