mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-10-24 09:56:30 +02:00
Merge branch 'master' into V12
This commit is contained in:
commit
8731365911
11 changed files with 96 additions and 37 deletions
21
.travis.yml
21
.travis.yml
|
@ -1,11 +1,18 @@
|
||||||
language: python
|
language: python
|
||||||
python:
|
matrix:
|
||||||
- "2.7"
|
include:
|
||||||
- "3.4"
|
- python: 2.7
|
||||||
- "3.5"
|
- python: 3.4
|
||||||
- "3.6"
|
- python: 3.5
|
||||||
- "3.7-dev"
|
- python: 3.6
|
||||||
- "pypy-5.7.1"
|
- 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
|
dist: trusty
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
|
@ -23,6 +23,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
||||||
- `d-qoi <https://github.com/d-qoi>`_
|
- `d-qoi <https://github.com/d-qoi>`_
|
||||||
- `daimajia <https://github.com/daimajia>`_
|
- `daimajia <https://github.com/daimajia>`_
|
||||||
- `Daniel Reed <https://github.com/nmlorg>`_
|
- `Daniel Reed <https://github.com/nmlorg>`_
|
||||||
|
- `Ehsan Online <https://github.com/ehsanonline>`_
|
||||||
- `Eli Gao <https://github.com/eligao>`_
|
- `Eli Gao <https://github.com/eligao>`_
|
||||||
- `Emilio Molinari <https://github.com/xates>`_
|
- `Emilio Molinari <https://github.com/xates>`_
|
||||||
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
|
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
|
||||||
|
|
|
@ -10,6 +10,7 @@ environment:
|
||||||
- PYTHON: "C:\\Python34"
|
- PYTHON: "C:\\Python34"
|
||||||
- PYTHON: "C:\\Python35"
|
- PYTHON: "C:\\Python35"
|
||||||
- PYTHON: "C:\\Python36"
|
- PYTHON: "C:\\Python36"
|
||||||
|
- PYTHON: "C:\\Python37"
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
|
|
1
setup.py
1
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.4',
|
||||||
'Programming Language :: Python :: 3.5',
|
'Programming Language :: Python :: 3.5',
|
||||||
'Programming Language :: Python :: 3.6'
|
'Programming Language :: Python :: 3.6'
|
||||||
|
'Programming Language :: Python :: 3.7'
|
||||||
],)
|
],)
|
||||||
|
|
|
@ -70,7 +70,7 @@ class InputFile(object):
|
||||||
self.filename)[0] or DEFAULT_MIME_TYPE
|
self.filename)[0] or DEFAULT_MIME_TYPE
|
||||||
else:
|
else:
|
||||||
self.mimetype = DEFAULT_MIME_TYPE
|
self.mimetype = DEFAULT_MIME_TYPE
|
||||||
if not self.filename or '.' not in self.filename:
|
if not self.filename:
|
||||||
self.filename = self.mimetype.replace('/', '.')
|
self.filename = self.mimetype.replace('/', '.')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -943,7 +943,9 @@ class Message(TelegramObject):
|
||||||
|
|
||||||
if entity.type == MessageEntity.TEXT_LINK:
|
if entity.type == MessageEntity.TEXT_LINK:
|
||||||
insert = '<a href="{}">{}</a>'.format(entity.url, text)
|
insert = '<a href="{}">{}</a>'.format(entity.url, text)
|
||||||
elif (entity.type == MessageEntity.URL) and urled:
|
elif entity.type == MessageEntity.TEXT_MENTION and entity.user:
|
||||||
|
insert = '<a href="tg://user?id={}">{}</a>'.format(entity.user.id, text)
|
||||||
|
elif entity.type == MessageEntity.URL and urled:
|
||||||
insert = '<a href="{0}">{0}</a>'.format(text)
|
insert = '<a href="{0}">{0}</a>'.format(text)
|
||||||
elif entity.type == MessageEntity.BOLD:
|
elif entity.type == MessageEntity.BOLD:
|
||||||
insert = '<b>' + text + '</b>'
|
insert = '<b>' + text + '</b>'
|
||||||
|
@ -1040,7 +1042,9 @@ class Message(TelegramObject):
|
||||||
|
|
||||||
if entity.type == MessageEntity.TEXT_LINK:
|
if entity.type == MessageEntity.TEXT_LINK:
|
||||||
insert = '[{}]({})'.format(text, entity.url)
|
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)
|
insert = '[{0}]({0})'.format(text)
|
||||||
elif entity.type == MessageEntity.BOLD:
|
elif entity.type == MessageEntity.BOLD:
|
||||||
insert = '*' + text + '*'
|
insert = '*' + text + '*'
|
||||||
|
|
|
@ -39,7 +39,8 @@ class PersonalDetails(TelegramObject):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, first_name, last_name, birth_date, gender, country_code,
|
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):
|
middle_name_native=None, bot=None, **kwargs):
|
||||||
# Required
|
# Required
|
||||||
self.first_name = first_name
|
self.first_name = first_name
|
||||||
|
|
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 ==
|
assert (InputFile(BytesIO(b'blah'), filename='tg.notaproperext').mimetype ==
|
||||||
'application/octet-stream')
|
'application/octet-stream')
|
||||||
assert InputFile(BytesIO(b'blah')).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'
|
||||||
|
|
|
@ -114,9 +114,11 @@ class TestMessage(object):
|
||||||
{'length': 7, 'offset': 16, 'type': 'italic'},
|
{'length': 7, 'offset': 16, 'type': 'italic'},
|
||||||
{'length': 4, 'offset': 25, 'type': 'code'},
|
{'length': 4, 'offset': 25, 'type': 'code'},
|
||||||
{'length': 5, 'offset': 31, 'type': 'text_link', 'url': 'http://github.com/'},
|
{'length': 5, 'offset': 31, 'type': 'text_link', 'url': 'http://github.com/'},
|
||||||
{'length': 3, 'offset': 41, 'type': 'pre'},
|
{'length': 12, 'offset': 38, 'type': 'text_mention',
|
||||||
{'length': 17, 'offset': 46, 'type': 'url'}]
|
'user': User(123456789, 'mentioned user', False)},
|
||||||
test_text = 'Test for <bold, ita_lic, code, links and pre. http://google.com'
|
{'length': 3, 'offset': 55, 'type': 'pre'},
|
||||||
|
{'length': 17, 'offset': 60, 'type': 'url'}]
|
||||||
|
test_text = 'Test for <bold, ita_lic, code, links, text-mention and pre. http://google.com'
|
||||||
test_message = Message(message_id=1,
|
test_message = Message(message_id=1,
|
||||||
from_user=None,
|
from_user=None,
|
||||||
date=None,
|
date=None,
|
||||||
|
@ -173,8 +175,9 @@ class TestMessage(object):
|
||||||
|
|
||||||
def test_text_html_simple(self):
|
def test_text_html_simple(self):
|
||||||
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
||||||
'<a href="http://github.com/">links</a> and <pre>pre</pre>. '
|
'<a href="http://github.com/">links</a>, '
|
||||||
'http://google.com')
|
'<a href="tg://user?id=123456789">text-mention</a> and '
|
||||||
|
'<pre>pre</pre>. http://google.com')
|
||||||
text_html = self.test_message.text_html
|
text_html = self.test_message.text_html
|
||||||
assert text_html == test_html_string
|
assert text_html == test_html_string
|
||||||
|
|
||||||
|
@ -185,14 +188,16 @@ class TestMessage(object):
|
||||||
|
|
||||||
def test_text_html_urled(self):
|
def test_text_html_urled(self):
|
||||||
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
||||||
'<a href="http://github.com/">links</a> and <pre>pre</pre>. '
|
'<a href="http://github.com/">links</a>, '
|
||||||
'<a href="http://google.com">http://google.com</a>')
|
'<a href="tg://user?id=123456789">text-mention</a> and '
|
||||||
|
'<pre>pre</pre>. <a href="http://google.com">http://google.com</a>')
|
||||||
text_html = self.test_message.text_html_urled
|
text_html = self.test_message.text_html_urled
|
||||||
assert text_html == test_html_string
|
assert text_html == test_html_string
|
||||||
|
|
||||||
def test_text_markdown_simple(self):
|
def test_text_markdown_simple(self):
|
||||||
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and '
|
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), '
|
||||||
'```pre```. http://google.com')
|
'[text-mention](tg://user?id=123456789) and ```pre```. '
|
||||||
|
'http://google.com')
|
||||||
text_markdown = self.test_message.text_markdown
|
text_markdown = self.test_message.text_markdown
|
||||||
assert text_markdown == test_md_string
|
assert text_markdown == test_md_string
|
||||||
|
|
||||||
|
@ -202,8 +207,9 @@ class TestMessage(object):
|
||||||
assert message.text_markdown is None
|
assert message.text_markdown is None
|
||||||
|
|
||||||
def test_text_markdown_urled(self):
|
def test_text_markdown_urled(self):
|
||||||
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and '
|
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), '
|
||||||
'```pre```. [http://google.com](http://google.com)')
|
'[text-mention](tg://user?id=123456789) and ```pre```. '
|
||||||
|
'[http://google.com](http://google.com)')
|
||||||
text_markdown = self.test_message.text_markdown_urled
|
text_markdown = self.test_message.text_markdown_urled
|
||||||
assert text_markdown == test_md_string
|
assert text_markdown == test_md_string
|
||||||
|
|
||||||
|
@ -225,8 +231,9 @@ class TestMessage(object):
|
||||||
|
|
||||||
def test_caption_html_simple(self):
|
def test_caption_html_simple(self):
|
||||||
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
||||||
'<a href="http://github.com/">links</a> and <pre>pre</pre>. '
|
'<a href="http://github.com/">links</a>, '
|
||||||
'http://google.com')
|
'<a href="tg://user?id=123456789">text-mention</a> and '
|
||||||
|
'<pre>pre</pre>. http://google.com')
|
||||||
caption_html = self.test_message.caption_html
|
caption_html = self.test_message.caption_html
|
||||||
assert caption_html == test_html_string
|
assert caption_html == test_html_string
|
||||||
|
|
||||||
|
@ -237,14 +244,16 @@ class TestMessage(object):
|
||||||
|
|
||||||
def test_caption_html_urled(self):
|
def test_caption_html_urled(self):
|
||||||
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
||||||
'<a href="http://github.com/">links</a> and <pre>pre</pre>. '
|
'<a href="http://github.com/">links</a>, '
|
||||||
'<a href="http://google.com">http://google.com</a>')
|
'<a href="tg://user?id=123456789">text-mention</a> and '
|
||||||
|
'<pre>pre</pre>. <a href="http://google.com">http://google.com</a>')
|
||||||
caption_html = self.test_message.caption_html_urled
|
caption_html = self.test_message.caption_html_urled
|
||||||
assert caption_html == test_html_string
|
assert caption_html == test_html_string
|
||||||
|
|
||||||
def test_caption_markdown_simple(self):
|
def test_caption_markdown_simple(self):
|
||||||
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and '
|
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), '
|
||||||
'```pre```. http://google.com')
|
'[text-mention](tg://user?id=123456789) and ```pre```. '
|
||||||
|
'http://google.com')
|
||||||
caption_markdown = self.test_message.caption_markdown
|
caption_markdown = self.test_message.caption_markdown
|
||||||
assert caption_markdown == test_md_string
|
assert caption_markdown == test_md_string
|
||||||
|
|
||||||
|
@ -254,8 +263,9 @@ class TestMessage(object):
|
||||||
assert message.caption_markdown is None
|
assert message.caption_markdown is None
|
||||||
|
|
||||||
def test_caption_markdown_urled(self):
|
def test_caption_markdown_urled(self):
|
||||||
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and '
|
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), '
|
||||||
'```pre```. [http://google.com](http://google.com)')
|
'[text-mention](tg://user?id=123456789) and ```pre```. '
|
||||||
|
'[http://google.com](http://google.com)')
|
||||||
caption_markdown = self.test_message.caption_markdown_urled
|
caption_markdown = self.test_message.caption_markdown_urled
|
||||||
assert caption_markdown == test_md_string
|
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)
|
assert message.reply_text('test', reply_to_message_id=message.message_id, quote=True)
|
||||||
|
|
||||||
def test_reply_markdown(self, monkeypatch, message):
|
def test_reply_markdown(self, monkeypatch, message):
|
||||||
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and '
|
test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), '
|
||||||
'```pre```. http://google.com')
|
'[text-mention](tg://user?id=123456789) and ```pre```. '
|
||||||
|
'http://google.com')
|
||||||
|
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
cid = args[1] == message.chat_id
|
cid = args[1] == message.chat_id
|
||||||
|
@ -351,8 +362,9 @@ class TestMessage(object):
|
||||||
|
|
||||||
def test_reply_html(self, monkeypatch, message):
|
def test_reply_html(self, monkeypatch, message):
|
||||||
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
test_html_string = ('Test for <<b>bold</b>, <i>ita_lic</i>, <code>code</code>, '
|
||||||
'<a href="http://github.com/">links</a> and <pre>pre</pre>. '
|
'<a href="http://github.com/">links</a>, '
|
||||||
'http://google.com')
|
'<a href="tg://user?id=123456789">text-mention</a> and '
|
||||||
|
'<pre>pre</pre>. http://google.com')
|
||||||
|
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
cid = args[1] == message.chat_id
|
cid = args[1] == message.chat_id
|
||||||
|
|
|
@ -23,9 +23,10 @@ from telegram import ParseMode
|
||||||
|
|
||||||
|
|
||||||
class TestParseMode(object):
|
class TestParseMode(object):
|
||||||
markdown_text = '*bold* _italic_ [link](http://google.com).'
|
markdown_text = '*bold* _italic_ [link](http://google.com) [name](tg://user?id=123456789).'
|
||||||
html_text = '<b>bold</b> <i>italic</i> <a href="http://google.com">link</a>.'
|
html_text = ('<b>bold</b> <i>italic</i> <a href="http://google.com">link</a> '
|
||||||
formatted_text_formatted = u'bold italic link.'
|
'<a href="tg://user?id=123456789">name</a>.')
|
||||||
|
formatted_text_formatted = u'bold italic link name.'
|
||||||
|
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@pytest.mark.timeout(10)
|
@pytest.mark.timeout(10)
|
||||||
|
|
Loading…
Reference in a new issue