Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- repo: git://github.com/pre-commit/mirrors-yapf
sha: 316b795b2f32cbe80047aff7e842b72368d5a2c1
sha: 34303f2856d4e4ba26dc302d9c28632e9b5a8626
hooks:
- id: yapf
files: ^(telegram|tests)/.*\.py$
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ install:
- pip install coveralls
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install ujson; fi
script:
- nosetests -v --with-flaky --no-flaky-report --with-coverage --cover-package=telegram/
- 'if [ $TRAVIS_PYTHON_VERSION != 3.3 ] && [ $TRAVIS_PYTHON_VERSION != pypy3 ]; then pre-commit run --all-files; fi'
- if [ $TRAVIS_PYTHON_VERSION != 3.3 ] && [ $TRAVIS_PYTHON_VERSION != pypy3 ]; then pre-commit run --all-files; fi
after_success:
coveralls
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def requirements():
long_description=fd.read(),
packages=find_packages(exclude=['tests*']),
install_requires=requirements(),
extras_require={
'json': 'ujson',
},
include_package_data=True,
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down
6 changes: 5 additions & 1 deletion telegram/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""Base class for Telegram Objects."""

import json
try:
import ujson as json
except ImportError:
import json

from abc import ABCMeta


Expand Down
18 changes: 7 additions & 11 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,8 @@ def sendLocation(self, chat_id, latitude, longitude, **kwargs):

@log
@message
def sendVenue(
self, chat_id,
latitude,
longitude,
title, address,
foursquare_id=None,
**kwargs):
def sendVenue(self, chat_id, latitude, longitude, title, address, foursquare_id=None,
**kwargs):
"""
Use this method to send information about a venue.

Expand Down Expand Up @@ -1132,10 +1127,11 @@ def editMessageCaption(self,

@log
@message
def editMessageReplyMarkup(
self, chat_id=None,
message_id=None, inline_message_id=None,
**kwargs):
def editMessageReplyMarkup(self,
chat_id=None,
message_id=None,
inline_message_id=None,
**kwargs):
"""Use this method to edit only the reply markup of messages sent by
the bot or via the bot (for inline bots).

Expand Down
10 changes: 4 additions & 6 deletions telegram/contrib/botan.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ def track(self, message, event_name='event'):
return False
data = message.to_json()
try:
url = self.url_template.format(token=str(self.token),
uid=str(uid),
name=quote(event_name))
request = Request(url,
data=data.encode(),
headers={'Content-Type': 'application/json'})
url = self.url_template.format(
token=str(self.token), uid=str(uid), name=quote(event_name))
request = Request(
url, data=data.encode(), headers={'Content-Type': 'application/json'})
urlopen(request)
return True
except HTTPError as error:
Expand Down
5 changes: 2 additions & 3 deletions telegram/ext/callbackqueryhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def __init__(self,
pattern=None,
pass_groups=False,
pass_groupdict=False):
super(CallbackQueryHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(CallbackQueryHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)

if isinstance(pattern, string_types):
pattern = re.compile(pattern)
Expand Down
5 changes: 2 additions & 3 deletions telegram/ext/choseninlineresulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class ChosenInlineResultHandler(Handler):
"""

def __init__(self, callback, pass_update_queue=False, pass_job_queue=False):
super(ChosenInlineResultHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(ChosenInlineResultHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)

def check_update(self, update):
return isinstance(update, Update) and update.chosen_inline_result
Expand Down
5 changes: 2 additions & 3 deletions telegram/ext/commandhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ def __init__(self,
pass_args=False,
pass_update_queue=False,
pass_job_queue=False):
super(CommandHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(CommandHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
self.command = command
self.allow_edited = allow_edited
self.pass_args = pass_args
Expand Down
5 changes: 2 additions & 3 deletions telegram/ext/inlinequeryhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def __init__(self,
pattern=None,
pass_groups=False,
pass_groupdict=False):
super(InlineQueryHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(InlineQueryHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)

if isinstance(pattern, string_types):
pattern = re.compile(pattern)
Expand Down
7 changes: 3 additions & 4 deletions telegram/ext/messagehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def status_update(message):
or message.group_chat_created or message.supergroup_chat_created
or message.channel_chat_created or message.migrate_to_chat_id
or message.migrate_from_chat_id or message.pinned_message)

@staticmethod
def forwarded(message):
return bool(message.forward_date)
Expand Down Expand Up @@ -115,9 +115,8 @@ def __init__(self,
allow_edited=False,
pass_update_queue=False,
pass_job_queue=False):
super(MessageHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(MessageHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
self.filters = filters
self.allow_edited = allow_edited

Expand Down
5 changes: 2 additions & 3 deletions telegram/ext/regexhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ def __init__(self,
pass_groupdict=False,
pass_update_queue=False,
pass_job_queue=False):
super(RegexHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(RegexHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)

if isinstance(pattern, string_types):
pattern = re.compile(pattern)
Expand Down
5 changes: 2 additions & 3 deletions telegram/ext/stringcommandhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ def __init__(self,
pass_args=False,
pass_update_queue=False,
pass_job_queue=False):
super(StringCommandHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(StringCommandHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
self.command = command
self.pass_args = pass_args

Expand Down
5 changes: 2 additions & 3 deletions telegram/ext/stringregexhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def __init__(self,
pass_groupdict=False,
pass_update_queue=False,
pass_job_queue=False):
super(StringRegexHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(StringRegexHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)

if isinstance(pattern, string_types):
pattern = re.compile(pattern)
Expand Down
11 changes: 3 additions & 8 deletions telegram/ext/typehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ class TypeHandler(Handler):
Default is ``False``.
"""

def __init__(self,
type,
callback,
strict=False,
pass_update_queue=False,
def __init__(self, type, callback, strict=False, pass_update_queue=False,
pass_job_queue=False):
super(TypeHandler, self).__init__(callback,
pass_update_queue=pass_update_queue,
pass_job_queue=pass_job_queue)
super(TypeHandler, self).__init__(
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
self.type = type
self.strict = strict

Expand Down
31 changes: 15 additions & 16 deletions telegram/ext/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ def __init__(self, token=None, base_url=None, workers=4, bot=None):
self.update_queue = Queue()
self.job_queue = JobQueue(self.bot)
self.__exception_event = Event()
self.dispatcher = Dispatcher(self.bot,
self.update_queue,
job_queue=self.job_queue,
workers=workers,
exception_event=self.__exception_event)
self.dispatcher = Dispatcher(
self.bot,
self.update_queue,
job_queue=self.job_queue,
workers=workers,
exception_event=self.__exception_event)
self.last_update_id = 0
self.logger = logging.getLogger(__name__)
self.running = False
Expand Down Expand Up @@ -216,9 +217,8 @@ def _start_polling(self, poll_interval, timeout, network_delay, bootstrap_retrie

while self.running:
try:
updates = self.bot.getUpdates(self.last_update_id,
timeout=timeout,
network_delay=network_delay)
updates = self.bot.getUpdates(
self.last_update_id, timeout=timeout, network_delay=network_delay)
except TelegramError as te:
self.logger.error("Error while getting Updates: {0}".format(te))

Expand Down Expand Up @@ -271,10 +271,11 @@ def _start_webhook(self, listen, port, url_path, cert, key, bootstrap_retries, c
if not webhook_url:
webhook_url = self._gen_webhook_url(listen, port, url_path)

self._bootstrap(max_retries=bootstrap_retries,
clean=clean,
webhook_url=webhook_url,
cert=open(cert, 'rb'))
self._bootstrap(
max_retries=bootstrap_retries,
clean=clean,
webhook_url=webhook_url,
cert=open(cert, 'rb'))
elif clean:
self.logger.warning("cleaning updates is not supported if "
"SSL-termination happens elsewhere; skipping")
Expand All @@ -292,10 +293,8 @@ def _check_ssl_cert(self, cert, key):
exit_code = 0
if exit_code is 0:
try:
self.httpd.socket = ssl.wrap_socket(self.httpd.socket,
certfile=cert,
keyfile=key,
server_side=True)
self.httpd.socket = ssl.wrap_socket(
self.httpd.socket, certfile=cert, keyfile=key, server_side=True)
except ssl.SSLError as error:
self.logger.exception('Failed to init SSL socket')
raise TelegramError(str(error))
Expand Down
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultarticle.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def de_json(data):
data = super(InlineQueryResultArticle, InlineQueryResultArticle).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultArticle(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def de_json(data):
data = super(InlineQueryResultAudio, InlineQueryResultAudio).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultAudio(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcachedaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def de_json(data):
data = super(InlineQueryResultCachedAudio, InlineQueryResultCachedAudio).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultCachedAudio(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcacheddocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def de_json(data):
InlineQueryResultCachedDocument).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultCachedDocument(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcachedgif.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def de_json(data):
data = super(InlineQueryResultCachedGif, InlineQueryResultCachedGif).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultCachedGif(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcachedmpeg4gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def de_json(data):
InlineQueryResultCachedMpeg4Gif).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultCachedMpeg4Gif(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcachedphoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def de_json(data):
data = super(InlineQueryResultCachedPhoto, InlineQueryResultCachedPhoto).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultCachedPhoto(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcachedsticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def de_json(data):
data = super(InlineQueryResultCachedSticker, InlineQueryResultCachedSticker).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultCachedSticker(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcachedvideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def de_json(data):
data = super(InlineQueryResultCachedVideo, InlineQueryResultCachedVideo).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultCachedVideo(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcachedvoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def de_json(data):
data = super(InlineQueryResultCachedVoice, InlineQueryResultCachedVoice).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultCachedVoice(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultcontact.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def de_json(data):
data = super(InlineQueryResultContact, InlineQueryResultContact).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultContact(**data)
4 changes: 2 additions & 2 deletions telegram/inlinequeryresultdocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def de_json(data):
data = super(InlineQueryResultDocument, InlineQueryResultDocument).de_json(data)

data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
data['input_message_content'] = InputMessageContent.de_json(data.get(
'input_message_content'))
data['input_message_content'] = InputMessageContent.de_json(
data.get('input_message_content'))

return InlineQueryResultDocument(**data)
Loading