mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
new: add mime types parsing (#431)
This commit is contained in:
parent
b0f2fe3ed4
commit
e2273e6c31
1 changed files with 32 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue