From aeca3ca174292ef3c477352ba6e7eb906855e1b7 Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sat, 26 Dec 2015 01:10:15 +0200 Subject: [PATCH] basic token validation refs #134 --- telegram/bot.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/telegram/bot.py b/telegram/bot.py index eee2c41c9..fe6023b1f 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -52,7 +52,7 @@ class Bot(TelegramObject): def __init__(self, token, base_url=None): - self.token = token + self.token = self._valid_token(token) if base_url is None: self.base_url = 'https://api.telegram.org/bot%s' % self.token @@ -744,3 +744,11 @@ class Bot(TelegramObject): def __reduce__(self): return (self.__class__, (self.token, self.base_url.replace(self.token, ''))) + + @staticmethod + def _valid_token(token): + """a very basic validation on token""" + left, sep, _right = token.partition(':') + if (sep is None) or (not left.isdigit()) or (len(left) < 3): + raise TelegramError('Invalid token') + return token