mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-05 10:24:48 +01:00
create _isFileRequest to simplify _requestUrl
This commit is contained in:
parent
4c306de3a7
commit
f0a5b756cf
1 changed files with 19 additions and 4 deletions
|
@ -583,6 +583,24 @@ class Bot(object):
|
||||||
|
|
||||||
return True
|
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,
|
def _requestUrl(self,
|
||||||
url,
|
url,
|
||||||
method,
|
method,
|
||||||
|
@ -602,10 +620,7 @@ class Bot(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if method == 'POST':
|
if method == 'POST':
|
||||||
file_type = ['audio', 'document', 'photo', 'video']
|
if self._isFileRequest(data):
|
||||||
# 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')):
|
|
||||||
try:
|
try:
|
||||||
data = InputFile(data)
|
data = InputFile(data)
|
||||||
request = urllib2.Request(
|
request = urllib2.Request(
|
||||||
|
|
Loading…
Reference in a new issue