new: add mime types parsing (#431)

This commit is contained in:
Ramzan Bekbulatov 2021-03-21 10:41:03 +03:00 committed by GitHub
parent b0f2fe3ed4
commit e2273e6c31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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