Skip to content

Commit ca81a75

Browse files
authored
Merge pull request python-telegram-bot#396 from python-telegram-bot/json
use ujson as JSON en/decoder if available
2 parents ffff093 + da87d4b commit ca81a75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+317
-311
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- repo: git://github.com/pre-commit/mirrors-yapf
2-
sha: 316b795b2f32cbe80047aff7e842b72368d5a2c1
2+
sha: 34303f2856d4e4ba26dc302d9c28632e9b5a8626
33
hooks:
44
- id: yapf
55
files: ^(telegram|tests)/.*\.py$

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ install:
1010
- pip install coveralls
1111
- pip install -r requirements.txt
1212
- pip install -r requirements-dev.txt
13+
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install ujson; fi
1314
script:
1415
- nosetests -v --with-flaky --no-flaky-report --with-coverage --cover-package=telegram/
15-
- 'if [ $TRAVIS_PYTHON_VERSION != 3.3 ] && [ $TRAVIS_PYTHON_VERSION != pypy3 ]; then pre-commit run --all-files; fi'
16+
- if [ $TRAVIS_PYTHON_VERSION != 3.3 ] && [ $TRAVIS_PYTHON_VERSION != pypy3 ]; then pre-commit run --all-files; fi
1617
after_success:
1718
coveralls

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def requirements():
3434
long_description=fd.read(),
3535
packages=find_packages(exclude=['tests*']),
3636
install_requires=requirements(),
37+
extras_require={
38+
'json': 'ujson',
39+
},
3740
include_package_data=True,
3841
classifiers=[
3942
'Development Status :: 5 - Production/Stable',

telegram/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919
"""Base class for Telegram Objects."""
2020

21-
import json
21+
try:
22+
import ujson as json
23+
except ImportError:
24+
import json
25+
2226
from abc import ABCMeta
2327

2428

telegram/bot.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,8 @@ def sendLocation(self, chat_id, latitude, longitude, **kwargs):
618618

619619
@log
620620
@message
621-
def sendVenue(
622-
self, chat_id,
623-
latitude,
624-
longitude,
625-
title, address,
626-
foursquare_id=None,
627-
**kwargs):
621+
def sendVenue(self, chat_id, latitude, longitude, title, address, foursquare_id=None,
622+
**kwargs):
628623
"""
629624
Use this method to send information about a venue.
630625
@@ -1132,10 +1127,11 @@ def editMessageCaption(self,
11321127

11331128
@log
11341129
@message
1135-
def editMessageReplyMarkup(
1136-
self, chat_id=None,
1137-
message_id=None, inline_message_id=None,
1138-
**kwargs):
1130+
def editMessageReplyMarkup(self,
1131+
chat_id=None,
1132+
message_id=None,
1133+
inline_message_id=None,
1134+
**kwargs):
11391135
"""Use this method to edit only the reply markup of messages sent by
11401136
the bot or via the bot (for inline bots).
11411137

telegram/contrib/botan.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ def track(self, message, event_name='event'):
2828
return False
2929
data = message.to_json()
3030
try:
31-
url = self.url_template.format(token=str(self.token),
32-
uid=str(uid),
33-
name=quote(event_name))
34-
request = Request(url,
35-
data=data.encode(),
36-
headers={'Content-Type': 'application/json'})
31+
url = self.url_template.format(
32+
token=str(self.token), uid=str(uid), name=quote(event_name))
33+
request = Request(
34+
url, data=data.encode(), headers={'Content-Type': 'application/json'})
3735
urlopen(request)
3836
return True
3937
except HTTPError as error:

telegram/ext/callbackqueryhandler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ def __init__(self,
6161
pattern=None,
6262
pass_groups=False,
6363
pass_groupdict=False):
64-
super(CallbackQueryHandler, self).__init__(callback,
65-
pass_update_queue=pass_update_queue,
66-
pass_job_queue=pass_job_queue)
64+
super(CallbackQueryHandler, self).__init__(
65+
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
6766

6867
if isinstance(pattern, string_types):
6968
pattern = re.compile(pattern)

telegram/ext/choseninlineresulthandler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ class ChosenInlineResultHandler(Handler):
4343
"""
4444

4545
def __init__(self, callback, pass_update_queue=False, pass_job_queue=False):
46-
super(ChosenInlineResultHandler, self).__init__(callback,
47-
pass_update_queue=pass_update_queue,
48-
pass_job_queue=pass_job_queue)
46+
super(ChosenInlineResultHandler, self).__init__(
47+
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
4948

5049
def check_update(self, update):
5150
return isinstance(update, Update) and update.chosen_inline_result

telegram/ext/commandhandler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ def __init__(self,
5757
pass_args=False,
5858
pass_update_queue=False,
5959
pass_job_queue=False):
60-
super(CommandHandler, self).__init__(callback,
61-
pass_update_queue=pass_update_queue,
62-
pass_job_queue=pass_job_queue)
60+
super(CommandHandler, self).__init__(
61+
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
6362
self.command = command
6463
self.allow_edited = allow_edited
6564
self.pass_args = pass_args

telegram/ext/inlinequeryhandler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ def __init__(self,
6060
pattern=None,
6161
pass_groups=False,
6262
pass_groupdict=False):
63-
super(InlineQueryHandler, self).__init__(callback,
64-
pass_update_queue=pass_update_queue,
65-
pass_job_queue=pass_job_queue)
63+
super(InlineQueryHandler, self).__init__(
64+
callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)
6665

6766
if isinstance(pattern, string_types):
6867
pattern = re.compile(pattern)

0 commit comments

Comments
 (0)