Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Commit

Permalink
Response can return bytes and Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bata committed Dec 17, 2016
1 parent 0267afa commit ae7fe68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions kobin/environs.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def __init__(self, body='', status=None, headers=None, charset='utf-8'):

@property
def body(self):
if isinstance(self._body, bytes):
return [self._body]
return [self._body.encode(self.charset)]

@property
Expand Down
8 changes: 5 additions & 3 deletions kobin/environs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Request:
@property
def forms(self) -> Dict[str, str]: ...
@property
def raw_body(self) -> bytes: ...
@property
def body(self) -> str: ...
@property
def json(self) -> Dict[str, Any]: ...
Expand Down Expand Up @@ -65,11 +67,9 @@ class Response:
_cookies: SimpleCookie
charset: str

def __init__(self, body: str = ..., status: int = ..., headers: Dict = ...,
def __init__(self, body: Union[str, bytes] = ..., status: int = ..., headers: Dict = ...,
charset: str = ...) -> None: ...
@property
def raw_body(self) -> bytes: ...
@property
def body(self) -> str: ...
@property
def status_code(self) -> int: ...
Expand All @@ -86,6 +86,7 @@ class Response:
class JSONResponse:
dic: Dict[str, Any]
json_dump_args: Dict[str, Any]
charset: str

def __init__(self, dic: Dict, status: int = ..., headers: Dict = ...,
charset: str = ..., **dump_args: Any) -> None: ...
Expand All @@ -96,6 +97,7 @@ class JSONResponse:
class TemplateResponse:
template: Template
tpl_args: Dict[str, Any]
charset: str

def __init__(self, filename: str, status: int = ..., headers: Dict[str, str] = ...,
charset: str = ..., **tpl_args: Any) -> None: ...
Expand Down

0 comments on commit ae7fe68

Please sign in to comment.