From: David Kerkeslager Date: Tue, 22 Oct 2019 18:39:24 +0000 (-0400) Subject: Make content a positional argument X-Git-Url: https://code.kerkeslager.com/?a=commitdiff_plain;h=75c28fd9b45419e0be516a793e587154a757ba34;p=fwx Make content a positional argument --- 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',