From 75c28fd9b45419e0be516a793e587154a757ba34 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Tue, 22 Oct 2019 14:39:24 -0400 Subject: [PATCH] Make content a positional argument --- main.py | 3 +-- phial.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index d7ea725..f0bc2bc 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,7 @@ import phial def handler(request): - return phial.Response( - content_type='text/plain', + return phial.TextResponse( content='Hello, world\n', ) diff --git a/phial.py b/phial.py index bce8979..f76a5dc 100644 --- a/phial.py +++ b/phial.py @@ -18,7 +18,7 @@ _Response = collections.namedtuple( ) class Response(_Response): - def __new__(cls, **kwargs): + def __new__(cls, content, **kwargs): status = kwargs.pop('status', 200) assert isinstance(status, int) @@ -28,8 +28,6 @@ class Response(_Response): extra_headers = kwargs.pop('extra_headers', ()) assert isinstance(extra_headers, tuple) - content = kwargs.pop('content') - assert len(kwargs) == 0 return super().__new__( @@ -46,6 +44,16 @@ class Response(_Response): ('Content-Type', self.content_type), ) +class TextResponse(Response): + def __new__(cls, content, **kwargs): + assert 'content_type' not in kwargs + return super().__new__( + cls, + content, + content_type='text/plain', + **kwargs, + ) + def _get_status(response): return { 200: '200 OK', -- 2.20.1