@@ -79,22 +79,26 @@ def build_curl(method, url, headers, params, data_str, data_json, files):
7979 if files is not None :
8080 if isinstance (files , (dict )):
8181 for k , v in files .items ():
82- if v [0 ] is None :
83- msg .append (' --form %s="%s" \\ ' % (k , v [1 ]))
82+ if isinstance (v , (list , tuple )):
83+ if v [0 ] is None :
84+ msg .append (' --form %s="%s" \\ ' % (k , v [1 ]))
85+ else :
86+ msg .append (' --form %s="%s" \\ ' % (k , v [0 ]))
8487 else :
85- msg .append (' --form %s="%s" \\ ' % (k , v [ 0 ] ))
88+ msg .append (' --form %s="%s" \\ ' % (k ,v ))
8689 elif isinstance (files , (list , tuple )):
8790 for f in files :
88- msg .append (' --form "%s" \\ ' % (f ,))
89- continue
90- if f [1 ][0 ] is None :
91- # not a file
92- msg .append (' --form %s="%s" \\ ' % (f [0 ], f [1 ][1 ]))
91+ if isinstance (f , (list , tuple )):
92+ if f [1 ][0 ] is None :
93+ # not a file
94+ msg .append (' --form %s="%s" \\ ' % (f [0 ], f [1 ][1 ]))
95+ else :
96+ # a file
97+ msg .append (' --form %s="@%s" \\ ' % (f [0 ], f [1 ][0 ]))
9398 else :
94- # a file
95- msg .append (' --form %s="@%s" \\ ' % (f [0 ], f [1 ][0 ]))
99+ msg .append (' --form "%s" \\ ' % (f ,))
96100 else :
97- msg .append (' --form " file=@%s" \\ ' % (files ))
101+ msg .append (' --form file=" @%s" \\ ' % (files ))
98102
99103 # remove the last \ from the last line.
100104 msg [- 1 ] = msg [- 1 ][:- 1 ]
0 commit comments