async def get_value(self, request: Request) -> T: if request.declares_json( ) and request.method not in self._excluded_methods: data = await request.json() if not data: raise MissingBodyError() return self.parse_value(data) if self.required: if not request.has_body(): raise MissingBodyError() raise InvalidRequestBody('Expected JSON payload') return None
async def get_value(self, request: Request) -> T: if request.method not in self._excluded_methods and self.matches_content_type( request): data = await self.read_data(request) if not data: raise MissingBodyError() return self.parse_value(data) if self.required: if not request.has_body(): raise MissingBodyError() raise InvalidRequestBody( f'Expected payload {self.__class__.__name__}') return None
async def get_value(self, request: Request) -> Optional[T]: if request.method not in self._excluded_methods and self.matches_content_type( request): data = await self.read_data(request) if not data: raise MissingBodyError() return self.parse_value(data) if self.required: if self.default is not empty: # very unlikely: this is to support user defined default parameters return None if not request.has_body(): raise MissingBodyError() raise InvalidRequestBody("Expected request content") return None