Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def example(request):
nonlocal calls
calls.append(5)
return Response(200,
[(b'Server', b'Python/3.7')],
JsonContent({'id': '123'}))
async def test_from_body_json_binding_extra_parameters_strategy():
request = Request('POST', b'/', [
JsonContentType
]).with_content(JsonContent({
'a': 'world',
'b': 9000,
'c': 'This is an extra parameter, accepted by constructor explicitly'
}))
parameter = FromJson(ExampleTwo)
value = await parameter.get_value(request)
assert isinstance(value, ExampleTwo)
assert value.a == 'world'
assert value.b == 9000
def status_code(status: int = 200, message: MessageType = None):
"""Returns a plain response with given status, with optional message; sent as plain text or JSON."""
if not message:
return Response(status)
if isinstance(message, str):
content = TextContent(message)
else:
content = JsonContent(message)
return Response(status, content=content)
def created(location: BytesOrStr, value: Any = None):
"""Returns an HTTP 201 Created response, to the given location and with optional JSON content."""
return Response(201,
[(b'Location', _ensure_bytes(location))],
JsonContent(value) if value else None)