2626import stat
2727import sys
2828
29+ from lib .core .common import getBytes
2930from lib .core .compat import choose_boundary
3031from lib .core .exception import SqlmapDataException
3132from thirdparty .six .moves import urllib as _urllib
@@ -51,7 +52,7 @@ def http_request(self, request):
5152
5253 try :
5354 for (key , value ) in data .items ():
54- if isinstance (value , file ) or hasattr (value , "file" ) or isinstance (value , io .IOBase ):
55+ if hasattr (value , "fileno" ) or hasattr (value , "file" ) or isinstance (value , io .IOBase ):
5556 v_files .append ((key , value ))
5657 else :
5758 v_vars .append ((key , value ))
@@ -85,7 +86,7 @@ def multipart_encode(vars, files, boundary=None, buf=None):
8586 buf += "\r \n \r \n " + value + "\r \n "
8687
8788 for (key , fd ) in files :
88- file_size = os .fstat (fd .fileno ())[stat .ST_SIZE ] if isinstance (fd , file ) else fd .len
89+ file_size = os .fstat (fd .fileno ())[stat .ST_SIZE ] if hasattr (fd , "fileno" ) else fd .len
8990 filename = fd .name .split ("/" )[- 1 ] if "/" in fd .name else fd .name .split ("\\ " )[- 1 ]
9091 try :
9192 contenttype = mimetypes .guess_type (filename )[0 ] or "application/octet-stream"
@@ -98,8 +99,8 @@ def multipart_encode(vars, files, boundary=None, buf=None):
9899 # buf += "Content-Length: %s\r\n" % file_size
99100 fd .seek (0 )
100101
101- buf = str (buf ) if not isinstance ( buf , unicode ) else buf . encode ( "utf8" )
102- buf += "\r \n %s\r \n " % fd .read ()
102+ buf = getBytes (buf )
103+ buf += b "\r \n %s\r \n " % fd .read ()
103104
104105 buf += "--%s--\r \n \r \n " % boundary
105106
0 commit comments