mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Allow filenames without dots in them when sending files (#1228)
* Fix issue 1227 by allowing filenames without dots in them * Touch new test data file * Satisfy flake8
This commit is contained in:
parent
c714a177d1
commit
4c66ba3a8d
3 changed files with 32 additions and 1 deletions
|
@ -70,7 +70,7 @@ class InputFile(object):
|
|||
self.filename)[0] or DEFAULT_MIME_TYPE
|
||||
else:
|
||||
self.mimetype = DEFAULT_MIME_TYPE
|
||||
if not self.filename or '.' not in self.filename:
|
||||
if not self.filename:
|
||||
self.filename = self.mimetype.replace('/', '.')
|
||||
|
||||
@property
|
||||
|
|
0
tests/data/telegram
Normal file
0
tests/data/telegram
Normal file
|
@ -63,3 +63,34 @@ class TestInputFile(object):
|
|||
assert (InputFile(BytesIO(b'blah'), filename='tg.notaproperext').mimetype ==
|
||||
'application/octet-stream')
|
||||
assert InputFile(BytesIO(b'blah')).mimetype == 'application/octet-stream'
|
||||
|
||||
def test_filenames(self):
|
||||
assert InputFile(open('tests/data/telegram.jpg', 'rb')).filename == 'telegram.jpg'
|
||||
assert InputFile(open('tests/data/telegram.jpg', 'rb'),
|
||||
filename='blah').filename == 'blah'
|
||||
assert InputFile(open('tests/data/telegram.jpg', 'rb'),
|
||||
filename='blah.jpg').filename == 'blah.jpg'
|
||||
assert InputFile(open('tests/data/telegram', 'rb')).filename == 'telegram'
|
||||
assert InputFile(open('tests/data/telegram', 'rb'),
|
||||
filename='blah').filename == 'blah'
|
||||
assert InputFile(open('tests/data/telegram', 'rb'),
|
||||
filename='blah.jpg').filename == 'blah.jpg'
|
||||
|
||||
class MockedFileobject(object):
|
||||
# A open(?, 'rb') without a .name
|
||||
def __init__(self, f):
|
||||
self.f = open(f, 'rb')
|
||||
|
||||
def read(self):
|
||||
return self.f.read()
|
||||
|
||||
assert InputFile(MockedFileobject('tests/data/telegram.jpg')).filename == 'image.jpeg'
|
||||
assert InputFile(MockedFileobject('tests/data/telegram.jpg'),
|
||||
filename='blah').filename == 'blah'
|
||||
assert InputFile(MockedFileobject('tests/data/telegram.jpg'),
|
||||
filename='blah.jpg').filename == 'blah.jpg'
|
||||
assert InputFile(MockedFileobject('tests/data/telegram')).filename == 'application.octet-stream' # flake8: noqa
|
||||
assert InputFile(MockedFileobject('tests/data/telegram'),
|
||||
filename='blah').filename == 'blah'
|
||||
assert InputFile(MockedFileobject('tests/data/telegram'),
|
||||
filename='blah.jpg').filename == 'blah.jpg'
|
||||
|
|
Loading…
Reference in a new issue