From aa9212f3226b10976c31cdf804139d60ae655a16 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 21 Jul 2019 13:14:38 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D1=80=D1=8F=D0=B4=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day9/task5/core.py | 82 ------------------------------------------------------ 1 file changed, 82 deletions(-) delete mode 100644 day9/task5/core.py (limited to 'day9/task5/core.py') diff --git a/day9/task5/core.py b/day9/task5/core.py deleted file mode 100644 index 2bf9cf5..0000000 --- a/day9/task5/core.py +++ /dev/null @@ -1,82 +0,0 @@ -from abc import ABC, abstractmethod -import json - -from utils import HTTP_STATUS_CODES - - -class Response(ABC): - @property - def status_code(self) -> int: - """ - По дефолту возвращается статус 200 - """ - return 200 - - @property - @abstractmethod - def content_type(self) -> str: - pass - - @property - @abstractmethod - def content(self) -> bytes: - pass - - -class HtmlResponse(Response): - def __init__(self, html, status_code=200): - self._html: str = html - self._code = status_code - - @property - def status_code(self) -> int: - return self._code - - @property - def content_type(self) -> str: - return 'text/html' - - @property - def content(self) -> bytes: - return self._html.encode() - - -class TextFileResponse(Response): - def __init__(self, path, extension): - with open(path, 'rb') as f: - self._content = f.read() - - self._extension = extension - - @property - def content_type(self) -> str: - return f'text/{self._extension}' - - @property - def content(self) -> bytes: - return self._content - - -class ImageResponse(TextFileResponse): - @property - def content_type(self) -> str: - return f'image/{self._extension}' - - -class JsonResponse(Response): - def __init__(self, json_object): - self._json_str = json.dumps(json_object, ensure_ascii=False) - - @property - def content_type(self) -> str: - return 'application/json' - - @property - def content(self) -> bytes: - return self._json_str.encode() - - -class ErrorResponse(HtmlResponse): - def __init__(self, http_code, message=''): - html = f'

ERROR {http_code} {HTTP_STATUS_CODES[http_code].upper()}


{message}' - super().__init__(html, http_code) -- cgit v1.2.3