diff --git a/.travis.yml b/.travis.yml index 143f080d5..889af4c23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,18 @@ language: python -python: - - "2.7" - - "3.4" - - "3.5" - - "3.6" - - "3.7-dev" - - "pypy-5.7.1" +matrix: + include: + - python: 2.7 + - python: 3.4 + - python: 3.5 + - python: 3.6 + - python: 3.7 + dist: xenial + sudo: true + - python: pypy2.7-5.10.0 + - python: pypy3.5-5.10.1 + allow_failures: + - python: pypy2.7-5.10.0 + - python: pypy3.5-5.10.1 dist: trusty sudo: false diff --git a/AUTHORS.rst b/AUTHORS.rst index 6db6cabcd..bd53c1823 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -23,6 +23,7 @@ The following wonderful people contributed directly or indirectly to this projec - `d-qoi `_ - `daimajia `_ - `Daniel Reed `_ +- `Ehsan Online `_ - `Eli Gao `_ - `Emilio Molinari `_ - `ErgoZ Riftbit Vaper `_ diff --git a/appveyor.yml b/appveyor.yml index fdb97803c..b2aa6e1ce 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,7 @@ environment: - PYTHON: "C:\\Python34" - PYTHON: "C:\\Python35" - PYTHON: "C:\\Python36" + - PYTHON: "C:\\Python37" branches: only: diff --git a/setup.py b/setup.py index 55a0700c7..9cb90b7de 100644 --- a/setup.py +++ b/setup.py @@ -56,4 +56,5 @@ with codecs.open('README.rst', 'r', 'utf-8') as fd: 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6' + 'Programming Language :: Python :: 3.7' ],) diff --git a/telegram/files/inputfile.py b/telegram/files/inputfile.py index 0d614db34..977c325c5 100644 --- a/telegram/files/inputfile.py +++ b/telegram/files/inputfile.py @@ -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 diff --git a/telegram/message.py b/telegram/message.py index 09b07d41c..9ed3d7746 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -943,7 +943,9 @@ class Message(TelegramObject): if entity.type == MessageEntity.TEXT_LINK: insert = '{}'.format(entity.url, text) - elif (entity.type == MessageEntity.URL) and urled: + elif entity.type == MessageEntity.TEXT_MENTION and entity.user: + insert = '{}'.format(entity.user.id, text) + elif entity.type == MessageEntity.URL and urled: insert = '{0}'.format(text) elif entity.type == MessageEntity.BOLD: insert = '' + text + '' @@ -1040,7 +1042,9 @@ class Message(TelegramObject): if entity.type == MessageEntity.TEXT_LINK: insert = '[{}]({})'.format(text, entity.url) - elif (entity.type == MessageEntity.URL) and urled: + elif entity.type == MessageEntity.TEXT_MENTION and entity.user: + insert = '[{}](tg://user?id={})'.format(text, entity.user.id) + elif entity.type == MessageEntity.URL and urled: insert = '[{0}]({0})'.format(text) elif entity.type == MessageEntity.BOLD: insert = '*' + text + '*' diff --git a/telegram/passport/data.py b/telegram/passport/data.py index 08658be77..a0e08bc5c 100644 --- a/telegram/passport/data.py +++ b/telegram/passport/data.py @@ -39,7 +39,8 @@ class PersonalDetails(TelegramObject): """ def __init__(self, first_name, last_name, birth_date, gender, country_code, - residence_country_code, first_name_native, last_name_native, middle_name=None, + residence_country_code, first_name_native=None, + last_name_native=None, middle_name=None, middle_name_native=None, bot=None, **kwargs): # Required self.first_name = first_name diff --git a/tests/data/telegram b/tests/data/telegram new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_inputfile.py b/tests/test_inputfile.py index fd34c841b..1c667d3df 100644 --- a/tests/test_inputfile.py +++ b/tests/test_inputfile.py @@ -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' diff --git a/tests/test_message.py b/tests/test_message.py index 125f7be91..202897758 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -114,9 +114,11 @@ class TestMessage(object): {'length': 7, 'offset': 16, 'type': 'italic'}, {'length': 4, 'offset': 25, 'type': 'code'}, {'length': 5, 'offset': 31, 'type': 'text_link', 'url': 'http://github.com/'}, - {'length': 3, 'offset': 41, 'type': 'pre'}, - {'length': 17, 'offset': 46, 'type': 'url'}] - test_text = 'Test for bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') text_html = self.test_message.text_html assert text_html == test_html_string @@ -185,14 +188,16 @@ class TestMessage(object): def test_text_html_urled(self): test_html_string = ('Test for <bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') text_html = self.test_message.text_html_urled assert text_html == test_html_string def test_text_markdown_simple(self): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. http://google.com') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + 'http://google.com') text_markdown = self.test_message.text_markdown assert text_markdown == test_md_string @@ -202,8 +207,9 @@ class TestMessage(object): assert message.text_markdown is None def test_text_markdown_urled(self): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. [http://google.com](http://google.com)') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + '[http://google.com](http://google.com)') text_markdown = self.test_message.text_markdown_urled assert text_markdown == test_md_string @@ -225,8 +231,9 @@ class TestMessage(object): def test_caption_html_simple(self): test_html_string = ('Test for <bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') caption_html = self.test_message.caption_html assert caption_html == test_html_string @@ -237,14 +244,16 @@ class TestMessage(object): def test_caption_html_urled(self): test_html_string = ('Test for <bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') caption_html = self.test_message.caption_html_urled assert caption_html == test_html_string def test_caption_markdown_simple(self): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. http://google.com') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + 'http://google.com') caption_markdown = self.test_message.caption_markdown assert caption_markdown == test_md_string @@ -254,8 +263,9 @@ class TestMessage(object): assert message.caption_markdown is None def test_caption_markdown_urled(self): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. [http://google.com](http://google.com)') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + '[http://google.com](http://google.com)') caption_markdown = self.test_message.caption_markdown_urled assert caption_markdown == test_md_string @@ -326,8 +336,9 @@ class TestMessage(object): assert message.reply_text('test', reply_to_message_id=message.message_id, quote=True) def test_reply_markdown(self, monkeypatch, message): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. http://google.com') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + 'http://google.com') def test(*args, **kwargs): cid = args[1] == message.chat_id @@ -351,8 +362,9 @@ class TestMessage(object): def test_reply_html(self, monkeypatch, message): test_html_string = ('Test for <bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') def test(*args, **kwargs): cid = args[1] == message.chat_id diff --git a/tests/test_parsemode.py b/tests/test_parsemode.py index 0f7b155c6..c015f6fda 100644 --- a/tests/test_parsemode.py +++ b/tests/test_parsemode.py @@ -23,9 +23,10 @@ from telegram import ParseMode class TestParseMode(object): - markdown_text = '*bold* _italic_ [link](http://google.com).' - html_text = 'bold italic link.' - formatted_text_formatted = u'bold italic link.' + markdown_text = '*bold* _italic_ [link](http://google.com) [name](tg://user?id=123456789).' + html_text = ('bold italic link ' + 'name.') + formatted_text_formatted = u'bold italic link name.' @flaky(3, 1) @pytest.mark.timeout(10)