File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323try :
2424 from email .generator import _make_boundary as choose_boundary
2525 from urllib .request import urlopen
26- from io import BufferedReader as file
2726except ImportError :
2827 from mimetools import choose_boundary
2928 from urllib2 import urlopen
@@ -76,13 +75,12 @@ def __init__(self,
7675 else :
7776 from_url = False
7877
79- if isinstance (self .input_file , file ) or from_url :
78+ if hasattr (self .input_file , 'read' ) or from_url :
8079 self .filename = None
8180 self .input_file_content = self .input_file .read ()
8281 if 'filename' in data :
8382 self .filename = self .data .pop ('filename' )
84- elif isinstance (self .input_file , file ) and \
85- hasattr (self .input_file , 'name' ):
83+ elif hasattr (self .input_file , 'name' ):
8684 self .filename = os .path .basename (self .input_file .name )
8785 elif from_url :
8886 self .filename = os .path .basename (self .input_file .url ) \
@@ -198,7 +196,7 @@ def is_inputfile(data):
198196 if file_type :
199197 file_content = data [file_type [0 ]]
200198
201- return isinstance (file_content , file ) or str (
199+ return hasattr (file_content , 'read' ) or str (
202200 file_content ).startswith ('http' )
203201
204202 return False
Original file line number Diff line number Diff line change @@ -152,6 +152,16 @@ def testSendGIFURLPhoto(self):
152152 self .assertTrue (self .is_json (message .to_json ()))
153153 self .assertEqual (message .photo [0 ].file_size , 684 )
154154
155+ @flaky (3 , 1 )
156+ @timeout (10 )
157+ def testSendBufferedReaderPhoto (self ):
158+ photo = open ('tests/data/telegram.png' , 'rb' )
159+ message = self ._bot .sendPhoto (photo = photo ,
160+ chat_id = self ._chat_id )
161+
162+ self .assertTrue (self .is_json (message .to_json ()))
163+ self .assertEqual (message .photo [0 ].file_size , 1451 )
164+
155165 @flaky (3 , 1 )
156166 @timeout (10 )
157167 def testSendChatAction (self ):
You can’t perform that action at this time.
0 commit comments