X-Git-Url: https://code.kerkeslager.com/?p=fwx;a=blobdiff_plain;f=phial.py;h=f76a5dcbb464657556bc30db4a17566b46575adc;hp=bce897919819449d058a1eee2638681405dca368;hb=75c28fd9b45419e0be516a793e587154a757ba34;hpb=bae515833a10b81e1c8f7deb1f7a1320c2a09de1 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',