X Tutup
Skip to content

Commit 5cd153c

Browse files
committed
PEP8 and minor typos fixes
1 parent 2e7e24d commit 5cd153c

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

telegram/bot.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -538,17 +538,20 @@ def _isFileRequest(self,
538538
"""Check if the request is a file request
539539
Args:
540540
data:
541-
A dict od (str, unicode) key/value pairs
541+
A dict of (str, unicode) key/value pairs
542542
543543
Returns:
544544
bool
545545
"""
546546
if data:
547547
file_types = ['audio', 'document', 'photo', 'video']
548548
file_type = [i for i in data.keys() if i in file_types]
549+
549550
if file_type:
550551
file_content = data[file_type[0]]
551-
return isinstance(file_content, file) or str(file_content).startswith('http')
552+
return isinstance(file_content, file) or \
553+
str(file_content).startswith('http')
554+
552555
return False
553556

554557
def _requestUrl(self,
@@ -570,34 +573,34 @@ def _requestUrl(self,
570573
"""
571574

572575
if method == 'POST':
573-
if self._isFileRequest(data):
574-
try:
576+
try:
577+
if self._isFileRequest(data):
575578
data = InputFile(data)
579+
576580
request = urllib2.Request(
577581
url,
578582
data=data.to_form(),
579583
headers=data.headers
580584
)
585+
581586
return urllib2.urlopen(request).read()
582-
except urllib2.URLError as e:
583-
raise TelegramError(str(e))
584-
else:
585-
try:
587+
else:
586588
return urllib2.urlopen(
587589
url,
588590
urllib.urlencode(data)
589591
).read()
590-
except urllib.IOError as e:
591-
raise TelegramError(str(e))
592-
except urllib2.URLError as e:
593-
raise TelegramError(str(e))
592+
except urllib.IOError as e:
593+
raise TelegramError(str(e))
594+
except urllib2.URLError as e:
595+
raise TelegramError(str(e))
594596

595597
if method == 'GET':
596598
try:
597599
return urllib2.urlopen(url).read()
598600
except urllib2.URLError as e:
599601
raise TelegramError(str(e))
600-
return 0
602+
603+
return 0 # if not a POST or GET request
601604

602605
def _parseAndCheckTelegram(self,
603606
json_data):

0 commit comments

Comments
 (0)
X Tutup