From e2273e6c31aaf4eb70554239493547a13e486398 Mon Sep 17 00:00:00 2001 From: Ramzan Bekbulatov Date: Sun, 21 Mar 2021 10:41:03 +0300 Subject: [PATCH] new: add mime types parsing (#431) --- aiogram/types/document.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/aiogram/types/document.py b/aiogram/types/document.py index e15b745d..c3d19fa9 100644 --- a/aiogram/types/document.py +++ b/aiogram/types/document.py @@ -2,6 +2,7 @@ from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils import helper class Document(base.TelegramObject, mixins.Downloadable): @@ -16,3 +17,34 @@ class Document(base.TelegramObject, mixins.Downloadable): file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + @property + def mime_base(self) -> str: + base_type, _, _ = self.mime_type.partition('/') + return base_type + + @property + def mime_subtype(self) -> str: + _, _, subtype = self.mime_type.partition('/') + return subtype + + +class MimeBase(helper.Helper): + """ + List of mime base types registered in IANA + + https://www.iana.org/assignments/media-types/media-types.xhtml + """ + + mode = helper.HelperMode.lowercase + + APPLICATION = helper.Item() # application + AUDIO = helper.Item() # audio + EXAMPLE = helper.Item() # example + FONT = helper.Item() # font + IMAGE = helper.Item() # image + MESSAGE = helper.Item() # message + MODEL = helper.Item() # model + MULTIPART = helper.Item() # multipart + TEXT = helper.Item() # text + VIDEO = helper.Item() # video