mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-27 08:50:38 +01:00
PEP8 and minor typos fixes
This commit is contained in:
parent
2e7e24d16c
commit
5cd153c535
1 changed files with 16 additions and 13 deletions
|
@ -538,7 +538,7 @@ class Bot(object):
|
||||||
"""Check if the request is a file request
|
"""Check if the request is a file request
|
||||||
Args:
|
Args:
|
||||||
data:
|
data:
|
||||||
A dict od (str, unicode) key/value pairs
|
A dict of (str, unicode) key/value pairs
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool
|
bool
|
||||||
|
@ -546,9 +546,12 @@ class Bot(object):
|
||||||
if data:
|
if data:
|
||||||
file_types = ['audio', 'document', 'photo', 'video']
|
file_types = ['audio', 'document', 'photo', 'video']
|
||||||
file_type = [i for i in data.keys() if i in file_types]
|
file_type = [i for i in data.keys() if i in file_types]
|
||||||
|
|
||||||
if file_type:
|
if file_type:
|
||||||
file_content = data[file_type[0]]
|
file_content = data[file_type[0]]
|
||||||
return isinstance(file_content, file) or str(file_content).startswith('http')
|
return isinstance(file_content, file) or \
|
||||||
|
str(file_content).startswith('http')
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _requestUrl(self,
|
def _requestUrl(self,
|
||||||
|
@ -570,34 +573,34 @@ class Bot(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if method == 'POST':
|
if method == 'POST':
|
||||||
if self._isFileRequest(data):
|
try:
|
||||||
try:
|
if self._isFileRequest(data):
|
||||||
data = InputFile(data)
|
data = InputFile(data)
|
||||||
|
|
||||||
request = urllib2.Request(
|
request = urllib2.Request(
|
||||||
url,
|
url,
|
||||||
data=data.to_form(),
|
data=data.to_form(),
|
||||||
headers=data.headers
|
headers=data.headers
|
||||||
)
|
)
|
||||||
|
|
||||||
return urllib2.urlopen(request).read()
|
return urllib2.urlopen(request).read()
|
||||||
except urllib2.URLError as e:
|
else:
|
||||||
raise TelegramError(str(e))
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
return urllib2.urlopen(
|
return urllib2.urlopen(
|
||||||
url,
|
url,
|
||||||
urllib.urlencode(data)
|
urllib.urlencode(data)
|
||||||
).read()
|
).read()
|
||||||
except urllib.IOError as e:
|
except urllib.IOError as e:
|
||||||
raise TelegramError(str(e))
|
raise TelegramError(str(e))
|
||||||
except urllib2.URLError as e:
|
except urllib2.URLError as e:
|
||||||
raise TelegramError(str(e))
|
raise TelegramError(str(e))
|
||||||
|
|
||||||
if method == 'GET':
|
if method == 'GET':
|
||||||
try:
|
try:
|
||||||
return urllib2.urlopen(url).read()
|
return urllib2.urlopen(url).read()
|
||||||
except urllib2.URLError as e:
|
except urllib2.URLError as e:
|
||||||
raise TelegramError(str(e))
|
raise TelegramError(str(e))
|
||||||
return 0
|
|
||||||
|
return 0 # if not a POST or GET request
|
||||||
|
|
||||||
def _parseAndCheckTelegram(self,
|
def _parseAndCheckTelegram(self,
|
||||||
json_data):
|
json_data):
|
||||||
|
|
Loading…
Add table
Reference in a new issue