diff --git a/telegram/bot.py b/telegram/bot.py index 29705730f..b21278773 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -583,6 +583,24 @@ class Bot(object): return True + def _isFileRequest(self, + data=None): + """Check if the request is a file request + Args: + data: + A dict od (str, unicode) key/value pairs + + Returns: + bool + """ + if data: + file_types = ['audio', 'document', 'photo', 'video'] + file_type = [i for i in data.keys() if i in file_types] + if file_type: + file_content = data[file_type[0]] + return isinstance(file_content, file) or str(file_content).startswith('http') + return False + def _requestUrl(self, url, method, @@ -602,10 +620,7 @@ class Bot(object): """ if method == 'POST': - file_type = ['audio', 'document', 'photo', 'video'] - # len(dict{key1: val1, key2: val2}) == 2, it is used in case data is None - if len(data) >= 2 and data.keys()[1] in file_type and \ - (isinstance(data.items()[1], file) or str(data.items()[1]).startswith('http')): + if self._isFileRequest(data): try: data = InputFile(data) request = urllib2.Request(