1717#
1818# You should have received a copy of the GNU Lesser Public License
1919# along with this program. If not, see [http://www.gnu.org/licenses/].
20-
2120"""This module contains a object that represents a Telegram InputFile."""
2221
2322try :
4443class InputFile (object ):
4544 """This object represents a Telegram InputFile."""
4645
47- def __init__ (self ,
48- data ):
46+ def __init__ (self , data ):
4947 self .data = data
5048 self .boundary = choose_boundary ()
5149
@@ -87,25 +85,22 @@ def __init__(self,
8785 # pylint: disable=E1101
8886 self .filename = os .path .basename (self .input_file .name )
8987 elif from_url :
90- self .filename = os .path .basename (self .input_file .url ) \
91- .split ('?' )[0 ].split ('&' )[0 ]
88+ self .filename = os .path .basename (self .input_file .url ).split ('?' )[0 ].split ('&' )[0 ]
9289
9390 try :
9491 self .mimetype = InputFile .is_image (self .input_file_content )
9592 if not self .filename or '.' not in self .filename :
9693 self .filename = self .mimetype .replace ('/' , '.' )
9794 except TelegramError :
98- self .mimetype = mimetypes .guess_type (self .filename )[0 ] or \
99- DEFAULT_MIME_TYPE
95+ self .mimetype = mimetypes .guess_type (self .filename )[0 ] or DEFAULT_MIME_TYPE
10096
10197 @property
10298 def headers (self ):
10399 """
104100 Returns:
105101 str:
106102 """
107- return {'User-agent' : USER_AGENT ,
108- 'Content-type' : self .content_type }
103+ return {'User-agent' : USER_AGENT , 'Content-type' : self .content_type }
109104
110105 @property
111106 def content_type (self ):
@@ -126,21 +121,14 @@ def to_form(self):
126121 # Add data fields
127122 for name , value in self .data .items ():
128123 form .extend ([
129- form_boundary ,
130- 'Content-Disposition: form-data; name="%s"' % name ,
131- '' ,
132- str (value )
124+ form_boundary , 'Content-Disposition: form-data; name="%s"' % name , '' , str (value )
133125 ])
134126
135127 # Add input_file to upload
136128 form .extend ([
137- form_boundary ,
138- 'Content-Disposition: form-data; name="%s"; filename="%s"' % (
129+ form_boundary , 'Content-Disposition: form-data; name="%s"; filename="%s"' % (
139130 self .input_name , self .filename
140- ),
141- 'Content-Type: %s' % self .mimetype ,
142- '' ,
143- self .input_file_content
131+ ), 'Content-Type: %s' % self .mimetype , '' , self .input_file_content
144132 ])
145133
146134 form .append ('--' + self .boundary + '--' )
@@ -193,14 +181,12 @@ def is_inputfile(data):
193181 bool
194182 """
195183 if data :
196- file_types = ['audio' , 'document' , 'photo' , 'sticker' , 'video' ,
197- 'voice' , 'certificate' ]
184+ file_types = ['audio' , 'document' , 'photo' , 'sticker' , 'video' , 'voice' , 'certificate' ]
198185 file_type = [i for i in list (data .keys ()) if i in file_types ]
199186
200187 if file_type :
201188 file_content = data [file_type [0 ]]
202189
203- return hasattr (file_content , 'read' ) or str (
204- file_content ).startswith ('http' )
190+ return hasattr (file_content , 'read' ) or str (file_content ).startswith ('http' )
205191
206192 return False
0 commit comments