From 3829666a5325374c64828b9f20e752875e323a44 Mon Sep 17 00:00:00 2001 From: Ehsan <4243503+ehsanonline@users.noreply.github.com> Date: Tue, 25 Sep 2018 21:37:55 +0330 Subject: [PATCH 1/6] add text mention for message parse (#1206) * add text mention for message parse * add author * Update .gitignore --- AUTHORS.rst | 1 + telegram/message.py | 8 ++++-- tests/test_message.py | 58 +++++++++++++++++++++++++---------------- tests/test_parsemode.py | 7 ++--- 4 files changed, 46 insertions(+), 28 deletions(-) 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/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/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) From c714a177d1fa4b20dd55bc0ef71e5bab800f9e11 Mon Sep 17 00:00:00 2001 From: reablaz Date: Wed, 26 Sep 2018 16:46:25 +0300 Subject: [PATCH 2/6] Update data.py to be compatible with example (#1213) * Update data.py to be compatible with example for now, if you process personal_info with example code, then you got an error if there is no set option to get native fist and last name. setting default value will allow to process personal_info without native name/surname transation * fixing line length i hope i understood right this. sorry for delay, just starting using github! --- telegram/passport/data.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 4c66ba3a8d65d0c46e361472bac51ff005db454b Mon Sep 17 00:00:00 2001 From: Jasmin Bom Date: Sun, 30 Sep 2018 12:07:17 +0200 Subject: [PATCH 3/6] 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 --- telegram/files/inputfile.py | 2 +- tests/data/telegram | 0 tests/test_inputfile.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/data/telegram 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/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' From 6c36316aedc4bc2a7192a62e1c4a09b1f3a7ff3c Mon Sep 17 00:00:00 2001 From: Pieter Schutz Date: Mon, 1 Oct 2018 10:25:06 +0200 Subject: [PATCH 4/6] Change yamls to build v12 on travis an appveyor --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2209bfd42..4126fee6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ sudo: false branches: only: - master + - v12 cache: directories: diff --git a/appveyor.yml b/appveyor.yml index 60d135529..f8546f485 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,6 +14,7 @@ environment: branches: only: - master + - v12 skip_branch_with_pr: true From 3d8ab23d66075a38a3d7d0c478a62ab78a2fe14d Mon Sep 17 00:00:00 2001 From: Pieter Schutz Date: Mon, 1 Oct 2018 11:46:48 +0200 Subject: [PATCH 5/6] try to make ci build version branches --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4126fee6d..143f080d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ sudo: false branches: only: - master - - v12 + - /^[vV]\d+$/ cache: directories: diff --git a/appveyor.yml b/appveyor.yml index f8546f485..fdb97803c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ environment: branches: only: - master - - v12 + - /^[vV]\d+$/ skip_branch_with_pr: true From d9ae4be2b3db4de081c9688184020d976cc95377 Mon Sep 17 00:00:00 2001 From: Jasmin Bom Date: Mon, 1 Oct 2018 20:50:44 +0200 Subject: [PATCH 6/6] Add 3.7 to travis and make pypy allowed_failures (#1215) * Add 3.7 to travis build matrix using workaround See https://github.com/travis-ci/travis-ci/issues/9815 for workaround discussion * Add 3.7 to pypi classifiers * Format build matrix differently * Try adding pypy6.0.0 to travis build matrix * Add py3.7 to appveyor * Try pypy 5.10.1 instead 6.0.0 isn't on travis yet: https://github.com/travis-ci/travis-ci/issues/9542 * pypy2-5.10.0 isn't on travis yet either... * allow failures on travis pypy --- .travis.yml | 21 ++++++++++++++------- appveyor.yml | 1 + setup.py | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) 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/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' ],)