コード例 #1
0
    def __init__(
        self,
        media: Union[FileInput, Document],
        thumb: FileInput = None,
        caption: str = None,
        parse_mode: ODVInput[str] = DEFAULT_NONE,
        disable_content_type_detection: bool = None,
        caption_entities: Union[List[MessageEntity], Tuple[MessageEntity,
                                                           ...]] = None,
        filename: str = None,
    ):
        self.type = 'document'
        self.media = parse_file_input(media,
                                      Document,
                                      attach=True,
                                      filename=filename)

        if thumb:
            self.thumb = parse_file_input(thumb, attach=True)

        if caption:
            self.caption = caption
        self.parse_mode = parse_mode
        self.caption_entities = caption_entities
        self.disable_content_type_detection = disable_content_type_detection
コード例 #2
0
    def __init__(
        self,
        media: Union[FileInput, Audio],
        thumb: FileInput = None,
        caption: str = None,
        parse_mode: Union[str, DefaultValue] = DEFAULT_NONE,
        duration: int = None,
        performer: str = None,
        title: str = None,
        caption_entities: Union[List[MessageEntity], Tuple[MessageEntity,
                                                           ...]] = None,
    ):
        self.type = 'audio'

        if isinstance(media, Audio):
            self.media: Union[str, InputFile] = media.file_id
            self.duration = media.duration
            self.performer = media.performer
            self.title = media.title
        else:
            self.media = parse_file_input(media, attach=True)

        if thumb:
            self.thumb = parse_file_input(thumb, attach=True)

        if caption:
            self.caption = caption
        self.parse_mode = parse_mode
        self.caption_entities = caption_entities
        if duration:
            self.duration = duration
        if performer:
            self.performer = performer
        if title:
            self.title = title
コード例 #3
0
    def __init__(
        self,
        media: Union[FileInput, Animation],
        thumb: FileInput = None,
        caption: str = None,
        parse_mode: Union[str, DefaultValue] = DEFAULT_NONE,
        width: int = None,
        height: int = None,
        duration: int = None,
        caption_entities: Union[List[MessageEntity], Tuple[MessageEntity,
                                                           ...]] = None,
    ):
        self.type = 'animation'

        if isinstance(media, Animation):
            self.media: Union[str, InputFile] = media.file_id
            self.width = media.width
            self.height = media.height
            self.duration = media.duration
        else:
            self.media = parse_file_input(media, attach=True)

        if thumb:
            self.thumb = parse_file_input(thumb, attach=True)

        if caption:
            self.caption = caption
        self.parse_mode = parse_mode
        self.caption_entities = caption_entities
        if width:
            self.width = width
        if height:
            self.height = height
        if duration:
            self.duration = duration
コード例 #4
0
ファイル: test_helpers.py プロジェクト: hleserg/hleserg-bot1
    def test_parse_file_input_bytes(self):
        with open('tests/data/text_file.txt', 'rb') as file:
            parsed = helpers.parse_file_input(file.read())

        assert isinstance(parsed, InputFile)
        assert not parsed.attach
        assert parsed.filename == 'application.octet-stream'

        with open('tests/data/text_file.txt', 'rb') as file:
            parsed = helpers.parse_file_input(file.read(), attach=True, filename='test_file')

        assert isinstance(parsed, InputFile)
        assert parsed.attach
        assert parsed.filename == 'test_file'
コード例 #5
0
ファイル: test_helpers.py プロジェクト: hleserg/hleserg-bot1
    def test_parse_file_input_file_like(self):
        with open('tests/data/game.gif', 'rb') as file:
            parsed = helpers.parse_file_input(file)

        assert isinstance(parsed, InputFile)
        assert not parsed.attach
        assert parsed.filename == 'game.gif'

        with open('tests/data/game.gif', 'rb') as file:
            parsed = helpers.parse_file_input(file, attach=True, filename='test_file')

        assert isinstance(parsed, InputFile)
        assert parsed.attach
        assert parsed.filename == 'test_file'
コード例 #6
0
    def __init__(
        self,
        media: Union[FileInput, Video],
        caption: str = None,
        width: int = None,
        height: int = None,
        duration: int = None,
        supports_streaming: bool = None,
        parse_mode: ODVInput[str] = DEFAULT_NONE,
        thumb: FileInput = None,
        caption_entities: Union[List[MessageEntity], Tuple[MessageEntity,
                                                           ...]] = None,
        filename: str = None,
    ):
        self.type = 'video'

        if isinstance(media, Video):
            self.media: Union[str, InputFile] = media.file_id
            self.width = media.width
            self.height = media.height
            self.duration = media.duration
        else:
            self.media = parse_file_input(media,
                                          attach=True,
                                          filename=filename)

        if thumb:
            self.thumb = parse_file_input(thumb, attach=True)

        if caption:
            self.caption = caption
        self.parse_mode = parse_mode
        self.caption_entities = caption_entities
        if width:
            self.width = width
        if height:
            self.height = height
        if duration:
            self.duration = duration
        if supports_streaming:
            self.supports_streaming = supports_streaming
コード例 #7
0
    def __init__(
        self,
        media: Union[FileInput, PhotoSize],
        caption: str = None,
        parse_mode: Union[str, DefaultValue] = DEFAULT_NONE,
        caption_entities: Union[List[MessageEntity], Tuple[MessageEntity,
                                                           ...]] = None,
    ):
        self.type = 'photo'
        self.media = parse_file_input(media, PhotoSize, attach=True)

        if caption:
            self.caption = caption
        self.parse_mode = parse_mode
        self.caption_entities = caption_entities
コード例 #8
0
 def test_parse_file_input_other(self, obj):
     assert helpers.parse_file_input(obj) is obj
コード例 #9
0
 def test_parse_file_input_tg_object(self):
     animation = Animation('file_id', 'unique_id', 1, 1, 1)
     assert helpers.parse_file_input(animation, Animation) == 'file_id'
     assert helpers.parse_file_input(animation, MessageEntity) is animation
コード例 #10
0
 def test_parse_file_input_string(self, string, expected):
     assert helpers.parse_file_input(string) == expected